Spaces:
Running
Running
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() | |