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

114 lines
3.4 KiB
Markdown
Raw Normal View History

---
id: running-tests
2023-03-06 20:52:58 +01:00
title: "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**
- [How to run tests from the command line](/running-tests.md#command-line)
- [How to debug tests](/running-tests.md#debugging-tests)
- [How to open the HTML test reporter](/running-tests.md#test-reports)
2023-04-25 20:09:52 +02:00
## Run tests in UI Mode
Run your tests with [UI Mode](./test-ui-mode.md) for a better developer experience with time travel debugging, watch mode and more.
```bash
npx playwright test --ui
```
## Command Line
- Running all tests
```bash
npx playwright test
```
- Running a single test file
```bash
npx playwright test landing-page.spec.ts
```
- Run a set of test files
```bash
npx playwright test tests/todo-page/ tests/landing-page/
```
- Run files that have `landing` or `login` in the file name
```bash
npx playwright test landing login
```
- Run the test with the title
```bash
npx playwright test -g "add a todo item"
```
- Running tests in headed mode
```bash
npx playwright test landing-page.spec.ts --headed
```
- Running tests on a specific project
```bash
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](./getting-started-vscode.md). Playwright comes with the [Playwright Inspector](./debug.md#playwright-inspector) which allows you to step through Playwright API calls, see their debug logs and explore [locators](./locators.md).
- Debugging all tests:
```bash
npx playwright test --debug
```
- Debugging one test file:
```bash
npx playwright test example.spec.ts --debug
```
- Debugging a test from the line number where the `test(..` is defined:
```bash
npx playwright test example.spec.ts:10 --debug
```
2023-02-28 20:58:24 +01:00
<img width="1340" alt="Debugging Tests with the Playwright inspector" src="https://user-images.githubusercontent.com/13063165/212936618-84b87acc-bc2e-46ed-994b-32b2ef742e60.png" />
Check out our [debugging guide](./debug.md) to learn more about the [Playwright Inspector](./debug.md#playwright-inspector) as well as debugging with [Browser Developer tools](./debug.md#browser-developer-tools).
## Test Reports
The [HTML Reporter](././test-reporters.md#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.
```bash
npx playwright show-report
```
2023-02-28 20:58:24 +01:00
<img width="1424" alt="HTML Report > Test Reports view" src="https://user-images.githubusercontent.com/13063165/221930419-49543647-9130-4429-a857-6851c2005e48.png" />
You can click on each test and explore the tests errors as well as each step of the test.
2023-02-28 20:58:24 +01:00
<img width="1440" alt="HTML Reporter > Test Reports detailed view" src="https://user-images.githubusercontent.com/13063165/221930640-c1ccda28-7906-44c7-a198-acd9acb40bbe.png" />
## What's Next
- [Generate tests with Codegen](./codegen-intro.md)
2022-08-10 14:34:27 +02:00
- [See a trace of your tests](./trace-viewer-intro.md)