Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	File size: 2,738 Bytes
			
			| e96fbd0 aa95ea3 e96fbd0 aa95ea3 e96fbd0 37841e6 e96fbd0 37841e6 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 | from playwright.sync_api import sync_playwright
import time
import os
URL = "https://yozora721-pnp-chatbot-v1.hf.space"
PERTANYAAN = "Halo"
SCREENSHOTS_DIR = "screenshots"
def kirim_pertanyaan(page, pertanyaan: str):
    """Kirim pertanyaan dan tunggu hingga ada respon baru."""
    jumlah_awal = len(page.query_selector_all('.msg'))
    page.locator('textarea[placeholder="Masukkan pertanyaan"]').fill(pertanyaan)
    page.keyboard.press("Enter")
    # Tunggu pesan baru
    page.wait_for_function(
        f"() => document.querySelectorAll('.msg').length > {jumlah_awal}",
        timeout=120_000
    )
def jumlah_tag_audio(page) -> int:
    """Hitung jumlah tag <audio>."""
    return len(page.query_selector_all("audio"))
def buat_screenshot(page, status: str):
    """Buat screenshot area chat .msg dan simpan dengan status tertentu."""
    os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
    chat_area = page.locator('.msg')
    chat_area.screenshot(path=f"{SCREENSHOTS_DIR}/chat_{status}.png")
    print(f"π· Screenshot area chat disimpan: {SCREENSHOTS_DIR}/chat_{status}.png")
def test_tts(page, aktif: bool):
    """Test untuk status TTS aktif/nonaktif."""
    status = "AKTIF" if aktif else "NONAKTIF"
    # Klik Toggle sesuai kebutuhan
    if aktif and page.locator('text=π Text-to-Speech Nonaktif').count() > 0:
        page.locator('text=π Text-to-Speech Nonaktif').click()
    elif not aktif and page.locator('text=π Text-to-Speech Aktif').count() > 0:
        page.locator('text=π Text-to-Speech Aktif').click()
    # Kirim pertanyaan
    kirim_pertanyaan(page, PERTANYAAN)
    # Hitung jumlah audio
    jumlah_audio = jumlah_tag_audio(page)
    if aktif:
        if jumlah_audio > 0:
            print(f"β
 [AKTIF] Ada {jumlah_audio} tag <audio> (sesuai ekspektasi).")
        else:
            print(f"β [AKTIF] Tidak ditemukan tag <audio>.")
    else:
        if jumlah_audio == 0:
            print(f"β
 [NONAKTIF] Tidak ditemukan tag <audio> (sesuai ekspektasi).")
        else:
            print(f"β [NONAKTIF] Ada {jumlah_audio} tag <audio>, tidak sesuai ekspektasi.")
    # Simpan screenshot area chat
    buat_screenshot(page, status)
    # Beri waktu sebelum test selanjutnya
    time.sleep(2)
def main():
    """Main entry point."""
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)  # True kalau tidak perlu lihat
        page = browser.new_page()
        page.goto(URL)
        # Test dengan TTS Aktif
        test_tts(page, True)
        # Test dengan TTS Nonaktif
        test_tts(page, False)
        browser.close()
        print("\nπ Selesai! Cek folder 'screenshots' untuk melihat area chat.")
if __name__ == '__main__':
    main()
 | 
