BlueGit

projects-timfalken-com meteors

t1201: Playwright check

timfa Grok Bot · pushed by timfa

Authored 2026-11-15 · 2 days ago

Hash
be32c794bc3b28b0a47162a1d034470fcca3e1e4
Parent
d737b508
1 file changed +66 −0
test/t1201-menu-modes-playwright.py added +66 −0
@@ -0,0 +1,66 @@
1 """t1201: Play = rounds vs bots, Survival = endless solo. Usage: python3 test/t1201-menu-modes-playwright.py ROOT [tag]"""
2 import sys
3 from playwright.sync_api import sync_playwright
4 URL = sys.argv[1].rstrip("/") + "/"
5 TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
6 fails = []
7 def check(ok, msg):
8 print(("OK " if ok else "FAIL ") + msg)
9 if not ok: fails.append(msg)
10
11 def press(page, sel, mobile):
12 if mobile: page.tap(sel)
13 else: page.click(sel)
14
15 with sync_playwright() as p:
16 br = p.chromium.launch()
17 for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
18 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=2 if mobile else 1)
19 page = ctx.new_page(); errs = []
20 page.on("pageerror", lambda e: errs.append(str(e)))
21 page.goto(URL + "index.html", wait_until="networkidle")
22 pre = f"/workspace/meteors-shots/t1201-{TAG}-{name}-"
23 # English labels
24 check(page.inner_text("#btn-play").strip().lower() == "play" and page.inner_text("#btn-survival").strip().lower() == "survival", f"{name}: en menu {page.inner_text('#btn-play')!r} / {page.inner_text('#btn-survival')!r}")
25 check(page.locator("#btn-offline").count() == 0, f"{name}: no Offline Battle button")
26 page.screenshot(path=pre + "menu-en.png")
27 page.evaluate("() => I18n.setLocale('nl')"); page.wait_for_timeout(300)
28 check(page.inner_text("#btn-play").strip().lower() == "spelen" and page.inner_text("#btn-survival").strip().lower() == "overleven", f"{name}: nl menu {page.inner_text('#btn-play')!r} / {page.inner_text('#btn-survival')!r}")
29 page.screenshot(path=pre + "menu-nl.png")
30 # Spelen -> bot rounds
31 press(page, "#btn-play", mobile); page.wait_for_selector("#planet-select:not([hidden])")
32 check(page.inner_text("#planet-mode").strip().lower() == "spelen" and page.evaluate("() => app.planetSelectContext") == "offline", f"{name}: Spelen → planet select for rounds ({page.inner_text('#planet-mode')!r})")
33 page.screenshot(path=pre + "planet-spelen.png")
34 press(page, "#btn-planet-go", mobile)
35 page.wait_for_function("() => app.mode === 'playing'")
36 check(page.evaluate("() => !!(app.offline && app.battle)"), f"{name}: Spelen starts the rounds against bots")
37 check(page.is_visible("#offline-hud"), f"{name}: round HUD visible ({page.inner_text('#offline-hud')!r})")
38 press(page, "#btn-game-menu", mobile); page.wait_for_selector("#game-menu:not([hidden])")
39 check(page.inner_text("#game-menu-mode").strip().lower() == "spelen", f"{name}: pause menu names Spelen")
40 page.screenshot(path=pre + "pause-spelen.png")
41 press(page, "#btn-game-resume", mobile); page.wait_for_timeout(200)
42 page.evaluate("() => { app.core.state = 'gameover'; }")
43 page.wait_for_selector("#offline-result:not([hidden])", timeout=15000)
44 title = page.inner_text("#offline-result h2").strip()
45 check(title == "Uitslag", f"{name}: rounds result title {title!r} (no 'Offline Strijd')")
46 page.screenshot(path=pre + "result-spelen.png")
47 press(page, "#btn-offline-menu", mobile); page.wait_for_selector("#menu:not([hidden])")
48 # Overleven -> endless solo
49 press(page, "#btn-survival", mobile); page.wait_for_selector("#planet-select:not([hidden])")
50 check(page.inner_text("#planet-mode").strip().lower() == "overleven" and page.evaluate("() => app.planetSelectContext") == "solo", f"{name}: Overleven → planet select for endless ({page.inner_text('#planet-mode')!r})")
51 page.screenshot(path=pre + "planet-overleven.png")
52 press(page, "#btn-planet-go", mobile)
53 page.wait_for_function("() => app.mode === 'playing'")
54 check(page.evaluate("() => !app.offline && !app.battle && !app.online"), f"{name}: Overleven starts endless solo")
55 check(not page.is_visible("#offline-hud"), f"{name}: no round HUD in Overleven")
56 press(page, "#btn-game-menu", mobile); page.wait_for_selector("#game-menu:not([hidden])")
57 check(page.inner_text("#game-menu-mode").strip().lower() == "overleven", f"{name}: pause menu names Overleven")
58 page.screenshot(path=pre + "pause-overleven.png")
59 press(page, "#btn-game-quit", mobile) if page.locator("#btn-game-quit").count() else page.click("#game-menu button:nth-of-type(2)")
60 page.wait_for_selector("#menu:not([hidden])", timeout=10000)
61 check(page.evaluate("() => app.mode") == "menu", f"{name}: quitting Overleven returns to the main menu")
62 check(not errs, f"{name}: no page errors {errs}")
63 ctx.close()
64 br.close()
65 print("ALL OK" if not fails else f"{len(fails)} FAILED")
66 sys.exit(1 if fails else 0)
@@ -0,0 +1,66 @@
1"""t1201: Play = rounds vs bots, Survival = endless solo. Usage: python3 test/t1201-menu-modes-playwright.py ROOT [tag]"""
2import sys
3from playwright.sync_api import sync_playwright
4URL = sys.argv[1].rstrip("/") + "/"
5TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
6fails = []
7def check(ok, msg):
8 print(("OK " if ok else "FAIL ") + msg)
9 if not ok: fails.append(msg)
10
11def press(page, sel, mobile):
12 if mobile: page.tap(sel)
13 else: page.click(sel)
14
15with sync_playwright() as p:
16 br = p.chromium.launch()
17 for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
18 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=2 if mobile else 1)
19 page = ctx.new_page(); errs = []
20 page.on("pageerror", lambda e: errs.append(str(e)))
21 page.goto(URL + "index.html", wait_until="networkidle")
22 pre = f"/workspace/meteors-shots/t1201-{TAG}-{name}-"
23 # English labels
24 check(page.inner_text("#btn-play").strip().lower() == "play" and page.inner_text("#btn-survival").strip().lower() == "survival", f"{name}: en menu {page.inner_text('#btn-play')!r} / {page.inner_text('#btn-survival')!r}")
25 check(page.locator("#btn-offline").count() == 0, f"{name}: no Offline Battle button")
26 page.screenshot(path=pre + "menu-en.png")
27 page.evaluate("() => I18n.setLocale('nl')"); page.wait_for_timeout(300)
28 check(page.inner_text("#btn-play").strip().lower() == "spelen" and page.inner_text("#btn-survival").strip().lower() == "overleven", f"{name}: nl menu {page.inner_text('#btn-play')!r} / {page.inner_text('#btn-survival')!r}")
29 page.screenshot(path=pre + "menu-nl.png")
30 # Spelen -> bot rounds
31 press(page, "#btn-play", mobile); page.wait_for_selector("#planet-select:not([hidden])")
32 check(page.inner_text("#planet-mode").strip().lower() == "spelen" and page.evaluate("() => app.planetSelectContext") == "offline", f"{name}: Spelen → planet select for rounds ({page.inner_text('#planet-mode')!r})")
33 page.screenshot(path=pre + "planet-spelen.png")
34 press(page, "#btn-planet-go", mobile)
35 page.wait_for_function("() => app.mode === 'playing'")
36 check(page.evaluate("() => !!(app.offline && app.battle)"), f"{name}: Spelen starts the rounds against bots")
37 check(page.is_visible("#offline-hud"), f"{name}: round HUD visible ({page.inner_text('#offline-hud')!r})")
38 press(page, "#btn-game-menu", mobile); page.wait_for_selector("#game-menu:not([hidden])")
39 check(page.inner_text("#game-menu-mode").strip().lower() == "spelen", f"{name}: pause menu names Spelen")
40 page.screenshot(path=pre + "pause-spelen.png")
41 press(page, "#btn-game-resume", mobile); page.wait_for_timeout(200)
42 page.evaluate("() => { app.core.state = 'gameover'; }")
43 page.wait_for_selector("#offline-result:not([hidden])", timeout=15000)
44 title = page.inner_text("#offline-result h2").strip()
45 check(title == "Uitslag", f"{name}: rounds result title {title!r} (no 'Offline Strijd')")
46 page.screenshot(path=pre + "result-spelen.png")
47 press(page, "#btn-offline-menu", mobile); page.wait_for_selector("#menu:not([hidden])")
48 # Overleven -> endless solo
49 press(page, "#btn-survival", mobile); page.wait_for_selector("#planet-select:not([hidden])")
50 check(page.inner_text("#planet-mode").strip().lower() == "overleven" and page.evaluate("() => app.planetSelectContext") == "solo", f"{name}: Overleven → planet select for endless ({page.inner_text('#planet-mode')!r})")
51 page.screenshot(path=pre + "planet-overleven.png")
52 press(page, "#btn-planet-go", mobile)
53 page.wait_for_function("() => app.mode === 'playing'")
54 check(page.evaluate("() => !app.offline && !app.battle && !app.online"), f"{name}: Overleven starts endless solo")
55 check(not page.is_visible("#offline-hud"), f"{name}: no round HUD in Overleven")
56 press(page, "#btn-game-menu", mobile); page.wait_for_selector("#game-menu:not([hidden])")
57 check(page.inner_text("#game-menu-mode").strip().lower() == "overleven", f"{name}: pause menu names Overleven")
58 page.screenshot(path=pre + "pause-overleven.png")
59 press(page, "#btn-game-quit", mobile) if page.locator("#btn-game-quit").count() else page.click("#game-menu button:nth-of-type(2)")
60 page.wait_for_selector("#menu:not([hidden])", timeout=10000)
61 check(page.evaluate("() => app.mode") == "menu", f"{name}: quitting Overleven returns to the main menu")
62 check(not errs, f"{name}: no page errors {errs}")
63 ctx.close()
64 br.close()
65print("ALL OK" if not fails else f"{len(fails)} FAILED")
66sys.exit(1 if fails else 0)