playwright/docs/src/running-tests-js.md

3.4 KiB

id title
running-tests Running tests

You can run a single test, a set of tests or all tests. Tests can be run on one browser or multiple browsers. By default tests are run in a headless manner meaning no browser window will be opened while running the tests and results will be seen in the terminal.

You will learn

Run tests in UI Mode

Run your tests with UI Mode for a better developer experience with time travel debugging, watch mode and more.

npx playwright test --ui

Command Line

  • Running all tests

    npx playwright test
    
  • Running a single test file

    npx playwright test landing-page.spec.ts
    
  • Run a set of test files

    npx playwright test tests/todo-page/ tests/landing-page/
    
  • Run files that have landing or login in the file name

    npx playwright test landing login
    
  • Run the test with the title

    npx playwright test -g "add a todo item"
    
  • Running tests in headed mode

    npx playwright test landing-page.spec.ts --headed
    
  • Running tests on a specific project

    npx playwright test landing-page.ts --project=chromium
    

Debugging Tests

Since Playwright runs in Node.js, you can debug it with your debugger of choice e.g. using console.log or inside your IDE or directly in VS Code with the VS Code Extension. Playwright comes with the Playwright Inspector which allows you to step through Playwright API calls, see their debug logs and explore locators.

  • Debugging all tests:

    npx playwright test --debug
    
  • Debugging one test file:

    npx playwright test example.spec.ts --debug
    
  • Debugging a test from the line number where the test(.. is defined:

    npx playwright test example.spec.ts:10 --debug
    
Debugging Tests with the Playwright inspector

Check out our debugging guide to learn more about the Playwright Inspector as well as debugging with Browser Developer tools.

Test Reports

The HTML Reporter shows you a full report of your tests allowing you to filter the report by browsers, passed tests, failed tests, skipped tests and flaky tests. By default, the HTML report is opened automatically if some of the tests failed.

npx playwright show-report
HTML Report > Test Reports view

You can click on each test and explore the tests errors as well as each step of the test.

HTML Reporter > Test Reports detailed view

What's Next