pnp-chatbot-v1 / tests /test_admin.py
FauziIsyrinApridal
update test
aa95ea3
from playwright.sync_api import sync_playwright
import time
import os
import random
# Ganti path ini dengan path file kamu
FILE_PATH = r"C:\Users\USER\OneDrive\Tugas Akhir\pnp-chatbot-v1\requirements.txt"
# Folder untuk simpan screenshot
SCREENSHOTS_DIR = "screenshots"
def run_test():
os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
with sync_playwright() as p:
browser = p.chromium.launch(headless=False) # headless=False untuk lihat
page = browser.new_page()
# 1️⃣ Akses halaman login
page.goto("https://yozora721-pnp-chatbot-admin-v1.hf.space/login")
page.wait_for_timeout(2000)
# βœ… Screenshot halaman login
page.screenshot(path=f"{SCREENSHOTS_DIR}/00_login_page.png")
print("[πŸ“·] Berhasil Screenshot Halaman Login.")
# 2️⃣ Login dengan admin
page.fill("input[name='email']", "[email protected]")
page.fill("input[name='password']", "password")
page.wait_for_selector("button[type='submit']", timeout=10000)
page.click("button[type='submit']")
page.wait_for_timeout(3000)
page.screenshot(path=f"{SCREENSHOTS_DIR}/01_after_login.png")
print("[βœ…] Berhasil Login.")
# 3️⃣ Verifikasi status awal
page.wait_for_timeout(5000)
documents_count = page.inner_text("text=documents available") if page.is_visible("text=documents available") else "Tidak ditemukan"
print(f"[πŸ‘‰] Status awal dokumen: {documents_count}")
page.screenshot(path=f"{SCREENSHOTS_DIR}/02_status_awal.png")
# 4️⃣ Klik "Upload Document"
page.click("text=Upload Document")
page.wait_for_timeout(2000)
# βœ… Screenshot halaman Upload
page.screenshot(path=f"{SCREENSHOTS_DIR}/03_before_file_upload.png")
print("[πŸ“·] Berhasil Screenshot Halaman Upload.")
# Upload file
page.set_input_files("input[type='file']", FILE_PATH)
page.wait_for_selector("button[type='submit']", timeout=10000)
page.click("button[type='submit']")
page.wait_for_timeout(3000)
page.screenshot(path=f"{SCREENSHOTS_DIR}/04_after_upload.png")
print("[βœ…] Berhasil Upload File.")
# 5️⃣ Klik "Start Scraping"
page.click("button:has-text('Start Scraping')")
page.wait_for_timeout(1000)
page.screenshot(path=f"{SCREENSHOTS_DIR}/05.0_before_start_scraping.png")
page.wait_for_selector("div[role='menuitem']:has-text('Data Dosen')", timeout=5000)
page.click("div[role='menuitem']:has-text('Data Dosen')")
page.screenshot(path=f"{SCREENSHOTS_DIR}/05.1_after_start_scraping.png")
page.wait_for_timeout(50000)
print("[βœ…] Berhasil Memulai Scraping.")
# 6️⃣ Klik "Filter All Semesters"
page.click("text=All Semesters")
page.wait_for_timeout(1000)
page.click("div.font-medium:has-text('Ganjil 2025/2026')")
page.wait_for_timeout(2000)
page.screenshot(path=f"{SCREENSHOTS_DIR}/06_after_filter.png")
print("[βœ…] Berhasil Memilih Semester.")
# 7️⃣ Klik "Show All Documents"
page.click("text=Show all documents") # Sesuaikan dengan teks yang digunakan
page.wait_for_timeout(3000)
page.screenshot(path=f"{SCREENSHOTS_DIR}/07_after_show_all.png")
print("[βœ…] Berhasil Klik 'Show All Documents'.")
# 8️⃣ Klik "Refresh"
page.click("button:has-text('Refresh')")
page.wait_for_timeout(2000)
page.screenshot(path=f"{SCREENSHOTS_DIR}/08_after_refresh.png")
print("[βœ…] Berhasil Refresh.")
# 9️⃣ Klik "Log Out"
page.click("button:has-text('Log Out')")
page.wait_for_timeout(2000)
page.screenshot(path=f"{SCREENSHOTS_DIR}/09_after_logout.png")
print("[βœ…] Berhasil Log Out.")
print("\nπŸŽ‰ Test Admin Page selesai! Cek folder 'screenshots' untuk visualisasi.")
browser.close()
if __name__ == "__main__":
run_test()