DiplomovaPraca/scripts/evaluation/capture_demo.py

37 lines
2.4 KiB
Python

"""Exercise the real Streamlit UI and capture thesis illustrations."""
from pathlib import Path
from playwright.sync_api import sync_playwright, expect
root=Path(__file__).resolve().parents[2]
images=root/"ZAVERECNA_PRACA/ZAVERECNA_PRACA/images"
images.mkdir(exist_ok=True)
with sync_playwright() as p:
browser=p.chromium.launch(headless=True)
page=browser.new_page(viewport={"width":1440,"height":2200},device_scale_factor=1)
page.goto("http://localhost:8501",wait_until="domcontentloaded")
page.get_by_role("button",name="Opýtať sa",exact=True).wait_for(timeout=90000)
page.get_by_role("slider").nth(1).press("Home")
page.get_by_role("slider").nth(1).press("ArrowRight")
page.get_by_role("button",name="Na čo sa používa Aclexa?",exact=True).click()
expect(page.get_by_role("textbox",name="Otázka",exact=True)).to_have_value("Na čo sa používa Aclexa?",timeout=30000)
page.get_by_role("button",name="Opýtať sa",exact=True).click()
page.get_by_role("tab",name="Odpoveď",exact=True).wait_for(timeout=180000)
page.get_by_text("zdrojových úryvkov vrátených s touto odpoveďou",exact=False).wait_for(state="attached",timeout=90000)
errors=page.locator('[data-testid="stException"]')
if errors.count(): raise RuntimeError(errors.inner_text())
page.get_by_role("tabpanel",name="Odpoveď",exact=True).screenshot(path=str(images/"demo_odpoved.png"))
page.get_by_role("tab",name="Znalostný graf",exact=True).click()
page.locator('iframe').first.wait_for(timeout=30000)
page.frame_locator('iframe').first.locator('canvas').wait_for(timeout=30000)
frame=page.locator('iframe').first.content_frame
frame.locator('canvas').evaluate("el => new Promise(resolve => setTimeout(resolve, 2000))")
frame.locator('canvas').evaluate("el => { network.stopSimulation(); network.fit({animation:false}); }")
page.get_by_role("tabpanel",name="Znalostný graf",exact=True).screenshot(path=str(images/"demo_graf.png"))
page.get_by_role("tab",name="Zdroje z ADC",exact=True).click()
caption=page.get_by_text("zdrojových úryvkov vrátených s touto odpoveďou",exact=False)
caption.wait_for(timeout=30000)
if caption.inner_text().startswith("0 "): raise RuntimeError("Actual answer evidence is empty")
page.screenshot(path=str(images/"demo_zdroje.png"),full_page=True)
browser.close()
print("UI query, graph and source tabs verified; screenshots saved")