test: Playwright touch on Android- and iOS-like viewports
Real CDP touch sequences (hasTouch, isMobile) cover instant grab, immediate click tween, no-hold drag, fast swipe without skips, diagonal column lock, and snap. Run locally; CI stays on node --test.
@@ -0,0 +1,353 @@
1
#!/usr/bin/env python3
2
"""Touch input for Meteors: real touch sequences on Android- and iOS-like viewports."""
3
from __future__ import annotations
4
5
import json
6
import sys
7
import time
8
import subprocess
9
import socket
10
from pathlib import Path
11
12
from playwright.sync_api import sync_playwright
13
14
OUT = Path("/workspace/meteors-shots")
15
OUT.mkdir(parents=True, exist_ok=True)
16
ROOT = Path("/workspace/meteors")
17
CHROME = "/usr/bin/google-chrome"
18
CHROME_ARGS = [
19
"--use-gl=angle",
20
"--use-angle=swiftshader",
21
"--no-sandbox",
22
"--disable-dev-shm-usage",
23
"--disable-gpu-sandbox",
24
]
25
26
ANDROID = {
27
"name": "android-chrome",
28
"viewport": {"width": 393, "height": 851},
29
"device_scale_factor": 2,
30
"is_mobile": True,
31
"has_touch": True,
32
"user_agent": (
33
"Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 "
34
"(KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"
35
),
36
}
37
IOS = {
38
"name": "ios-safari",
39
"viewport": {"width": 390, "height": 844},
40
"device_scale_factor": 2,
41
"is_mobile": True,
42
"has_touch": True,
43
"user_agent": (
44
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) "
45
"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 "
46
"Mobile/15E148 Safari/604.1"
47
),
48
}
49
50
FAILURES = []
51
LOG = []
52
53
54
def free_port():
55
s = socket.socket()
56
s.bind(("127.0.0.1", 0))
57
port = s.getsockname()[1]
58
s.close()
59
return port
60
61
62
def field_to_client(page, col, field_y):
63
return page.evaluate(
64
"""([col, fieldY]) => {
65
const c = app.scene.canvas;
66
const r = c.getBoundingClientRect();
67
const x = (col + 0.5) * app.tile;
68
const y = c.height - fieldY * app.tile;
69
return {
70
x: r.left + x * (r.width / c.width),
71
y: r.top + y * (r.height / c.height)
72
};
73
}""",
74
[col, field_y],
75
)
76
77
78
def touch_start(cdp, x, y):
79
cdp.send(
80
"Input.dispatchTouchEvent",
81
{"type": "touchStart", "touchPoints": [{"x": x, "y": y, "id": 0, "force": 1.0}]},
82
)
83
84
85
def touch_move(cdp, x, y):
86
cdp.send(
87
"Input.dispatchTouchEvent",
88
{"type": "touchMove", "touchPoints": [{"x": x, "y": y, "id": 0, "force": 1.0}]},
89
)
90
91
92
def touch_end(cdp):
93
cdp.send("Input.dispatchTouchEvent", {"type": "touchEnd", "touchPoints": []})
94
95
96
def touch_drag(cdp, x1, y1, x2, y2, steps=16):
97
touch_start(cdp, x1, y1)
98
for i in range(1, steps + 1):
99
t = i / steps
100
touch_move(cdp, x1 + (x2 - x1) * t, y1 + (y2 - y1) * t)
101
touch_end(cdp)
102
103
104
def reset_board(page, stacks):
105
"""stacks: {col: [colors from bottom]}"""
106
page.evaluate(
107
"""(stacks) => {
108
const g = app.core;
109
g.spawnInterval = 1e9;
110
g.spawnTimer = 0;
111
g.blocks.length = 0;
112
g.clusters = Object.create(null);
113
g.score = 0;
114
g.drag = null;
115
g.state = 'playing';
116
g.nextBlockId = 1;
117
g.nextClusterId = 1;
118
app.selectTween = null;
119
for (const [col, colors] of Object.entries(stacks)) {
120
colors.forEach((color, row) => g.place(+col, row, color));
121
}
122
}""",
123
stacks,
124
)
125
page.evaluate("() => { if (typeof syncSprites === 'function') { /* maybe closed */ } }")
126
# Give the view one frame to draw.
127
page.wait_for_timeout(80)
128
129
130
def board(page):
131
return page.evaluate(
132
"""() => app.core.blocks.map((b) => ({
133
id: b.id, col: b.col, y: b.y, color: b.color, state: b.state
134
}))"""
135
)
136
137
138
def grab_state(page):
139
return page.evaluate(
140
"""() => ({
141
drag: app.core.drag && {
142
blockId: app.core.drag.blockId,
143
accum: app.core.drag.accum,
144
startedAsTop: app.core.drag.startedAsTop
145
},
146
tween: app.selectTween && {
147
phase: app.selectTween.phase,
148
scale: app.selectTween.scale,
149
t: app.selectTween.t,
150
blockId: app.selectTween.blockId
151
}
152
})"""
153
)
154
155
156
def check(cond, msg, device):
157
if not cond:
158
FAILURES.append(f"[{device}] {msg}")
159
print(f"FAIL [{device}] {msg}")
160
else:
161
print(f"OK [{device}] {msg}")
162
return cond
163
164
165
def shot(page, name):
166
path = OUT / name
167
page.screenshot(path=str(path), full_page=False)
168
print(f"wrote {path} ({path.stat().st_size} bytes)")
169
return path
170
171
172
def start_play(page):
173
page.goto(URL, wait_until="networkidle", timeout=20000)
174
page.wait_for_timeout(400)
175
btn = page.locator("#btn-play")
176
btn.wait_for(state="visible", timeout=5000)
177
# Real touch tap on the Play button (mobile browsers may swallow click).
178
box = btn.bounding_box()
179
cdp = page.context.new_cdp_session(page)
180
touch_drag(
181
cdp,
182
box["x"] + box["width"] / 2,
183
box["y"] + box["height"] / 2,
184
box["x"] + box["width"] / 2,
185
box["y"] + box["height"] / 2,
186
steps=1,
187
)
188
page.wait_for_timeout(400)
189
# Fallback if the touch didn't start the game (desktop-like click path).
190
if page.evaluate("() => app.mode") != "playing":
191
btn.click()
192
page.wait_for_timeout(400)
193
page.wait_for_function("() => app && app.mode === 'playing' && app.core && app.scene", timeout=8000)
194
page.wait_for_selector("canvas", state="visible", timeout=5000)
195
return cdp
196
197
198
def run_device(browser, device):
199
name = device["name"]
200
print(f"\n======== {name} ========")
201
context = browser.new_context(
202
viewport=device["viewport"],
203
device_scale_factor=device["device_scale_factor"],
204
is_mobile=device["is_mobile"],
205
has_touch=device["has_touch"],
206
user_agent=device["user_agent"],
207
)
208
page = context.new_page()
209
bag = []
210
page.on("console", lambda m: bag.append(f"{m.type}: {m.text}"))
211
page.on("pageerror", lambda e: bag.append(f"pageerror: {e}"))
212
cdp = start_play(page)
213
check(page.evaluate("() => app.mode") == "playing", "play started", name)
214
shot(page, f"t1102-touch-{name}-play.png")
215
216
# --- Instant grab + click tween starts on pointerdown, no hold delay ---
217
reset_board(page, {"2": [0, 1, 2, 3, 4]})
218
page.wait_for_timeout(120)
219
pos = field_to_client(page, 2, 1.5) # centre of the block at y=1
220
touch_start(cdp, pos["x"], pos["y"])
221
# No wait-for-hold: inspect immediately, then after one frame.
222
page.wait_for_timeout(16)
223
st = grab_state(page)
224
check(st.get("drag") is not None, f"instant grab on pointerdown, state={st}", name)
225
tw = st.get("tween") or {}
226
check(
227
tw.get("phase") in ("press", "hold") and tw.get("blockId") is not None,
228
f"click tween starts immediately on pointerdown, tween={tw}",
229
name,
230
)
231
# Drag without any extra hold delay: swipe up two tiles.
232
dest = field_to_client(page, 2, 1.5 + 2)
233
for i in range(1, 9):
234
t = i / 8
235
touch_move(cdp, pos["x"], pos["y"] + (dest["y"] - pos["y"]) * t)
236
page.wait_for_timeout(40)
237
mid = board(page)
238
# The grabbed block (color 1 at y=1) should have moved up.
239
grabbed = [b for b in mid if b["color"] == 1]
240
check(
241
grabbed and grabbed[0]["y"] >= 2.9,
242
f"immediate drag (no hold) swaps upward, grabbed={grabbed}",
243
name,
244
)
245
touch_end(cdp)
246
page.wait_for_timeout(80)
247
248
# --- Fast swipe: several tiles in a short sequence, no skip ---
249
reset_board(page, {"3": [0, 1, 2, 3, 4]})
250
page.wait_for_timeout(80)
251
p0 = field_to_client(page, 3, 0.5)
252
p1 = field_to_client(page, 3, 0.5 + 4)
253
# Few steps: a fast swipe that jumps a long way between events.
254
touch_drag(cdp, p0["x"], p0["y"], p1["x"], p1["y"], steps=3)
255
page.wait_for_timeout(80)
256
after = {b["color"]: b["y"] for b in board(page) if b["col"] == 3}
257
check(
258
after.get(0) == 4,
259
f"fast swipe walks every tile (bottom ends at top), after={after}",
260
name,
261
)
262
check(
263
after.get(1) == 0 and after.get(2) == 1 and after.get(3) == 2 and after.get(4) == 3,
264
f"fast swipe does not skip neighbours, after={after}",
265
name,
266
)
267
shot(page, f"t1102-touch-{name}-after-swipe.png")
268
269
# --- Horizontal slop: slightly diagonal swipe stays in column ---
270
reset_board(page, {"4": [0, 1, 2, 3], "5": [3, 4, 0, 1]})
271
page.wait_for_timeout(80)
272
q0 = field_to_client(page, 4, 0.5)
273
q1 = field_to_client(page, 4.4, 0.5 + 3) # drift 0.4 tiles toward col 5
274
# field_to_client uses (col+0.5)*tile, so 4.4 means 0.4 into the slop visually.
275
q1 = field_to_client(page, 4.4, 3.5)
276
colors_before_5 = [b["color"] for b in sorted(board(page), key=lambda b: b["y"]) if b["col"] == 5]
277
touch_drag(cdp, q0["x"], q0["y"], q1["x"], q1["y"], steps=10)
278
page.wait_for_timeout(80)
279
col4 = {b["color"]: (b["y"], b["col"]) for b in board(page) if b["color"] == 0 and b["state"] == "still"}
280
moved = [b for b in board(page) if b["color"] == 0 and b.get("id") is not None]
281
# The bottom block of col 4 (color 0) should be at the top of col 4, not in col 5.
282
bottoms = [b for b in board(page) if b["col"] == 4]
283
top4 = max(bottoms, key=lambda b: b["y"]) if bottoms else None
284
colors_after_5 = [b["color"] for b in sorted(board(page), key=lambda b: b["y"]) if b["col"] == 5]
285
check(
286
top4 and top4["color"] == 0 and top4["col"] == 4,
287
f"diagonal drag stays in starting column, top4={top4}, col5={colors_after_5}",
288
name,
289
)
290
check(
291
colors_after_5 == colors_before_5,
292
f"neighbour column untouched, before={colors_before_5} after={colors_after_5}",
293
name,
294
)
295
shot(page, f"t1102-touch-{name}-diagonal.png")
296
297
# --- Snap: press slightly above the top block still grabs it ---
298
reset_board(page, {"1": [2, 3]})
299
page.wait_for_timeout(80)
300
# Top block occupies [1, 2); press at 2.25 (0.25 above).
301
s = field_to_client(page, 1, 2.25)
302
touch_start(cdp, s["x"], s["y"])
303
page.wait_for_timeout(16)
304
st = grab_state(page)
305
check(st.get("drag") is not None, f"snap-grab slightly above the block, state={st}", name)
306
touch_end(cdp)
307
page.wait_for_timeout(50)
308
309
if bag:
310
print(f"console [{name}]: {bag[:8]}")
311
context.close()
312
313
314
def main():
315
global URL
316
port = free_port()
317
URL = f"http://127.0.0.1:{port}/"
318
print("serving", URL, "from", ROOT / "build")
319
httpd = subprocess.Popen(
320
["python3", "-m", "http.server", str(port), "--bind", "127.0.0.1", "--directory", str(ROOT / "build")],
321
stdout=subprocess.DEVNULL,
322
stderr=subprocess.DEVNULL,
323
)
324
try:
325
time.sleep(0.4)
326
with sync_playwright() as p:
327
browser = p.chromium.launch(
328
executable_path=CHROME,
329
args=CHROME_ARGS,
330
headless=True,
331
)
332
for device in (ANDROID, IOS):
333
run_device(browser, device)
334
browser.close()
335
finally:
336
httpd.terminate()
337
try:
338
httpd.wait(timeout=3)
339
except Exception:
340
httpd.kill()
341
342
print("\n======== summary ========")
343
if FAILURES:
344
print(f"{len(FAILURES)} failure(s):")
345
for f in FAILURES:
346
print(" -", f)
347
return 1
348
print("all touch tests passed")
349
return 0
350
351
352
if __name__ == "__main__":
353
sys.exit(main())
@@ -0,0 +1,353 @@1
#!/usr/bin/env python32
"""Touch input for Meteors: real touch sequences on Android- and iOS-like viewports."""3
from __future__ import annotations4
5
import json6
import sys7
import time8
import subprocess9
import socket10
from pathlib import Path11
12
from playwright.sync_api import sync_playwright13
14
OUT = Path("/workspace/meteors-shots")15
OUT.mkdir(parents=True, exist_ok=True)16
ROOT = Path("/workspace/meteors")17
CHROME = "/usr/bin/google-chrome"18
CHROME_ARGS = [19
"--use-gl=angle",20
"--use-angle=swiftshader",21
"--no-sandbox",22
"--disable-dev-shm-usage",23
"--disable-gpu-sandbox",24
]25
26
ANDROID = {27
"name": "android-chrome",28
"viewport": {"width": 393, "height": 851},29
"device_scale_factor": 2,30
"is_mobile": True,31
"has_touch": True,32
"user_agent": (33
"Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 "34
"(KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"35
),36
}37
IOS = {38
"name": "ios-safari",39
"viewport": {"width": 390, "height": 844},40
"device_scale_factor": 2,41
"is_mobile": True,42
"has_touch": True,43
"user_agent": (44
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) "45
"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 "46
"Mobile/15E148 Safari/604.1"47
),48
}49
50
FAILURES = []51
LOG = []52
53
54
def free_port():55
s = socket.socket()56
s.bind(("127.0.0.1", 0))57
port = s.getsockname()[1]58
s.close()59
return port60
61
62
def field_to_client(page, col, field_y):63
return page.evaluate(64
"""([col, fieldY]) => {65
const c = app.scene.canvas;66
const r = c.getBoundingClientRect();67
const x = (col + 0.5) * app.tile;68
const y = c.height - fieldY * app.tile;69
return {70
x: r.left + x * (r.width / c.width),71
y: r.top + y * (r.height / c.height)72
};73
}""",74
[col, field_y],75
)76
77
78
def touch_start(cdp, x, y):79
cdp.send(80
"Input.dispatchTouchEvent",81
{"type": "touchStart", "touchPoints": [{"x": x, "y": y, "id": 0, "force": 1.0}]},82
)83
84
85
def touch_move(cdp, x, y):86
cdp.send(87
"Input.dispatchTouchEvent",88
{"type": "touchMove", "touchPoints": [{"x": x, "y": y, "id": 0, "force": 1.0}]},89
)90
91
92
def touch_end(cdp):93
cdp.send("Input.dispatchTouchEvent", {"type": "touchEnd", "touchPoints": []})94
95
96
def touch_drag(cdp, x1, y1, x2, y2, steps=16):97
touch_start(cdp, x1, y1)98
for i in range(1, steps + 1):99
t = i / steps100
touch_move(cdp, x1 + (x2 - x1) * t, y1 + (y2 - y1) * t)101
touch_end(cdp)102
103
104
def reset_board(page, stacks):105
"""stacks: {col: [colors from bottom]}"""106
page.evaluate(107
"""(stacks) => {108
const g = app.core;109
g.spawnInterval = 1e9;110
g.spawnTimer = 0;111
g.blocks.length = 0;112
g.clusters = Object.create(null);113
g.score = 0;114
g.drag = null;115
g.state = 'playing';116
g.nextBlockId = 1;117
g.nextClusterId = 1;118
app.selectTween = null;119
for (const [col, colors] of Object.entries(stacks)) {120
colors.forEach((color, row) => g.place(+col, row, color));121
}122
}""",123
stacks,124
)125
page.evaluate("() => { if (typeof syncSprites === 'function') { /* maybe closed */ } }")126
# Give the view one frame to draw.127
page.wait_for_timeout(80)128
129
130
def board(page):131
return page.evaluate(132
"""() => app.core.blocks.map((b) => ({133
id: b.id, col: b.col, y: b.y, color: b.color, state: b.state134
}))"""135
)136
137
138
def grab_state(page):139
return page.evaluate(140
"""() => ({141
drag: app.core.drag && {142
blockId: app.core.drag.blockId,143
accum: app.core.drag.accum,144
startedAsTop: app.core.drag.startedAsTop145
},146
tween: app.selectTween && {147
phase: app.selectTween.phase,148
scale: app.selectTween.scale,149
t: app.selectTween.t,150
blockId: app.selectTween.blockId151
}152
})"""153
)154
155
156
def check(cond, msg, device):157
if not cond:158
FAILURES.append(f"[{device}] {msg}")159
print(f"FAIL [{device}] {msg}")160
else:161
print(f"OK [{device}] {msg}")162
return cond163
164
165
def shot(page, name):166
path = OUT / name167
page.screenshot(path=str(path), full_page=False)168
print(f"wrote {path} ({path.stat().st_size} bytes)")169
return path170
171
172
def start_play(page):173
page.goto(URL, wait_until="networkidle", timeout=20000)174
page.wait_for_timeout(400)175
btn = page.locator("#btn-play")176
btn.wait_for(state="visible", timeout=5000)177
# Real touch tap on the Play button (mobile browsers may swallow click).178
box = btn.bounding_box()179
cdp = page.context.new_cdp_session(page)180
touch_drag(181
cdp,182
box["x"] + box["width"] / 2,183
box["y"] + box["height"] / 2,184
box["x"] + box["width"] / 2,185
box["y"] + box["height"] / 2,186
steps=1,187
)188
page.wait_for_timeout(400)189
# Fallback if the touch didn't start the game (desktop-like click path).190
if page.evaluate("() => app.mode") != "playing":191
btn.click()192
page.wait_for_timeout(400)193
page.wait_for_function("() => app && app.mode === 'playing' && app.core && app.scene", timeout=8000)194
page.wait_for_selector("canvas", state="visible", timeout=5000)195
return cdp196
197
198
def run_device(browser, device):199
name = device["name"]200
print(f"\n======== {name} ========")201
context = browser.new_context(202
viewport=device["viewport"],203
device_scale_factor=device["device_scale_factor"],204
is_mobile=device["is_mobile"],205
has_touch=device["has_touch"],206
user_agent=device["user_agent"],207
)208
page = context.new_page()209
bag = []210
page.on("console", lambda m: bag.append(f"{m.type}: {m.text}"))211
page.on("pageerror", lambda e: bag.append(f"pageerror: {e}"))212
cdp = start_play(page)213
check(page.evaluate("() => app.mode") == "playing", "play started", name)214
shot(page, f"t1102-touch-{name}-play.png")215
216
# --- Instant grab + click tween starts on pointerdown, no hold delay ---217
reset_board(page, {"2": [0, 1, 2, 3, 4]})218
page.wait_for_timeout(120)219
pos = field_to_client(page, 2, 1.5) # centre of the block at y=1220
touch_start(cdp, pos["x"], pos["y"])221
# No wait-for-hold: inspect immediately, then after one frame.222
page.wait_for_timeout(16)223
st = grab_state(page)224
check(st.get("drag") is not None, f"instant grab on pointerdown, state={st}", name)225
tw = st.get("tween") or {}226
check(227
tw.get("phase") in ("press", "hold") and tw.get("blockId") is not None,228
f"click tween starts immediately on pointerdown, tween={tw}",229
name,230
)231
# Drag without any extra hold delay: swipe up two tiles.232
dest = field_to_client(page, 2, 1.5 + 2)233
for i in range(1, 9):234
t = i / 8235
touch_move(cdp, pos["x"], pos["y"] + (dest["y"] - pos["y"]) * t)236
page.wait_for_timeout(40)237
mid = board(page)238
# The grabbed block (color 1 at y=1) should have moved up.239
grabbed = [b for b in mid if b["color"] == 1]240
check(241
grabbed and grabbed[0]["y"] >= 2.9,242
f"immediate drag (no hold) swaps upward, grabbed={grabbed}",243
name,244
)245
touch_end(cdp)246
page.wait_for_timeout(80)247
248
# --- Fast swipe: several tiles in a short sequence, no skip ---249
reset_board(page, {"3": [0, 1, 2, 3, 4]})250
page.wait_for_timeout(80)251
p0 = field_to_client(page, 3, 0.5)252
p1 = field_to_client(page, 3, 0.5 + 4)253
# Few steps: a fast swipe that jumps a long way between events.254
touch_drag(cdp, p0["x"], p0["y"], p1["x"], p1["y"], steps=3)255
page.wait_for_timeout(80)256
after = {b["color"]: b["y"] for b in board(page) if b["col"] == 3}257
check(258
after.get(0) == 4,259
f"fast swipe walks every tile (bottom ends at top), after={after}",260
name,261
)262
check(263
after.get(1) == 0 and after.get(2) == 1 and after.get(3) == 2 and after.get(4) == 3,264
f"fast swipe does not skip neighbours, after={after}",265
name,266
)267
shot(page, f"t1102-touch-{name}-after-swipe.png")268
269
# --- Horizontal slop: slightly diagonal swipe stays in column ---270
reset_board(page, {"4": [0, 1, 2, 3], "5": [3, 4, 0, 1]})271
page.wait_for_timeout(80)272
q0 = field_to_client(page, 4, 0.5)273
q1 = field_to_client(page, 4.4, 0.5 + 3) # drift 0.4 tiles toward col 5274
# field_to_client uses (col+0.5)*tile, so 4.4 means 0.4 into the slop visually.275
q1 = field_to_client(page, 4.4, 3.5)276
colors_before_5 = [b["color"] for b in sorted(board(page), key=lambda b: b["y"]) if b["col"] == 5]277
touch_drag(cdp, q0["x"], q0["y"], q1["x"], q1["y"], steps=10)278
page.wait_for_timeout(80)279
col4 = {b["color"]: (b["y"], b["col"]) for b in board(page) if b["color"] == 0 and b["state"] == "still"}280
moved = [b for b in board(page) if b["color"] == 0 and b.get("id") is not None]281
# The bottom block of col 4 (color 0) should be at the top of col 4, not in col 5.282
bottoms = [b for b in board(page) if b["col"] == 4]283
top4 = max(bottoms, key=lambda b: b["y"]) if bottoms else None284
colors_after_5 = [b["color"] for b in sorted(board(page), key=lambda b: b["y"]) if b["col"] == 5]285
check(286
top4 and top4["color"] == 0 and top4["col"] == 4,287
f"diagonal drag stays in starting column, top4={top4}, col5={colors_after_5}",288
name,289
)290
check(291
colors_after_5 == colors_before_5,292
f"neighbour column untouched, before={colors_before_5} after={colors_after_5}",293
name,294
)295
shot(page, f"t1102-touch-{name}-diagonal.png")296
297
# --- Snap: press slightly above the top block still grabs it ---298
reset_board(page, {"1": [2, 3]})299
page.wait_for_timeout(80)300
# Top block occupies [1, 2); press at 2.25 (0.25 above).301
s = field_to_client(page, 1, 2.25)302
touch_start(cdp, s["x"], s["y"])303
page.wait_for_timeout(16)304
st = grab_state(page)305
check(st.get("drag") is not None, f"snap-grab slightly above the block, state={st}", name)306
touch_end(cdp)307
page.wait_for_timeout(50)308
309
if bag:310
print(f"console [{name}]: {bag[:8]}")311
context.close()312
313
314
def main():315
global URL316
port = free_port()317
URL = f"http://127.0.0.1:{port}/"318
print("serving", URL, "from", ROOT / "build")319
httpd = subprocess.Popen(320
["python3", "-m", "http.server", str(port), "--bind", "127.0.0.1", "--directory", str(ROOT / "build")],321
stdout=subprocess.DEVNULL,322
stderr=subprocess.DEVNULL,323
)324
try:325
time.sleep(0.4)326
with sync_playwright() as p:327
browser = p.chromium.launch(328
executable_path=CHROME,329
args=CHROME_ARGS,330
headless=True,331
)332
for device in (ANDROID, IOS):333
run_device(browser, device)334
browser.close()335
finally:336
httpd.terminate()337
try:338
httpd.wait(timeout=3)339
except Exception:340
httpd.kill()341
342
print("\n======== summary ========")343
if FAILURES:344
print(f"{len(FAILURES)} failure(s):")345
for f in FAILURES:346
print(" -", f)347
return 1348
print("all touch tests passed")349
return 0350
351
352
if __name__ == "__main__":353
sys.exit(main())