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:\path\ke\contoh\file.pdf" | |
def run_test(): | |
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) | |
# 2️⃣ Login dengan admin | |
page.fill("input[name='email']", "[email protected]") | |
page.fill("input[name='password']", "password") | |
page.click("text=Login") | |
page.wait_for_timeout(3000) | |
# 3️⃣ Verifikasi status awal | |
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}") | |
# 4️⃣ Klik "Upload Document" dan pilih file | |
page.click("text=Upload Document") | |
page.wait_for_timeout(2000) | |
page.set_input_files("input[type='file']", FILE_PATH) | |
page.click("text=Upload") | |
page.wait_for_timeout(3000) | |
# 5️⃣ Klik "Start Scraping" | |
page.click("text=Start Scraping") | |
page.wait_for_timeout(1000) | |
# Memilih item dari Dropdown Scraping | |
items = page.query_selector_all("//div[contains(@class,'menu-item')]") # contoh | |
if items: | |
item = random.choice(items) | |
item.click() | |
page.wait_for_timeout(3000) | |
# 6️⃣ Klik "Filter All Semesters" | |
page.click("text=All Semesters") | |
page.wait_for_timeout(2000) | |
# 7️⃣ Klik "Refresh" | |
page.click("text=Refresh") | |
page.wait_for_timeout(2000) | |
# 8️⃣ Klik "Log Out" | |
page.click("text=Log Out") | |
page.wait_for_timeout(2000) | |
print("✅ Test Admin Page selesai!") | |
browser.close() | |
if __name__ == "__main__": | |
run_test() | |