Playwright can either be used as a part of the Playwright Test, or as a [Playwright Library](./library.md). If you intend to use Playwright for testing, read on.
Playwright Test was created specifically to accommodate the needs of the end-to-end testing. It does everything you would expect from the regular test runner, and more. Playwright test allows to:
- Run tests across all browsers.
- Execute tests in parallel.
- Enjoy context isolation out of the box.
- Capture videos, screenshots and other artifacts on failure.
You can optionally install only selected browsers, see [installing browsers](./test-install.md) for more details. Or you can install no browsers at all and use existing [browser channels](./browsers.md).
We call these arguments `fixtures`. Fixtures are objects that are created for each test run. Playwright Test comes loaded with those fixtures, and you can add your own fixtures as well. When running tests, Playwright Test looks at each test declaration, analyses the set of fixtures the test needs and prepares those fixtures specifically for the test.
|context |[BrowserContext] |Isolated context for this test run. The `page` fixture belongs to this context as well. Learn how to [configure context](./test-configuration.md). |
|browser |[Browser] |Browsers are shared across tests to optimize resources. Learn how to [configure browser](./test-configuration.md). |
|browserName|[string] |The name of the browser currently running the test. Either `chromium`, `firefox` or `webkit`.|
## Test and assertion features
If you are familiar with test runners like Jest, Mocha and Ava, you will find the Playwright Test syntax familiar. These are the basic things you can do with the test:
### Focus a test
You can focus some tests. When there are focused tests, only they run.
```js js-flavor=js
test.only('focus this test', async ({ page }) => {
// Run only focused tests in the entire project.
});
```
```js js-flavor=ts
test.only('focus this test', async ({ page }) => {
Playwright Test uses [expect](https://jestjs.io/docs/expect) library for test assertions. It provides a lot of matchers like `toEqual`, `toContain`, `toMatch`, `toMatchSnapshot` and many more.
Combine `expect` with various Playwright methods to create expectations for your test:
- [`method: Page.isVisible`]
- [`method: Page.waitForSelector`]
- [`method: Page.textContent`]
- [`method: Page.getAttribute`]
- [`method: Page.screenshot`]
- Find out more in the [assertions](./assertions.md) guide
Error: example.spec.ts-snapshots/get-started-chromium-darwin.png is missing in snapshots, writing actual.
```
That's because there was no golden file for your `get-started.png` snapshot. It is now created and is ready to be added to the repository. The name of the folder with the golden expectations starts with the name of your test file:
```bash
drwxr-xr-x 5 user group 160 Jun 4 11:46 .
drwxr-xr-x 6 user group 192 Jun 4 11:45 ..
-rw-r--r-- 1 user group 231 Jun 4 11:16 example.spec.ts
drwxr-xr-x 3 user group 96 Jun 4 11:46 example.spec.ts-snapshots
```
To update your golden files, you can use the `--update-snapshots` parameter.
```bash
npx playwright test --update-snapshots
```
## Learn the command line
Here are the most common options available in the [command line](./test-cli.md).
- Run tests in headed browsers
```bash
npx playwright test --headed
```
- Run tests in a particular browser
```bash
npx playwright test --browser=webkit
```
- Run tests in all browsers
```bash
npx playwright test --browser=all
```
- Run a single test file
```bash
npx playwright test tests/todo-page.spec.ts
```
- Run a set of test files
```bash
npx playwright test tests/todo-page/ tests/landing-page/
```
- Run a test with specific title
```bash
npx playwright test -g "add a todo item"
```
- Run tests [in parallel](./test-parallel.md) - that's the default
```bash
npx playwright test
```
- Disable [parallelization](./test-parallel.md)
```bash
npx playwright test --workers=1
```
- Choose a [reporter](./test-reporters.md)
```bash
npx playwright test --reporter=dot
```
- Run in debug mode with [Playwright Inspector](./inspector.md)
```bash
# Linux/macOS
PWDEBUG=1 npx playwright test
# Windows with cmd.exe
set PWDEBUG=1
npx playwright test
# Windows with PowerShell
$env:PWDEBUG=1
npx playwright test
```
## Create a configuration file
So far, we've looked at the zero-config operation of Playwright Test. For a real world application, it is likely that you would want to use a config.
Create `playwright.config.ts` (or `playwright.config.js`) to configure your tests. You can specify browser launch options, run tests in multiple browsers and much more with the config. Here is an example configuration that runs every test in Chromium, Firefox and WebKit, both Desktop and Mobile versions. Look for more options in the [configuration section](./test-configuration.md).