Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS MATH

Playwright UI Mode


Share

Playwright UI Mode

UI mode is a window where you run tests, watch each step, and run them again with one click.

This chapter also shows how to rerun only the tests that failed.

The examples use the project from the Running Tests chapter, with tests/todo.spec.js and tests/login.spec.js.


Open UI Mode

Open UI mode with the --ui option:

Example

npx playwright test --ui

On the left are your test files and tests.

Click the play button next to a test to run it, or the play button at the top to run all of them.

Click a test to see every step it took, with a picture of the page before and after each step:

Playwright UI mode with four passed tests and the steps of the test can add a todo

Click the eye icon next to a test to watch it: UI mode runs the test again every time you save the file.

UI mode is a good way to work while you write new tests.



Run Only the Failed Tests

In tests/login.spec.js, change the expected text in the test "shows an error for a wrong password" to 'Wrong password.', and run all tests:

Example

npx playwright test

Output:

Running 4 tests using 4 workers

[1/4] [chromium] › tests/todo.spec.js:9:1 › can add a todo
[2/4] [chromium] › tests/login.spec.js:12:1 › shows an error for a wrong password
[3/4] [chromium] › tests/todo.spec.js:4:1 › has title
[4/4] [chromium] › tests/login.spec.js:4:1 › can log in
  1) [chromium] › tests/login.spec.js:12:1 › shows an error for a wrong password ───────────────────

    Error: expect(locator).toHaveText(expected) failed

    Locator:  getByRole('alert')
    Expected: "Wrong password."
    Received: "Wrong username or password."
    Timeout:  5000ms

  1 failed
    [chromium] › tests/login.spec.js:12:1 › shows an error for a wrong password ────────────────────
  3 passed (7.2s)

Playwright remembers which tests failed.

Run only those tests again with --last-failed:

Example

npx playwright test --last-failed

Output:

Running 1 test using 1 worker

[1/1] [chromium] › tests/login.spec.js:12:1 › shows an error for a wrong password
  1) [chromium] › tests/login.spec.js:12:1 › shows an error for a wrong password ───────────────────

    Error: expect(locator).toHaveText(expected) failed

    Locator:  getByRole('alert')
    Expected: "Wrong password."
    Received: "Wrong username or password."
    Timeout:  5000ms

  1 failed
    [chromium] › tests/login.spec.js:12:1 › shows an error for a wrong password ────────────────────

This is faster than running all tests while you fix a failure.

Playwright saves the list of failed tests in test-results/.last-run.json.



Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.