File size: 2,046 Bytes
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
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()