Spaces:
Sleeping
Sleeping
FauziIsyrinApridal
commited on
Commit
Β·
aa95ea3
1
Parent(s):
e96fbd0
update test
Browse files- tests/test_admin.py +61 -17
- tests/test_chatbot.py +33 -29
tests/test_admin.py
CHANGED
|
@@ -4,9 +4,14 @@ import os
|
|
| 4 |
import random
|
| 5 |
|
| 6 |
# Ganti path ini dengan path file kamu
|
| 7 |
-
FILE_PATH = r"C:\
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def run_test():
|
|
|
|
|
|
|
| 10 |
with sync_playwright() as p:
|
| 11 |
browser = p.chromium.launch(headless=False) # headless=False untuk lihat
|
| 12 |
page = browser.new_page()
|
|
@@ -15,48 +20,87 @@ def run_test():
|
|
| 15 |
page.goto("https://yozora721-pnp-chatbot-admin-v1.hf.space/login")
|
| 16 |
page.wait_for_timeout(2000)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# 2οΈβ£ Login dengan admin
|
| 19 |
page.fill("input[name='email']", "[email protected]")
|
| 20 |
page.fill("input[name='password']", "password")
|
| 21 |
-
page.
|
|
|
|
| 22 |
page.wait_for_timeout(3000)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
# 3οΈβ£ Verifikasi status awal
|
|
|
|
| 25 |
documents_count = page.inner_text("text=documents available") if page.is_visible("text=documents available") else "Tidak ditemukan"
|
| 26 |
-
print(f"π Status awal dokumen: {documents_count}")
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
page.click("text=Upload Document")
|
| 30 |
page.wait_for_timeout(2000)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
page.set_input_files("input[type='file']", FILE_PATH)
|
| 33 |
-
page.
|
|
|
|
| 34 |
page.wait_for_timeout(3000)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
# 5οΈβ£ Klik "Start Scraping"
|
| 37 |
-
page.click("text
|
| 38 |
page.wait_for_timeout(1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
items = page.query_selector_all("//div[contains(@class,'menu-item')]") # contoh
|
| 42 |
-
if items:
|
| 43 |
-
item = random.choice(items)
|
| 44 |
-
item.click()
|
| 45 |
-
page.wait_for_timeout(3000)
|
| 46 |
|
| 47 |
# 6οΈβ£ Klik "Filter All Semesters"
|
| 48 |
page.click("text=All Semesters")
|
|
|
|
|
|
|
|
|
|
| 49 |
page.wait_for_timeout(2000)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
page.wait_for_timeout(2000)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
page.wait_for_timeout(2000)
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
|
| 61 |
browser.close()
|
| 62 |
|
|
|
|
| 4 |
import random
|
| 5 |
|
| 6 |
# Ganti path ini dengan path file kamu
|
| 7 |
+
FILE_PATH = r"C:\Users\USER\OneDrive\Tugas Akhir\pnp-chatbot-v1\requirements.txt"
|
| 8 |
+
|
| 9 |
+
# Folder untuk simpan screenshot
|
| 10 |
+
SCREENSHOTS_DIR = "screenshots"
|
| 11 |
|
| 12 |
def run_test():
|
| 13 |
+
os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
|
| 14 |
+
|
| 15 |
with sync_playwright() as p:
|
| 16 |
browser = p.chromium.launch(headless=False) # headless=False untuk lihat
|
| 17 |
page = browser.new_page()
|
|
|
|
| 20 |
page.goto("https://yozora721-pnp-chatbot-admin-v1.hf.space/login")
|
| 21 |
page.wait_for_timeout(2000)
|
| 22 |
|
| 23 |
+
# β
Screenshot halaman login
|
| 24 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/00_login_page.png")
|
| 25 |
+
print("[π·] Berhasil Screenshot Halaman Login.")
|
| 26 |
+
|
| 27 |
# 2οΈβ£ Login dengan admin
|
| 28 |
page.fill("input[name='email']", "[email protected]")
|
| 29 |
page.fill("input[name='password']", "password")
|
| 30 |
+
page.wait_for_selector("button[type='submit']", timeout=10000)
|
| 31 |
+
page.click("button[type='submit']")
|
| 32 |
page.wait_for_timeout(3000)
|
| 33 |
|
| 34 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/01_after_login.png")
|
| 35 |
+
print("[β
] Berhasil Login.")
|
| 36 |
+
|
| 37 |
# 3οΈβ£ Verifikasi status awal
|
| 38 |
+
page.wait_for_timeout(5000)
|
| 39 |
documents_count = page.inner_text("text=documents available") if page.is_visible("text=documents available") else "Tidak ditemukan"
|
| 40 |
+
print(f"[π] Status awal dokumen: {documents_count}")
|
| 41 |
|
| 42 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/02_status_awal.png")
|
| 43 |
+
|
| 44 |
+
# 4οΈβ£ Klik "Upload Document"
|
| 45 |
page.click("text=Upload Document")
|
| 46 |
page.wait_for_timeout(2000)
|
| 47 |
|
| 48 |
+
# β
Screenshot halaman Upload
|
| 49 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/03_before_file_upload.png")
|
| 50 |
+
print("[π·] Berhasil Screenshot Halaman Upload.")
|
| 51 |
+
|
| 52 |
+
# Upload file
|
| 53 |
page.set_input_files("input[type='file']", FILE_PATH)
|
| 54 |
+
page.wait_for_selector("button[type='submit']", timeout=10000)
|
| 55 |
+
page.click("button[type='submit']")
|
| 56 |
page.wait_for_timeout(3000)
|
| 57 |
|
| 58 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/04_after_upload.png")
|
| 59 |
+
print("[β
] Berhasil Upload File.")
|
| 60 |
+
|
| 61 |
# 5οΈβ£ Klik "Start Scraping"
|
| 62 |
+
page.click("button:has-text('Start Scraping')")
|
| 63 |
page.wait_for_timeout(1000)
|
| 64 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/05.0_before_start_scraping.png")
|
| 65 |
+
|
| 66 |
+
page.wait_for_selector("div[role='menuitem']:has-text('Data Dosen')", timeout=5000)
|
| 67 |
+
page.click("div[role='menuitem']:has-text('Data Dosen')")
|
| 68 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/05.1_after_start_scraping.png")
|
| 69 |
+
page.wait_for_timeout(50000)
|
| 70 |
|
| 71 |
+
print("[β
] Berhasil Memulai Scraping.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
# 6οΈβ£ Klik "Filter All Semesters"
|
| 74 |
page.click("text=All Semesters")
|
| 75 |
+
page.wait_for_timeout(1000)
|
| 76 |
+
|
| 77 |
+
page.click("div.font-medium:has-text('Ganjil 2025/2026')")
|
| 78 |
page.wait_for_timeout(2000)
|
| 79 |
|
| 80 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/06_after_filter.png")
|
| 81 |
+
print("[β
] Berhasil Memilih Semester.")
|
| 82 |
+
|
| 83 |
+
# 7οΈβ£ Klik "Show All Documents"
|
| 84 |
+
page.click("text=Show all documents") # Sesuaikan dengan teks yang digunakan
|
| 85 |
+
page.wait_for_timeout(3000)
|
| 86 |
+
|
| 87 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/07_after_show_all.png")
|
| 88 |
+
print("[β
] Berhasil Klik 'Show All Documents'.")
|
| 89 |
+
|
| 90 |
+
# 8οΈβ£ Klik "Refresh"
|
| 91 |
+
page.click("button:has-text('Refresh')")
|
| 92 |
page.wait_for_timeout(2000)
|
| 93 |
|
| 94 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/08_after_refresh.png")
|
| 95 |
+
print("[β
] Berhasil Refresh.")
|
| 96 |
+
|
| 97 |
+
# 9οΈβ£ Klik "Log Out"
|
| 98 |
+
page.click("button:has-text('Log Out')")
|
| 99 |
page.wait_for_timeout(2000)
|
| 100 |
|
| 101 |
+
page.screenshot(path=f"{SCREENSHOTS_DIR}/09_after_logout.png")
|
| 102 |
+
print("[β
] Berhasil Log Out.")
|
| 103 |
+
print("\nπ Test Admin Page selesai! Cek folder 'screenshots' untuk visualisasi.")
|
| 104 |
|
| 105 |
browser.close()
|
| 106 |
|
tests/test_chatbot.py
CHANGED
|
@@ -1,46 +1,45 @@
|
|
| 1 |
from playwright.sync_api import sync_playwright
|
| 2 |
import time
|
|
|
|
| 3 |
|
| 4 |
URL = "https://yozora721-pnp-chatbot-v1.hf.space"
|
| 5 |
PERTANYAAN = "Halo"
|
|
|
|
| 6 |
|
| 7 |
def kirim_pertanyaan(page, pertanyaan: str):
|
| 8 |
-
"""Ketik pertanyaan dan kirim."""
|
| 9 |
page.locator('textarea[placeholder="Masukkan pertanyaan"]').fill(pertanyaan)
|
| 10 |
page.keyboard.press("Enter")
|
| 11 |
-
page.wait_for_selector('.
|
| 12 |
|
| 13 |
def jumlah_tag_audio(page) -> int:
|
| 14 |
-
"""Hitung jumlah tag <audio
|
| 15 |
return len(page.query_selector_all("audio"))
|
| 16 |
|
| 17 |
-
def
|
| 18 |
-
"""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
elif nonaktif.count() > 0:
|
| 24 |
-
nonaktif.click()
|
| 25 |
|
| 26 |
-
def
|
| 27 |
-
"""Test untuk
|
| 28 |
-
|
| 29 |
-
awal_aktif = page.locator('text=π Text-to-Speech Aktif')
|
| 30 |
-
awal_nonaktif = page.locator('text=π Text-to-Speech Nonaktif')
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
if
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
klik_toggle_tts(page)
|
| 38 |
|
|
|
|
| 39 |
kirim_pertanyaan(page, PERTANYAAN)
|
| 40 |
|
|
|
|
| 41 |
jumlah_audio = jumlah_tag_audio(page)
|
| 42 |
|
| 43 |
-
if
|
| 44 |
if jumlah_audio > 0:
|
| 45 |
print(f"β
[AKTIF] Ada {jumlah_audio} tag <audio> (sesuai ekspektasi).")
|
| 46 |
else:
|
|
@@ -51,22 +50,27 @@ def test_tts_condition(page, tts_aktif: bool):
|
|
| 51 |
else:
|
| 52 |
print(f"β [NONAKTIF] Ada {jumlah_audio} tag <audio>, tidak sesuai ekspektasi.")
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
def main():
|
| 57 |
"""Main entry point."""
|
| 58 |
with sync_playwright() as p:
|
| 59 |
-
browser = p.chromium.launch(headless=False) # True kalau tidak perlu
|
| 60 |
page = browser.new_page()
|
| 61 |
page.goto(URL)
|
| 62 |
|
| 63 |
-
# Test dengan TTS
|
| 64 |
-
|
| 65 |
|
| 66 |
-
# Test dengan TTS
|
| 67 |
-
|
| 68 |
|
| 69 |
browser.close()
|
|
|
|
| 70 |
|
| 71 |
if __name__ == '__main__':
|
| 72 |
main()
|
|
|
|
| 1 |
from playwright.sync_api import sync_playwright
|
| 2 |
import time
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
URL = "https://yozora721-pnp-chatbot-v1.hf.space"
|
| 6 |
PERTANYAAN = "Halo"
|
| 7 |
+
SCREENSHOTS_DIR = "screenshots"
|
| 8 |
|
| 9 |
def kirim_pertanyaan(page, pertanyaan: str):
|
| 10 |
+
"""Ketik pertanyaan dan kirim, tunggu hingga pesan keluar."""
|
| 11 |
page.locator('textarea[placeholder="Masukkan pertanyaan"]').fill(pertanyaan)
|
| 12 |
page.keyboard.press("Enter")
|
| 13 |
+
page.wait_for_selector('.msg', timeout=60000)
|
| 14 |
|
| 15 |
def jumlah_tag_audio(page) -> int:
|
| 16 |
+
"""Hitung jumlah tag <audio>."""
|
| 17 |
return len(page.query_selector_all("audio"))
|
| 18 |
|
| 19 |
+
def buat_screenshot(page, status: str):
|
| 20 |
+
"""Buat screenshot area chat .msg dan simpan dengan status tertentu."""
|
| 21 |
+
os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
|
| 22 |
+
chat_area = page.locator('.msg')
|
| 23 |
+
chat_area.screenshot(path=f"{SCREENSHOTS_DIR}/chat_{status}.png")
|
| 24 |
+
print(f"π· Screenshot area chat disimpan: {SCREENSHOTS_DIR}/chat_{status}.png")
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
def test_tts(page, aktif: bool):
|
| 27 |
+
"""Test untuk status TTS aktif/nonaktif."""
|
| 28 |
+
status = "AKTIF" if aktif else "NONAKTIF"
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Klik Toggle sesuai kebutuhan
|
| 31 |
+
if aktif and page.locator('text=π Text-to-Speech Nonaktif').count() > 0:
|
| 32 |
+
page.locator('text=π Text-to-Speech Nonaktif').click()
|
| 33 |
+
elif not aktif and page.locator('text=π Text-to-Speech Aktif').count() > 0:
|
| 34 |
+
page.locator('text=π Text-to-Speech Aktif').click()
|
|
|
|
| 35 |
|
| 36 |
+
# Kirim pertanyaan
|
| 37 |
kirim_pertanyaan(page, PERTANYAAN)
|
| 38 |
|
| 39 |
+
# Hitung jumlah audio
|
| 40 |
jumlah_audio = jumlah_tag_audio(page)
|
| 41 |
|
| 42 |
+
if aktif:
|
| 43 |
if jumlah_audio > 0:
|
| 44 |
print(f"β
[AKTIF] Ada {jumlah_audio} tag <audio> (sesuai ekspektasi).")
|
| 45 |
else:
|
|
|
|
| 50 |
else:
|
| 51 |
print(f"β [NONAKTIF] Ada {jumlah_audio} tag <audio>, tidak sesuai ekspektasi.")
|
| 52 |
|
| 53 |
+
# Simpan screenshot area chat
|
| 54 |
+
buat_screenshot(page, status)
|
| 55 |
+
|
| 56 |
+
# Beri waktu sebelum test selanjutnya
|
| 57 |
+
time.sleep(2)
|
| 58 |
|
| 59 |
def main():
|
| 60 |
"""Main entry point."""
|
| 61 |
with sync_playwright() as p:
|
| 62 |
+
browser = p.chromium.launch(headless=False) # True kalau tidak perlu lihat
|
| 63 |
page = browser.new_page()
|
| 64 |
page.goto(URL)
|
| 65 |
|
| 66 |
+
# Test dengan TTS Aktif
|
| 67 |
+
test_tts(page, True)
|
| 68 |
|
| 69 |
+
# Test dengan TTS Nonaktif
|
| 70 |
+
test_tts(page, False)
|
| 71 |
|
| 72 |
browser.close()
|
| 73 |
+
print("\nπ Selesai! Cek folder 'screenshots' untuk melihat area chat.")
|
| 74 |
|
| 75 |
if __name__ == '__main__':
|
| 76 |
main()
|