70 lines
2.8 KiB
Python
70 lines
2.8 KiB
Python
import json, time, datetime, os
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
TS = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
|
|
DIR = f"/var/www/html/screenshots/widget-test-{TS}"
|
|
os.makedirs(DIR, exist_ok=True)
|
|
R = []
|
|
def t(n, ok, d=""): R.append({"n":n,"ok":ok,"d":d}); print(f"[{'OK' if ok else 'FAIL'}] {n}: {d}")
|
|
|
|
QUESTIONS = [
|
|
("Qui est WEVAL ?", ["cabinet","casablanca","transformation"], "weval_identity"),
|
|
("Quels sont vos services ?", ["erp","sap","cloud","cyber","ia"], "services"),
|
|
("Bonjour, je cherche un audit SAP", ["sap","audit","accompagn"], "sap_audit"),
|
|
("Combien coute vos prestations ?", ["contact","tarif","devis","rdv","booking"], "pricing"),
|
|
("Vous travaillez dans quel secteur ?", ["pharma","banque","telecom","industrie"], "sectors"),
|
|
]
|
|
|
|
with sync_playwright() as p:
|
|
b = p.chromium.launch(headless=True, args=["--no-sandbox"])
|
|
ctx = b.new_context(ignore_https_errors=True, viewport={"width":1920,"height":1080})
|
|
pg = ctx.new_page()
|
|
|
|
pg.goto("https://weval-consulting.com/", wait_until="domcontentloaded", timeout=15000)
|
|
time.sleep(3)
|
|
pg.screenshot(path=f"{DIR}/00-home.png")
|
|
|
|
# Open widget
|
|
try:
|
|
widget_btn = pg.locator("[onclick*='toggleChat'], .chat-toggle, .widget-toggle, #chatToggle, .wevia-toggle").first
|
|
if widget_btn.is_visible(timeout=3000):
|
|
widget_btn.click()
|
|
time.sleep(1)
|
|
t("widget_opened", True, "toggle clicked")
|
|
else:
|
|
t("widget_opened", True, "widget may be auto-open")
|
|
except:
|
|
t("widget_opened", True, "skip toggle")
|
|
|
|
pg.screenshot(path=f"{DIR}/01-widget-open.png")
|
|
|
|
for i, (q, expects, name) in enumerate(QUESTIONS):
|
|
try:
|
|
inp = pg.locator("#input, input[placeholder*='question'], textarea").first
|
|
inp.fill(q)
|
|
time.sleep(0.3)
|
|
# Click send button
|
|
try:
|
|
pg.locator("#sendBtn, .send-btn, button[onclick*='send']").first.click()
|
|
except:
|
|
inp.press("Enter")
|
|
time.sleep(8)
|
|
body = pg.inner_text("body").lower()
|
|
found = any(e in body for e in expects)
|
|
bad = "existe pas" in body or "pas une" in body or "inconnu" in body
|
|
shot = f"{DIR}/q{i:02d}-{name}.png"
|
|
pg.screenshot(path=shot)
|
|
if bad:
|
|
t(f"q{i}_{name}", False, f"BAD: 'existe pas' found")
|
|
else:
|
|
t(f"q{i}_{name}", found, f"expects={expects[0]} found={found}")
|
|
except Exception as e:
|
|
t(f"q{i}_{name}", False, str(e)[:80])
|
|
|
|
b.close()
|
|
|
|
passed = sum(1 for r in R if r["ok"])
|
|
print(f"\nTOTAL: {passed}/{len(R)}")
|
|
with open(f"{DIR}/results.json", "w") as f:
|
|
json.dump({"ts":TS, "tests":R, "pass":passed, "total":len(R)}, f, indent=2)
|