Sign-up form
A sign-up form, checked twice: on a laptop with clicks and keys, and on a phone with taps. The checks type into fields, press Enter, check the error and welcome messages with expect, and compare screenshots with their baselines.
Run it#
cd examples/form
npx brokit check --verbose # --verbose lists every step, as below$ brokit check --verbose
brokit check: 2 scenarios, Chrome 158.0.8127.36, software drawing
✓ checks/signup-phone 12 steps, 1.1 s, 2 baselines written
✓ expect document.documentElement.scrollWidth <= innerWidth truthy
✓ tap #name 155 ms
✓ type "Ana Pop"
✓ tap #email
✓ type "ana@example.com"
✓ tap #password
✓ type "correct horse battery"
✓ screenshot filled → brokit-out/checks/signup-phone/filled.png (786×1704) [baseline: new] 269 ms
✓ tap #submit
✓ expect document.querySelector('#welcome h2').textContent equals "Welcome, Ana"
✓ expect document.querySelector('#form').checkVisibility() equals false
✓ screenshot welcome → brokit-out/checks/signup-phone/welcome.png (786×1704) [baseline: new] 158 ms
✓ checks/signup 17 steps, 0.6 s, 2 baselines written
✓ click #name
✓ type "Ana Pop"
✓ click #email
✓ type "ana@example"
✓ key Enter
✓ expect document.querySelector('#email-error').textContent equals "Enter a valid email, like ana@example.com"
✓ expect document.activeElement.id equals "email"
✓ screenshot error → brokit-out/checks/signup/error.png (380×453) [baseline: new] 161 ms
✓ click #email
✓ type "ana@example.com"
✓ click #password
✓ type "correct horse battery"
✓ click #submit
✓ expect document.querySelector('#welcome h2').textContent equals "Welcome, Ana"
✓ expect document.querySelector('#welcome p').textContent matches /^We sent a link to ana@example\.com\.$/
✓ expect document.querySelector('#form').checkVisibility() equals false
✓ screenshot welcome → brokit-out/checks/signup/welcome.png (800×600) [baseline: new] 128 ms
2 scenarios passed in 1.7 sbrokit serves this folder, so "url": "/index.html" in a check opens index.html. The first run writes the baselines in checks/baselines/; the runs after it compare against them. In a real project you commit the baselines. They're not committed here, since they depend on the fonts of the machine that made them.

The baselines the checks wrote: a wrong email, the welcome card, and the phone check.
The page#
index.html is a form with a name, an email and a password. app.js checks the email when the form is sent: if it's wrong, it shows an error and puts the cursor back in the field; if it's right, it hides the form and says welcome.
The laptop check#
The check, checks/signup.check.json:
{
"note": "The sign-up form on a laptop: a wrong email first, then the right one.",
"url": "/index.html",
"viewport": { "size": "800x600" },
"ready": "document.readyState === 'complete'",
"steps": [
{ "click": { "selector": "#name" } },
{ "type": "Ana Pop" },
{ "click": { "selector": "#email" } },
{ "type": "ana@example" },
{ "key": "Enter", "note": "Enter in a field submits the form" },
{
"expect": "document.querySelector('#email-error').textContent",
"equals": "Enter a valid email, like ana@example.com"
},
{
"expect": "document.activeElement.id",
"equals": "email",
"note": "the page puts the cursor back in the field to fix"
},
{ "screenshot": "error", "selector": ".card", "baseline": true },
{ "click": { "selector": "#email" }, "count": 3, "note": "a triple click selects all the text in the field" },
{ "type": "ana@example.com", "note": "replaces the selection" },
{ "click": { "selector": "#password" } },
{ "type": "correct horse battery" },
{ "click": { "selector": "#submit" } },
{ "expect": "document.querySelector('#welcome h2').textContent", "equals": "Welcome, Ana" },
{ "expect": "document.querySelector('#welcome p').textContent", "matches": "^We sent a link to ana@example\\.com\\.$" },
{ "expect": "document.querySelector('#form').checkVisibility()", "equals": false, "note": "the form is gone, not just covered" },
{ "screenshot": "welcome", "baseline": true }
]
}{ "click": { "selector": "#email" } }clicks the middle of the field, as a mouse would.{ "type": "ana@example" }then types into whatever has focus.{ "key": "Enter" }presses Enter in the field, which sends the form. The page sees the same events as from a keyboard."equals"checks the error's exact text;"matches"checks the welcome line with a regular expression. An expectation is tried again for up to 2 seconds, so a page that updates a moment later still passes."count": 3is a triple click, which selects all the text in the field, so the nexttypereplaces it.- The
checkVisibility()expectation caught a real mistake while this example was written: the form'sdisplay: gridkept it on screen under the welcome message. "selector": ".card"takes a screenshot of just the card. Without it, a screenshot is the whole viewport.
The phone check#
The check, checks/signup-phone.check.json:
{
"note": "The same form on a phone: a touch screen, so taps instead of clicks.",
"url": "/index.html",
"viewport": { "size": "393x852", "dpr": 2, "mobile": true },
"ready": "document.readyState === 'complete'",
"steps": [
{ "expect": "document.documentElement.scrollWidth <= innerWidth", "note": "nothing wider than the phone" },
{ "tap": { "selector": "#name" } },
{ "type": "Ana Pop" },
{ "tap": { "selector": "#email" } },
{ "type": "ana@example.com" },
{ "tap": { "selector": "#password" } },
{ "type": "correct horse battery" },
{ "screenshot": "filled", "baseline": true },
{ "tap": { "selector": "#submit" } },
{ "expect": "document.querySelector('#welcome h2').textContent", "equals": "Welcome, Ana" },
{ "expect": "document.querySelector('#form').checkVisibility()", "equals": false },
{ "screenshot": "welcome", "baseline": true }
]
}"viewport": { "size": "393x852", "dpr": 2, "mobile": true }is a phone: a 393×852 CSS-pixel screen, 2 device pixels per CSS pixel (so the screenshots are 786×1704), a mobile viewport and touch.tapis a finger, not a mouse: the page gets touch events, then the click that follows a tap.- The first expectation checks that nothing is wider than the phone's screen, a common mistake on small screens.
Learn more#
- Steps: every step, points and expectations.
- Scenarios: scenario files,
viewportandready. - Checks and baselines:
brokit check, baselines and--update.