Verify UI changes in a real browser
Exercise browser flows, keyboard access, mobile layout, loading and error states and capture evidence tied to each acceptance criterion.
By Invicly Tech, , in Prompt Engineering and Vibe Coding. About 9 minutes to read.
In short
For UI changes, running the page in a real browser is the honest check. Use Playwright to drive the flow, check keyboard access, try phone-sized screens, force loading and error states, and save screenshots. Each piece of evidence should point back to one acceptance criterion.
Think of it like this: It is like test-driving a car on a real road instead of reading the spec sheet: you only learn how it behaves by using it.
Explained simply
A page can pass every unit test and still be broken on a phone. Only a real browser shows what users see. Playwright is a free tool that controls real browsers from test code, so you can click, type and look at the result.
Drive the actual flow: open the page, fill the form, press the button and check the visible result. Find elements the way a person would, by their role and label, such as the button named Submit. This also tells you if labels are missing.
Then check what tests often skip. Can you do everything with only the keyboard? Is the focus ring visible? Does the layout work at 390 pixels wide, and in landscape? What does the page show while data loads, and when the request fails?
Save screenshots as evidence and name each after the acceptance criterion it proves. In review, nobody has to take your word that it works.
Press Play on a diagram to walk through it one step at a time.
- 1Start app
Run the dev server or a production build locally
- 2Drive the flow
Playwright clicks, types and asserts visible results
- 3Keyboard
Tab through, check focus order and Enter or Space actions
- 4Viewports
Repeat at phone and desktop sizes
- 5Edge states
Slow response and failed request
- 6Evidence
Save screenshots named after each criterion
- AC1 Works
- ac1-desktop.png
- ac1-mobile.png
- AC2 Keyboard
- ac2-focus.png
- AC3 Error state
- ac3-error-mobile.png
- AC4 Loading
- ac4-loading.png
In depth
Driving the flow with Playwright
Prerequisites: Node and a Next.js app that runs locally. Install Playwright with the init command, which also offers to download browsers. Browser downloads are large, so allow a few minutes. Start the app and write a test that follows the user flow.
Use getByRole and getByLabel locators. Playwright waits for elements automatically, so you rarely need fixed sleeps. Playwright can start your dev server for you through the webServer option in its config.
- npm init playwright@latest to set up
- getByRole and getByLabel for locators
- expect(...).toBeVisible() waits and retries
- webServer option starts the app
Keyboard access and focus
Many people do not use a mouse. Everything interactive must work with Tab, Shift+Tab, Enter and Space. Focus must be visible and move in a sensible order. Dialogs should hold focus while open and return it when closed.
In a test, press Tab and assert which element has focus. For broader checks, Playwright documents using the axe-core engine through @axe-core/playwright. It finds many accessibility problems automatically, but not all, so keep the manual keyboard pass as well.
- 1Tab to Email
Focus ring visible
- 2Type value
Label read by screen readers
- 3Tab to Submit
Order matches visual order
- 4Press Enter
Form submits without a mouse
- 5Result message
Announced or visible, focus not lost
Mobile viewports and emulation
Most visits to many sites come from phones. Playwright can set a viewport size or use a built-in device profile such as iPhone 13, which also sets touch and a user agent. Test at least 390 by 844 and a landscape size like 844 by 390, plus a desktop size.
Look for horizontal scroll, text that is cut off, tap targets smaller than about 44 pixels, and menus that do not scroll when tall. A screenshot shows these problems far faster than reading CSS.
- 390 by 844
- No horizontal scroll
- Tap targets large enough
- Menu scrolls if tall
- 844 by 390
- Header does not fill the screen
- Dialogs reachable
- Content not clipped
- 1280 wide or more
- Line length readable
- Focus ring visible
- Hover not required
Loading, error states and evidence
Real users have slow and failing connections. Playwright can intercept a request with page.route, then delay it or return an error. You can then assert that a loading message appears and that a clear error shows, with a way to retry.
Save a screenshot for each criterion, for example evidence/ac3-error-mobile.png. Playwright also supports visual comparison with toHaveScreenshot, which stores a baseline image and fails when pixels change. Keep evidence files out of the main source unless your team wants them committed.
- page.route to delay or fail a request
- Assert the loading text and the error text
- Name screenshots after criteria
- toHaveScreenshot for visual baselines
Learn it in 5 short steps
About 35m each. Track them with a timer in your plan.
- 1Drive the flow with Playwright~35m
- 2Check keyboard access and focus~35m
- 3Test mobile viewports~35m
- 4Cover loading and error states~35m
- 5Save screenshots as evidence~35m
Key points
- Locate elements by role and label, as a user would, not by fragile CSS classes.
- Check that every control works with the keyboard and that focus is visible.
- Test a narrow viewport such as 390 by 844 and a landscape phone, not just desktop.
- Cover loading and error states by delaying or failing network requests in the test.
- Save screenshots and name them after the acceptance criterion they show.
Key terms
Tap a card to flip it. 0/5 known
Examples
import { test, expect } from "@playwright/test";
test.use({ viewport: { width: 390, height: 844 } });
test("subscribe form works by keyboard", async ({ page }) => {
await page.goto("http://localhost:3000/");
await page.getByLabel("Email").fill("ada@example.com");
await page.keyboard.press("Tab");
await page.keyboard.press("Enter");
await expect(page.getByText("Thanks")).toBeVisible();
await page.screenshot({ path: "evidence/ac1-subscribe-mobile.png" });
});A Playwright test with keyboard use and a phone viewport.
A full check of an error state
Criterion: when saving fails, the form shows a clear message and keeps the typed text. Step 1: open the page. Step 2: use page.route to make the save request return a 500. Step 3: fill and submit. Step 4: assert the error message is visible and the field still holds its value. Step 5: save a screenshot named after the criterion. Cleanup: the route override ends with the test.
import { test, expect } from "@playwright/test";
test("AC3 shows error and keeps text", async ({ page }) => {
await page.route("**/api/subscribe", (r) => r.fulfill({ status: 500 }));
await page.goto("http://localhost:3000/");
await page.getByLabel("Email").fill("ada@example.com");
await page.getByRole("button", { name: "Subscribe" }).click();
await expect(page.getByRole("alert")).toBeVisible();
await expect(page.getByLabel("Email")).toHaveValue("ada@example.com");
await page.screenshot({ path: "evidence/ac3-error.png" });
});Testing a phone layout
Criterion: at 390 pixels wide the page has no horizontal scroll. Step 1: set the viewport. Step 2: open the page. Step 3: compare the document width with the window width in the browser. Step 4: assert they are equal. Step 5: take a screenshot as evidence. If it fails, the screenshot shows which element overflows, which is the starting point for the fix.
import { test, expect } from "@playwright/test";
test.use({ viewport: { width: 390, height: 844 } });
test("AC5 no horizontal scroll on phone", async ({ page }) => {
await page.goto("http://localhost:3000/");
const overflow = await page.evaluate(
() => document.documentElement.scrollWidth > window.innerWidth
);
expect(overflow).toBe(false);
await page.screenshot({ path: "evidence/ac5-mobile.png", fullPage: true });
});Quick reference
- npm init playwright@latest sets up Playwright and the config file.
- Prefer getByRole and getByLabel over CSS selectors.
- Check Tab order, visible focus and Enter or Space on every control.
- Test 390 by 844, landscape 844 by 390, and a desktop width.
- Use page.route to delay or fail a request and check the message.
- Name screenshots after the acceptance criterion they prove.
- Automated accessibility checks find some issues, not all. Keep a manual pass.
Common mistakes
- Trusting that the assistant's description of the page matches what renders.
- Testing only at desktop width and finding horizontal scroll on phones later.
- Screenshots with no label, so nobody knows which criterion they prove.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
List the keyboard checks for a login form with email, password and Sign in button.
- Exercise 2medium
Write a Playwright test that checks a loading message appears while a slow request is pending.
- Exercise 3hard
Design an evidence pack for a feature with four acceptance criteria, and say how a reviewer uses it.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Do I need paid tools for browser testing?
- No. Playwright is free and open source. Browsers it downloads are free too, though the download is large.
- Can the assistant just tell me the UI works?
- It cannot see your running page unless you give it screenshots or test output. Check in a real browser and keep the evidence.
- Should every UI change get a Playwright test?
- Not every one. Cover the flows that must not break and the criteria of the current change, then take screenshots for the rest.
- Is Playwright needed if I use Vitest?
- They solve different problems. Vitest checks logic and components quickly. Playwright checks the page in a real browser.