74 lines
2.9 KiB
Python
74 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Playwright · verify VM widget activé dans visual-management.html"""
|
|
import time, json
|
|
from pathlib import Path
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
TS = time.strftime("%Y%m%d-%H%M%S")
|
|
OUT = Path(f"/var/www/html/test-report/vm-post-activation-{TS}")
|
|
OUT.mkdir(parents=True, exist_ok=True)
|
|
|
|
URL = "https://weval-consulting.com/visual-management.html"
|
|
|
|
result = {"ts": TS, "url": URL}
|
|
|
|
try:
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True, args=["--no-sandbox"])
|
|
ctx = browser.new_context(
|
|
viewport={"width": 1440, "height": 1200},
|
|
record_video_dir=str(OUT),
|
|
ignore_https_errors=True,
|
|
)
|
|
page = ctx.new_page()
|
|
|
|
# Try direct (may hit auth redirect)
|
|
print(f"[load] {URL}", flush=True)
|
|
resp = page.goto(URL, wait_until="domcontentloaded", timeout=15000)
|
|
result["http"] = resp.status if resp else None
|
|
result["final_url"] = page.url
|
|
|
|
# Wait 3s for any redirect
|
|
time.sleep(3)
|
|
|
|
# Check if we got auth page or actual dashboard
|
|
body_len = page.evaluate("document.body.innerText.length")
|
|
result["body_len"] = body_len
|
|
result["page_title"] = page.title()[:80]
|
|
|
|
# Check if widget script tag exists in HTML (regardless of render)
|
|
has_script = page.evaluate("""
|
|
Array.from(document.querySelectorAll('script'))
|
|
.some(s => s.src && s.src.includes('dsh-vm-alerts-widget'))
|
|
""")
|
|
result["has_widget_script_tag"] = has_script
|
|
|
|
# If widget got loaded, check rendered elements
|
|
if has_script:
|
|
time.sleep(3) # wait widget fetch
|
|
result["widget_rendered"] = page.evaluate("!!document.querySelector('.dsh-vm-wrap')")
|
|
result["alerts_count"] = page.evaluate("document.querySelectorAll('.dsh-vm-alert').length")
|
|
result["stats_count"] = page.evaluate("document.querySelectorAll('.dsh-vm-stat').length")
|
|
|
|
page.screenshot(path=str(OUT / "vm-post.png"), full_page=True)
|
|
result["screenshot"] = str(OUT / "vm-post.png")
|
|
|
|
# Also test the test page (no auth) for proof
|
|
page.goto("https://weval-consulting.com/test-vm-widget.html", wait_until="domcontentloaded", timeout=15000)
|
|
time.sleep(5)
|
|
result["test_page_widget"] = page.evaluate("!!document.querySelector('.dsh-vm-wrap')")
|
|
result["test_page_alerts"] = page.evaluate("document.querySelectorAll('.dsh-vm-alert').length")
|
|
page.screenshot(path=str(OUT / "test-vm-widget-post.png"), full_page=True)
|
|
|
|
ctx.close()
|
|
browser.close()
|
|
|
|
print(f"[OK] result: {result}", flush=True)
|
|
except Exception as e:
|
|
result["error"] = str(e)
|
|
print(f"[FAIL] {e}", flush=True)
|
|
|
|
with open(OUT / "result.json","w") as f:
|
|
json.dump(result, f, indent=2)
|
|
print(f"[OUT] {OUT}")
|