Files
weval-l99/selenium_business_test.py
2026-04-20 15:39:16 +02:00

100 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""
V89 Selenium Business Scenario Test (headless chrome)
Scenarios testés:
1. WTP (weval-technology-platform.html) - page principale
2. WEVIA Master chat
3. CRM Bridge V68
4. Business KPI V83
5. Manifest endpoint
6. 15 Depts dashboard
"""
import sys, os, time, json, traceback
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
opts = Options()
opts.add_argument("--headless=new")
opts.add_argument("--no-sandbox")
opts.add_argument("--disable-dev-shm-usage")
opts.add_argument("--disable-gpu")
opts.add_argument("--window-size=1920,1080")
opts.add_argument("--ignore-certificate-errors")
opts.add_argument("--disable-web-security")
results = {"ts": time.strftime("%Y-%m-%dT%H:%M:%S"), "scenarios": [], "pass": 0, "fail": 0}
def run_scenario(name, url, expected_text=None, check_title=True, timeout=12):
"""Test a page: loads, title+body+screenshot + opt text match"""
driver = None
try:
driver = webdriver.Chrome(options=opts)
driver.set_page_load_timeout(timeout)
t0 = time.time()
driver.get(url)
load_time = round(time.time() - t0, 2)
title = driver.title
body = driver.find_element(By.TAG_NAME, "body").text[:300]
status = "PASS"
detail = {"title": title, "body_preview": body[:100], "load_time_s": load_time}
# 20avr fix: also check page_source (HTML) for SPA/API/auth-redirect pages
page_src = driver.page_source.lower() if expected_text else ""
if expected_text and expected_text.lower() not in body.lower() and expected_text.lower() not in title.lower() and expected_text.lower() not in page_src:
status = "WARN"
detail["missing_text"] = expected_text
# Screenshot
screenshot_path = f"/tmp/selenium_{name}.png"
driver.save_screenshot(screenshot_path)
detail["screenshot"] = screenshot_path
detail["screenshot_size"] = os.path.getsize(screenshot_path)
results["scenarios"].append({"name": name, "url": url, "status": status, **detail})
if status == "PASS": results["pass"] += 1
else: results["fail"] += 1
print(f" [{status}] {name:<30} load={load_time}s title='{title[:50]}'")
except Exception as e:
results["scenarios"].append({"name": name, "url": url, "status": "FAIL", "error": str(e)[:200]})
results["fail"] += 1
print(f" [FAIL] {name:<30} {str(e)[:100]}")
finally:
if driver: driver.quit()
print("=" * 70)
print("V89 SELENIUM BUSINESS SCENARIOS")
print("=" * 70)
scenarios = [
("wtp_main", "https://weval-consulting.com/weval-technology-platform.html", "WEVAL"),
("wevia_master", "https://weval-consulting.com/wevia-master.html", "WEVIA"),
("business_kpi", "https://weval-consulting.com/business-kpi-dashboard.php", "KPI"),
("crm_hub", "https://weval-consulting.com/crm.html", None),
("main_site", "https://weval-consulting.com/", "WEVAL"),
("manifest_api", "https://weval-consulting.com/api/weval-archi-manifest.php", "weval"),
("l99_honest", "https://weval-consulting.com/api/l99-honest.php", "6sigma"),
("depts_kpi", "https://weval-consulting.com/api/wevia-v64-departments-kpi.php", "departments"),
]
for name, url, expected in scenarios:
run_scenario(name, url, expected)
print()
print("=" * 70)
print(f"RESULTS: {results['pass']} PASS / {results['fail']} FAIL")
print("=" * 70)
# Save results
with open("/tmp/selenium_business_results.json", "w") as f:
json.dump(results, f, indent=2)
print(f"Saved: /tmp/selenium_business_results.json")
# Cleanup if ok
total = results["pass"] + results["fail"]
pct = round(100 * results["pass"] / total, 1) if total else 0
print(f"Pass rate: {pct}%")
sys.exit(0 if results["fail"] == 0 else 1)