Skip to main content

UI mode and watch mode

Why This Matters

While you write or fix a test, the loop is: change, run, look, repeat. In the terminal every round trip costs you a run and a scroll through output. UI mode turns that loop into seconds: you see every step, the page before and after it, and the test reruns when you save.

Open UI mode

npm run test:ui

This is npx playwright test --ui. A window opens with all tests on the left, grouped by file and project. Click the triangle next to a test to run it.

What you see

After a run, click any step in the list:

  • Actions: every goto, click, fill and assertion, with its duration.
  • Before / After: a snapshot of the page right before and after that step. You can scroll and inspect it like a real page.
  • Locator: the element the step used is highlighted in the snapshot.
  • Console, Network, Errors: what the page logged, which requests it made, what went wrong.

For the slow-backend test from the debugging exercise, the Network tab shows the request to /api/shop/products taking six seconds: the cause is visible without reading a line of code.

Watch mode

Click the eye icon next to a test or a file. From then on UI mode reruns it every time you save a file it uses. Write a step, save, see it run.

Pick a locator

The Pick locator button works on the snapshots: click an element and UI mode shows the locator for it, which you can copy into your test. This is the same picker as in codegen, but on the exact state your test reached.

Exercise

  1. Switch to the exercise branch: git checkout exercise/debugging.
  2. Open UI mode and run tests/module-3/debugging.spec.ts.
  3. For search updates the results count, step to the textContent call and look at the snapshot. What does the results count show at that moment?
  4. Switch back with git checkout main when you are done.
Show suggested answer

The snapshot shows the list as it was when textContent() ran: the search text is in the box, but the shop has not filtered yet, so the count still says 10. That matches the real failure:

Expected: "1"
Received: "10"

UI mode lets you see the timing problem instead of guessing at it. Lesson 15 fixes it.