Spaces:
Running
Running
File size: 4,045 Bytes
e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
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()
|