Explorer
/proc/2012/task/2113/root/tmp/test_question_dashboard.py
← Zurück ↓ Download
from playwright.sync_api import sync_playwright
from pathlib import Path
import json
url='http://127.0.0.1:5004/wissenspipeline/fragen'
question='Welche Empfehlung ergibt sich aus Zweck, Betrieb und Entscheidungsregel gemeinsam für eine Wissenslösung?'
with sync_playwright() as p:
    browser=p.chromium.launch(headless=True, executable_path='/snap/bin/chromium', args=['--no-sandbox'])
    page=browser.new_page(viewport={'width':1440,'height':1000})
    errors=[]; failed=[]
    page.on('console',lambda m: errors.append(m.text) if m.type=='error' else None)
    page.on('requestfailed',lambda r: failed.append({'url':r.url,'failure':r.failure}))
    page.goto(url,wait_until='domcontentloaded')
    visible={
      'title':page.locator('h1').inner_text(),
      'textarea':page.locator('#question').is_visible(),
      'button':page.locator('#ask-button').inner_text(),
      'answer_hidden_before':page.locator('#answer-panel').is_hidden(),
      'sources_hidden_before':page.locator('#sources-panel').is_hidden(),
    }
    page.locator('#question').fill(question)
    page.locator('#ask-button').click()
    try: page.wait_for_selector('#answer-panel:not([hidden])',timeout=150000)
    except Exception: pass
    page.screenshot(path='/home/hermes/Wissenspipeline-Frage-Dashboard-E2E.png',full_page=True)
    result={'url':url,'visible':visible,'question_value':page.locator('#question').input_value(),'status':page.locator('#status').inner_text(),'answer_visible':page.locator('#answer-panel').is_visible(),'answer_text':page.locator('#answer').inner_text(),'sources_visible':page.locator('#sources-panel').is_visible(),'sources_text':page.locator('#sources').inner_text(),'console_errors':errors,'request_failures':failed}
    Path('/tmp/frage_dashboard_e2e.json').write_text(json.dumps(result,ensure_ascii=False,indent=2))
    print(json.dumps(result,ensure_ascii=False,indent=2))
    browser.close()