Bash.tv → GitHub → itch.io

Automated browser testing for 2D and DOM web games with Playwright (playwright-cli). One-command playtests that press keys, hold directions, click, tap and drag, take screenshots at desktop and phone sizes, check game state through a debug handle, and report console errors, failed requests, frozen screens and input that did nothing. Also unit tests for pure game logic with node. Never runs WebG...

Download skill (.zip) Files on GitHub

Playwright game testing

WebGL, three.js, WebGPU pages: do not load them in the sandbox browser (no GPU). Use look_at_preview / control_preview in the viewer’s browser, or check_gpu_render. Everything below is for Canvas 2D and DOM games.

Make the game testable (one line)

Expose a read-only debug handle. The game-scaffolding template does it already:

window.__game = game;     // scenes.current, player position, score, …

Tests can then check real state (“reached play”, “score went up”) instead of guessing from pixels.

One-command playtest

python3 <skill>/scripts/playtest.py http://localhost:8000/                      # default smoke test, desktop + phone
python3 <skill>/scripts/playtest.py http://localhost:8000/ --steps steps.json --sizes desktop,phone,phone-landscape

Steps file:

[
  {"wait": 800}, {"shot": "title"},
  {"expect": "window.__game.scenes.current === 'title'", "name": "starts on title"},
  {"key": "Enter"},
  {"expect": "window.__game.scenes.current === 'play'", "name": "reached play"},
  {"hold": "ArrowRight", "ms": 600}, {"shot": "moved"},
  {"eval": "window.__game.scenes.stack.at(-1).player.x", "name": "player x"},
  {"tap": [340, 700]}, {"drag": [100, 400, 300, 400], "ms": 300},
  {"key": "Escape"}, {"expect": "window.__game.scenes.current === 'pause'", "name": "pauses"}
]

It reports page errors, console errors and warnings, failed or 4xx/5xx requests, every expect, whether each screenshot changed from the last (input did something), whether the screen is animating, canvas size vs viewport, and page scrolling. Inputs wait 120 ms after (--settle, or "after" per step) so the game can react. Exit code 1 on any failure.

Always look at the screenshots with the view tool before saying it works.

Interactive debugging

playwright-cli open http://localhost:8000/
playwright-cli press Enter
playwright-cli eval "JSON.stringify({scene: __game.scenes.current})"
playwright-cli screenshot --filename=/tmp/now.png
playwright-cli console
playwright-cli resize 390 844
playwright-cli close

Unit tests for game logic (fast, no browser)

Keep rules in pure modules (no DOM) and test them with node:

// tests/rules.test.mjs   →   node tests/rules.test.mjs
import { scoreFor, nextWave } from "../src/rules.js";
const ok = (name, v) => { console.log((v ? "PASS " : "FAIL ") + name); if (!v) process.exitCode = 1; };
ok("combo doubles", scoreFor({ combo: 5 }) === 20);
ok("wave 3 has 8 enemies", nextWave(3).count === 8);

Good targets: scoring, damage formulas, loot tables, pathfinding, save migration, level parsing, seeded generation (same seed gives the same map).

What to test after every change

  1. Title → play → pause → resume → lose → retry (and win, if reachable via a debug key or state eval).
  2. Desktop and phone sizes. Touch path (tap) as well as keys.
  3. Zero page errors. No 404s (wrong-case paths break on Linux hosts and itch.io).
  4. Input changes the screen. The game animates in play. It doesn’t scroll the page.

Tips