t1196-t1198: Playwright checks
@@ -0,0 +1,117 @@
1
"""t1196 (last planet), t1197 (+x% combo), t1198 (defeated count) checks.
2
Usage: python3 test/t1196-t1198-playwright.py ROOT_URL [local]"""
3
import sys
4
from playwright.sync_api import sync_playwright
5
6
URL = sys.argv[1].rstrip("/") + "/"
7
LOCAL = len(sys.argv) > 2 and sys.argv[2] == "local"
8
SHOTS = "/workspace/meteors-shots/t1196-"
9
fails = []
10
def check(ok, msg):
11
print(("OK " if ok else "FAIL ") + msg)
12
if not ok: fails.append(msg)
13
14
def pick(page, pid):
15
page.click("#btn-play"); page.wait_for_selector("#planet-select:not([hidden])")
16
page.click(f'#planet-grid [data-planet="{pid}"]')
17
18
def selected(page):
19
return page.evaluate("() => app.selectedPlanetId")
20
21
with sync_playwright() as p:
22
br = p.chromium.launch()
23
# ---- logged out: localStorage
24
ctx = br.new_context(viewport={"width": 1280, "height": 800}); page = ctx.new_page()
25
errs = []; page.on("pageerror", lambda e: errs.append(str(e)))
26
page.goto(URL + "index.html", wait_until="networkidle")
27
ids = page.evaluate("() => Planet.allPlanets().map(p => p.id)")
28
other = [i for i in ids if i != "terra"][0]
29
pick(page, other); page.click("#btn-planet-go"); page.wait_for_timeout(300)
30
page.goto(URL + "index.html", wait_until="networkidle")
31
check(selected(page) == other, f"logged out: {other} remembered via localStorage after reload ({selected(page)})")
32
for btn, ctxname in (("#btn-play", "Spelen"), ("#btn-offline", "Offline Strijd")):
33
page.click(btn); page.wait_for_selector("#planet-select:not([hidden])")
34
sel = page.evaluate("() => (document.querySelector('#planet-grid .selected, #planet-grid [aria-pressed=\"true\"], #planet-grid [aria-selected=\"true\"]')||{}).dataset")
35
check(bool(sel) and sel.get("planet") == other, f"logged out: {ctxname} planet select pre-selects {other} ({sel})")
36
page.screenshot(path=SHOTS + f"preselect-{ctxname.split()[0].lower()}.png")
37
page.click("#btn-planet-back")
38
39
# ---- t1197 indicator + combo (offline, real core)
40
page.click("#btn-play"); page.wait_for_selector("#planet-select:not([hidden])"); page.click("#btn-planet-go")
41
page.wait_for_function("() => app.mode === 'playing' && app.core")
42
res = page.evaluate("""() => {
43
const g = app.core; g.noSpawn = true;
44
for (const b of Object.values(g.blocks || {})) {}
45
const out = [];
46
for (let k = 0; k < 3; k++) {
47
for (let c = 0; c < 10; c++) for (let y = 0; y < 13; y++) { const b = g.at ? g.at(c, y) : null; if (b) g.removeBlock && g.removeBlock(b); }
48
g.place(0, 0, 1 + k); g.place(1, 0, 1 + k); g.place(2, 0, 1 + k);
49
const l = g.resolveMatches();
50
out.push(l.length ? Math.round((l[0].chainBonus - 1) * 100) : null);
51
}
52
return { out, combo: g.combo, ind: g.lastChainIndicator };
53
}""")
54
page.wait_for_timeout(150)
55
txt = page.evaluate("() => { const e = document.getElementById('chain-indicator'); return e && !e.hidden ? e.textContent : null; }")
56
style = page.evaluate("() => { const s = getComputedStyle(document.getElementById('chain-indicator')); return [s.color, s.webkitTextStrokeColor, s.webkitTextStrokeWidth]; }")
57
check(res["out"] == [0, 5, 10], f"combo bonus per match {res['out']} (combo {res['combo']})")
58
check(txt == "+10%", f"indicator text {txt!r}")
59
check("255, 230, 0" in style[0] and "255, 122, 0" in style[1], f"yellow fill, orange stroke {style}")
60
page.screenshot(path=SHOTS.replace("t1196", "t1197") + "plus-pct.png")
61
el = page.locator("#chain-indicator")
62
if el.is_visible(): el.screenshot(path=SHOTS.replace("t1196", "t1197") + "plus-pct-crop.png")
63
page.evaluate("() => { for (let i = 0; i < 120; i++) app.core.tick(0.05); }")
64
check(page.evaluate("() => app.core.combo") == 0, "combo reset after 6 s without a match")
65
page.evaluate("() => teardownPlay && teardownPlay()") if False else None
66
ctx.close()
67
68
# ---- t1198 offline result text
69
ctx = br.new_context(viewport={"width": 1280, "height": 800}); page = ctx.new_page()
70
page.goto(URL + "index.html", wait_until="networkidle")
71
page.click("#btn-offline"); page.wait_for_selector("#planet-select:not([hidden])"); page.click("#btn-planet-go")
72
page.wait_for_function("() => app.battle && app.mode === 'playing'")
73
page.evaluate("() => { for (const b of app.battle.bots) b.core.state = 'gameover'; }")
74
page.wait_for_function("() => app.battle && app.battle.round === 2 && app.mode === 'playing'", timeout=15000)
75
page.evaluate("() => { app.battle.bots[0].core.state = 'gameover'; }")
76
page.wait_for_timeout(300)
77
page.evaluate("() => { app.core.state = 'gameover'; }")
78
page.wait_for_selector("#offline-result:not([hidden])", timeout=15000)
79
reached = page.inner_text("#offline-reached-line"); detail = page.inner_text("#offline-result-detail")
80
check(detail.strip() == "2 opponents defeated", f"en result: {reached!r} / {detail!r}")
81
page.screenshot(path=SHOTS.replace("t1196", "t1198") + "result-en.png")
82
page.evaluate("() => I18n.setLocale('nl'); ") if True else None
83
page.evaluate("() => { if (typeof showOfflineResult === 'function') { app.offlineResultShown = false; showOfflineResult(); } }")
84
page.wait_for_timeout(200)
85
detail_nl = page.inner_text("#offline-result-detail"); reached_nl = page.inner_text("#offline-reached-line")
86
check(detail_nl.strip() == "2 tegenstanders verslagen" and "bereikt" in reached_nl, f"nl result: {reached_nl!r} / {detail_nl!r}")
87
page.screenshot(path=SHOTS.replace("t1196", "t1198") + "result-nl.png")
88
ctx.close()
89
90
# ---- logged in: server profile (local test login only)
91
if LOCAL:
92
ctx = br.new_context(viewport={"width": 1280, "height": 800}); page = ctx.new_page()
93
page.goto(URL + "auth.php?test=2&next=index.html", wait_until="domcontentloaded")
94
page.goto(URL + "index.html", wait_until="networkidle")
95
page.wait_for_function("() => Online.me")
96
pid = page.evaluate("""async () => {
97
const cols = ['terra-ember','terra-aqua','terra-leaf','terra-sun','terra-orchid'];
98
const r = await Online.request('planet_save', { planet: { name: 'Proef', people: 'Proevers', jumpsToClear: 2.5, fallTime: 2, riseTime: 1, colors: cols } });
99
await Online.refresh(); return r.planet.id; }""")
100
pick(page, pid); page.click("#btn-planet-go"); page.wait_for_timeout(600)
101
ctx2 = br.new_context(viewport={"width": 1280, "height": 800}); p2 = ctx2.new_page()
102
p2.goto(URL + "auth.php?test=2&next=index.html", wait_until="domcontentloaded")
103
p2.goto(URL + "index.html", wait_until="networkidle"); p2.wait_for_function("() => Online.me")
104
p2.wait_for_timeout(400)
105
check(p2.evaluate("() => Online.lastPlanet") == pid and selected(p2) == pid, f"logged in: custom planet {pid} restored from the profile in a fresh browser ({selected(p2)})")
106
p2.click("#btn-online"); p2.wait_for_timeout(500)
107
p2.screenshot(path=SHOTS + "loggedin-online.png")
108
page.evaluate(f"async () => {{ await Online.request('planet_delete', {{ id: '{pid}' }}); }}")
109
ctx3 = br.new_context(viewport={"width": 1280, "height": 800}); p3 = ctx3.new_page()
110
p3.goto(URL + "auth.php?test=2&next=index.html", wait_until="domcontentloaded")
111
p3.goto(URL + "index.html", wait_until="networkidle"); p3.wait_for_function("() => Online.me"); p3.wait_for_timeout(400)
112
check(p3.evaluate("() => Online.lastPlanet") is None and selected(p3) == "terra", f"deleted custom planet → falls back to Terra ({selected(p3)})")
113
ctx.close(); ctx2.close(); ctx3.close()
114
check(not errs, f"no page errors {errs}")
115
br.close()
116
print("ALL OK" if not fails else f"{len(fails)} FAILED")
117
sys.exit(1 if fails else 0)
@@ -0,0 +1,117 @@1
"""t1196 (last planet), t1197 (+x% combo), t1198 (defeated count) checks.2
Usage: python3 test/t1196-t1198-playwright.py ROOT_URL [local]"""3
import sys4
from playwright.sync_api import sync_playwright5
6
URL = sys.argv[1].rstrip("/") + "/"7
LOCAL = len(sys.argv) > 2 and sys.argv[2] == "local"8
SHOTS = "/workspace/meteors-shots/t1196-"9
fails = []10
def check(ok, msg):11
print(("OK " if ok else "FAIL ") + msg)12
if not ok: fails.append(msg)13
14
def pick(page, pid):15
page.click("#btn-play"); page.wait_for_selector("#planet-select:not([hidden])")16
page.click(f'#planet-grid [data-planet="{pid}"]')17
18
def selected(page):19
return page.evaluate("() => app.selectedPlanetId")20
21
with sync_playwright() as p:22
br = p.chromium.launch()23
# ---- logged out: localStorage24
ctx = br.new_context(viewport={"width": 1280, "height": 800}); page = ctx.new_page()25
errs = []; page.on("pageerror", lambda e: errs.append(str(e)))26
page.goto(URL + "index.html", wait_until="networkidle")27
ids = page.evaluate("() => Planet.allPlanets().map(p => p.id)")28
other = [i for i in ids if i != "terra"][0]29
pick(page, other); page.click("#btn-planet-go"); page.wait_for_timeout(300)30
page.goto(URL + "index.html", wait_until="networkidle")31
check(selected(page) == other, f"logged out: {other} remembered via localStorage after reload ({selected(page)})")32
for btn, ctxname in (("#btn-play", "Spelen"), ("#btn-offline", "Offline Strijd")):33
page.click(btn); page.wait_for_selector("#planet-select:not([hidden])")34
sel = page.evaluate("() => (document.querySelector('#planet-grid .selected, #planet-grid [aria-pressed=\"true\"], #planet-grid [aria-selected=\"true\"]')||{}).dataset")35
check(bool(sel) and sel.get("planet") == other, f"logged out: {ctxname} planet select pre-selects {other} ({sel})")36
page.screenshot(path=SHOTS + f"preselect-{ctxname.split()[0].lower()}.png")37
page.click("#btn-planet-back")38
39
# ---- t1197 indicator + combo (offline, real core)40
page.click("#btn-play"); page.wait_for_selector("#planet-select:not([hidden])"); page.click("#btn-planet-go")41
page.wait_for_function("() => app.mode === 'playing' && app.core")42
res = page.evaluate("""() => {43
const g = app.core; g.noSpawn = true;44
for (const b of Object.values(g.blocks || {})) {}45
const out = [];46
for (let k = 0; k < 3; k++) {47
for (let c = 0; c < 10; c++) for (let y = 0; y < 13; y++) { const b = g.at ? g.at(c, y) : null; if (b) g.removeBlock && g.removeBlock(b); }48
g.place(0, 0, 1 + k); g.place(1, 0, 1 + k); g.place(2, 0, 1 + k);49
const l = g.resolveMatches();50
out.push(l.length ? Math.round((l[0].chainBonus - 1) * 100) : null);51
}52
return { out, combo: g.combo, ind: g.lastChainIndicator };53
}""")54
page.wait_for_timeout(150)55
txt = page.evaluate("() => { const e = document.getElementById('chain-indicator'); return e && !e.hidden ? e.textContent : null; }")56
style = page.evaluate("() => { const s = getComputedStyle(document.getElementById('chain-indicator')); return [s.color, s.webkitTextStrokeColor, s.webkitTextStrokeWidth]; }")57
check(res["out"] == [0, 5, 10], f"combo bonus per match {res['out']} (combo {res['combo']})")58
check(txt == "+10%", f"indicator text {txt!r}")59
check("255, 230, 0" in style[0] and "255, 122, 0" in style[1], f"yellow fill, orange stroke {style}")60
page.screenshot(path=SHOTS.replace("t1196", "t1197") + "plus-pct.png")61
el = page.locator("#chain-indicator")62
if el.is_visible(): el.screenshot(path=SHOTS.replace("t1196", "t1197") + "plus-pct-crop.png")63
page.evaluate("() => { for (let i = 0; i < 120; i++) app.core.tick(0.05); }")64
check(page.evaluate("() => app.core.combo") == 0, "combo reset after 6 s without a match")65
page.evaluate("() => teardownPlay && teardownPlay()") if False else None66
ctx.close()67
68
# ---- t1198 offline result text69
ctx = br.new_context(viewport={"width": 1280, "height": 800}); page = ctx.new_page()70
page.goto(URL + "index.html", wait_until="networkidle")71
page.click("#btn-offline"); page.wait_for_selector("#planet-select:not([hidden])"); page.click("#btn-planet-go")72
page.wait_for_function("() => app.battle && app.mode === 'playing'")73
page.evaluate("() => { for (const b of app.battle.bots) b.core.state = 'gameover'; }")74
page.wait_for_function("() => app.battle && app.battle.round === 2 && app.mode === 'playing'", timeout=15000)75
page.evaluate("() => { app.battle.bots[0].core.state = 'gameover'; }")76
page.wait_for_timeout(300)77
page.evaluate("() => { app.core.state = 'gameover'; }")78
page.wait_for_selector("#offline-result:not([hidden])", timeout=15000)79
reached = page.inner_text("#offline-reached-line"); detail = page.inner_text("#offline-result-detail")80
check(detail.strip() == "2 opponents defeated", f"en result: {reached!r} / {detail!r}")81
page.screenshot(path=SHOTS.replace("t1196", "t1198") + "result-en.png")82
page.evaluate("() => I18n.setLocale('nl'); ") if True else None83
page.evaluate("() => { if (typeof showOfflineResult === 'function') { app.offlineResultShown = false; showOfflineResult(); } }")84
page.wait_for_timeout(200)85
detail_nl = page.inner_text("#offline-result-detail"); reached_nl = page.inner_text("#offline-reached-line")86
check(detail_nl.strip() == "2 tegenstanders verslagen" and "bereikt" in reached_nl, f"nl result: {reached_nl!r} / {detail_nl!r}")87
page.screenshot(path=SHOTS.replace("t1196", "t1198") + "result-nl.png")88
ctx.close()89
90
# ---- logged in: server profile (local test login only)91
if LOCAL:92
ctx = br.new_context(viewport={"width": 1280, "height": 800}); page = ctx.new_page()93
page.goto(URL + "auth.php?test=2&next=index.html", wait_until="domcontentloaded")94
page.goto(URL + "index.html", wait_until="networkidle")95
page.wait_for_function("() => Online.me")96
pid = page.evaluate("""async () => {97
const cols = ['terra-ember','terra-aqua','terra-leaf','terra-sun','terra-orchid'];98
const r = await Online.request('planet_save', { planet: { name: 'Proef', people: 'Proevers', jumpsToClear: 2.5, fallTime: 2, riseTime: 1, colors: cols } });99
await Online.refresh(); return r.planet.id; }""")100
pick(page, pid); page.click("#btn-planet-go"); page.wait_for_timeout(600)101
ctx2 = br.new_context(viewport={"width": 1280, "height": 800}); p2 = ctx2.new_page()102
p2.goto(URL + "auth.php?test=2&next=index.html", wait_until="domcontentloaded")103
p2.goto(URL + "index.html", wait_until="networkidle"); p2.wait_for_function("() => Online.me")104
p2.wait_for_timeout(400)105
check(p2.evaluate("() => Online.lastPlanet") == pid and selected(p2) == pid, f"logged in: custom planet {pid} restored from the profile in a fresh browser ({selected(p2)})")106
p2.click("#btn-online"); p2.wait_for_timeout(500)107
p2.screenshot(path=SHOTS + "loggedin-online.png")108
page.evaluate(f"async () => {{ await Online.request('planet_delete', {{ id: '{pid}' }}); }}")109
ctx3 = br.new_context(viewport={"width": 1280, "height": 800}); p3 = ctx3.new_page()110
p3.goto(URL + "auth.php?test=2&next=index.html", wait_until="domcontentloaded")111
p3.goto(URL + "index.html", wait_until="networkidle"); p3.wait_for_function("() => Online.me"); p3.wait_for_timeout(400)112
check(p3.evaluate("() => Online.lastPlanet") is None and selected(p3) == "terra", f"deleted custom planet → falls back to Terra ({selected(p3)})")113
ctx.close(); ctx2.close(); ctx3.close()114
check(not errs, f"no page errors {errs}")115
br.close()116
print("ALL OK" if not fails else f"{len(fails)} FAILED")117
sys.exit(1 if fails else 0)