FauziIsyrinApridal commited on
Commit
aa95ea3
Β·
1 Parent(s): e96fbd0

update test

Browse files
Files changed (2) hide show
  1. tests/test_admin.py +61 -17
  2. 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:\path\ke\contoh\file.pdf"
 
 
 
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.click("text=Login")
 
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
- # 4️⃣ Klik "Upload Document" dan pilih file
 
 
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.click("text=Upload")
 
34
  page.wait_for_timeout(3000)
35
 
 
 
 
36
  # 5️⃣ Klik "Start Scraping"
37
- page.click("text=Start Scraping")
38
  page.wait_for_timeout(1000)
 
 
 
 
 
 
39
 
40
- # Memilih item dari Dropdown Scraping
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
- # 7️⃣ Klik "Refresh"
52
- page.click("text=Refresh")
 
 
 
 
 
 
 
 
 
 
53
  page.wait_for_timeout(2000)
54
 
55
- # 8️⃣ Klik "Log Out"
56
- page.click("text=Log Out")
 
 
 
57
  page.wait_for_timeout(2000)
58
 
59
- print("βœ… Test Admin Page selesai!")
 
 
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('.stChatMessage', timeout=60000)
12
 
13
  def jumlah_tag_audio(page) -> int:
14
- """Hitung jumlah tag <audio>"""
15
  return len(page.query_selector_all("audio"))
16
 
17
- def klik_toggle_tts(page):
18
- """Klik Toggle TTS sesuai status awal"""
19
- aktif = page.locator('text=πŸ”Š Text-to-Speech Aktif')
20
- nonaktif = page.locator('text=πŸ”‡ Text-to-Speech Nonaktif')
21
- if aktif.count() > 0:
22
- aktif.click()
23
- elif nonaktif.count() > 0:
24
- nonaktif.click()
25
 
26
- def test_tts_condition(page, tts_aktif: bool):
27
- """Test untuk satu skenario."""
28
- print(f"\n=== TEST: {'TTS Aktif' if tts_aktif else 'TTS Nonaktif'} ===")
29
- awal_aktif = page.locator('text=πŸ”Š Text-to-Speech Aktif')
30
- awal_nonaktif = page.locator('text=πŸ”‡ Text-to-Speech Nonaktif')
31
 
32
- # Atur status sesuai kebutuhan
33
- if tts_aktif and awal_nonaktif.count() > 0:
34
- klik_toggle_tts(page)
35
-
36
- if not tts_aktif and awal_aktif.count() > 0:
37
- klik_toggle_tts(page)
38
 
 
39
  kirim_pertanyaan(page, PERTANYAAN)
40
 
 
41
  jumlah_audio = jumlah_tag_audio(page)
42
 
43
- if tts_aktif:
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
- time.sleep(3) # buat melihat efek sebelum tes selanjutnya
 
 
 
 
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 melihat
60
  page = browser.new_page()
61
  page.goto(URL)
62
 
63
- # Test dengan TTS aktif
64
- test_tts_condition(page, True)
65
 
66
- # Test dengan TTS nonaktif
67
- test_tts_condition(page, False)
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()