89 lines
3.4 KiB
Python
89 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Deep Playwright test L99 Brain chat with login"""
|
|
import json, time
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
SITE = "https://weval-consulting.com"
|
|
R = []
|
|
|
|
def log(t, s, d=""):
|
|
print(f" {'✅' if s=='P' else '❌'} {t}: {d}")
|
|
R.append({"test":t,"status":s,"detail":d})
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True, args=["--no-sandbox"])
|
|
ctx = browser.new_context(ignore_https_errors=True)
|
|
page = ctx.new_page()
|
|
|
|
# Capture console + network
|
|
console_log = []
|
|
page.on("console", lambda m: console_log.append(f"{m.type}:{m.text[:100]}"))
|
|
|
|
net_log = []
|
|
page.on("response", lambda r: net_log.append(f"{r.status}:{r.url[:80]}") if "master-api" in r.url or "autonomous" in r.url else None)
|
|
|
|
# 1. Login first
|
|
page.goto(f"{SITE}/login", timeout=20000, wait_until="domcontentloaded")
|
|
page.wait_for_timeout(2000)
|
|
user_inp = page.query_selector("input[name='user'],input[name='username'],input[type='text']")
|
|
pass_inp = page.query_selector("input[name='pass'],input[name='password'],input[type='password']")
|
|
if user_inp and pass_inp:
|
|
user_inp.fill("yacine")
|
|
pass_inp.fill("Weval@2026")
|
|
submit = page.query_selector("button[type='submit'],input[type='submit'],button:has-text('Login')")
|
|
if submit: submit.click()
|
|
page.wait_for_timeout(3000)
|
|
log("LOGIN", "P", "credentials submitted")
|
|
else:
|
|
log("LOGIN", "F", "no login form found")
|
|
|
|
# 2. Navigate to brain
|
|
page.goto(f"{SITE}/l99-brain.html", timeout=30000, wait_until="domcontentloaded")
|
|
page.wait_for_timeout(5000)
|
|
log("PAGE_LOAD", "P", f"title={page.title()[:50]}")
|
|
|
|
# 3. Type + click send
|
|
inp = page.query_selector("#inp")
|
|
sbtn = page.query_selector("#sbtn")
|
|
log("ELEMENTS", "P" if inp and sbtn else "F", f"inp={'Y' if inp else 'N'} sbtn={'Y' if sbtn else 'N'}")
|
|
|
|
page.fill("#inp", "status")
|
|
page.click("#sbtn")
|
|
log("CLICK_SEND", "P", "sent 'status'")
|
|
|
|
# 4. Wait for network response
|
|
page.wait_for_timeout(18000)
|
|
|
|
# 5. Check network calls
|
|
api_calls = [n for n in net_log if "master-api" in n or "autonomous" in n]
|
|
log("API_CALLED", "P" if api_calls else "F", str(api_calls[:3]))
|
|
|
|
# 6. Check console for errors
|
|
errors = [c for c in console_log if c.startswith("error:")]
|
|
log("JS_ERRORS", "P" if not errors else "F", str(errors[:3]) if errors else "0 errors")
|
|
|
|
# 7. Check DOM for response
|
|
msgs = page.query_selector_all(".mb")
|
|
contents = [m.text_content() for m in msgs]
|
|
last = contents[-1] if contents else ""
|
|
ok = len(last) > 10 and "Pas de reponse" not in last
|
|
log("RESPONSE", "P" if ok else "F", f"msgs={len(contents)} last_len={len(last)} preview='{last[:100]}'")
|
|
|
|
# 8. Screenshot
|
|
page.screenshot(path="/var/www/html/screenshots/brain-chat-deep.png")
|
|
log("SCREENSHOT", "P", "saved")
|
|
|
|
# 9. All console
|
|
print("\n --- CONSOLE LOG ---")
|
|
for c in console_log[-10:]: print(f" {c[:120]}")
|
|
print(f" --- NET LOG ({len(net_log)} calls) ---")
|
|
for n in net_log[:5]: print(f" {n}")
|
|
|
|
browser.close()
|
|
|
|
passed = sum(1 for r in R if r["status"] == "P")
|
|
print(f"\n{'='*60}")
|
|
print(f"L99 BRAIN DEEP TEST: {passed}/{len(R)} PASS")
|
|
print(f"{'='*60}")
|
|
json.dump({"pass":passed,"total":len(R),"tests":R}, open("/var/www/html/api/l99-brain-chat-test.json","w"), indent=2)
|