new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · all subjects

configuration

165 notes in this subject, read out of this brain and free to use. This is page 2 of 3.

Configure retries in playwright.config.ts

Configure retries in the configuration file using the retries option. Example: export default defineConfig({ retries: 3 });

Test categorization with retries enabled

Playwright Test categorizes tests as follows: 'passed' — tests that passed on the first run; 'flaky' — tests that failed on the first run but passed when retried; 'failed' — tests that failed on the first run and failed all retries.

Configure retries for specific test group with Test.describe.configure

You can specify retries for a specific group of tests or a single file using test.describe.configure({ retries: 2 }). All tests in that describe group will get the specified number of retry attempts.

Default behavior: failing tests are not retried

By default, failing tests are not retried. Retries must be explicitly enabled via command line or configuration file.

snapshotPathTemplate configuration option

The snapshot name and path can be configured with the TestConfig.snapshotPathTemplate property in the playwright config.

Browser versions tested in 1.8

Playwright 1.8 was tested with: Chromium 90.0.4392.0, Mozilla Firefox 85.0b5, WebKit 14.1.

TestProject.ignoreSnapshots per-project configuration

The TestProject.ignoreSnapshots property allows configuring per project whether to skip screenshot expectations such as expect(page).toHaveScreenshot().

BrowserType.launchPersistentContext firefoxUserPrefs option

The BrowserType.launchPersistentContext method now accepts a firefoxUserPrefs option to set Firefox user preferences for the persistent context.

workers option accepts percentage

The workers option in playwright.config.ts now accepts a percentage string like '20%' to use that percentage of available CPUs, or can be passed via --workers command line option.

FullConfig.configFile property

The FullConfig.configFile property is available to test reporters, specifying the path to the config file if any.

snapshotPathTemplate controls snapshot location

The TestProject.snapshotPathTemplate and TestConfig.snapshotPathTemplate properties control the location of snapshots generated by PageAssertions.toHaveScreenshot and SnapshotAssertions.toMatchSnapshot.

Screenshot fullPage mode captures entire page

The screenshot option with mode: 'only-on-failure' and fullPage: true automatically captures full page screenshots on test failure.

TestConfig.fullyParallel enables full parallelization

The TestConfig.fullyParallel mode enables parallel execution of tests within a single file, in addition to parallel execution between files.

TestProject.grep and grepInvert per-project filtering

The TestProject.grep and TestProject.grepInvert properties allow configuring test filtering per project, useful for running smoke tests or specific test types.

TestProject.teardown cleanup after dependent projects

The TestProject.teardown property specifies a project that runs after this project and all dependent projects finish, useful for resource cleanup.

TestConfig.webServer stdout stderr configuration

The TestConfig.webServer now accepts stdout and stderr options to configure output handling for the web server process.

tsconfig.json baseUrl and paths support

Playwright Test now respects tsconfig.json baseUrl and paths configuration, enabling TypeScript path aliases in tests.

TestConfig.webServer url option

The TestConfig.webServer accepts a url option to specify the server endpoint that Playwright waits for before running tests.

serviceWorkers block option disables service workers

The serviceWorkers: 'block' context option in playwright.config.ts disables service workers that might interfere with testing.

WebServer ready status codes include 200-399 and 400-403

The WebServer is now considered ready if the request returns HTTP status codes 200-299, 300-399, 400, 401, 402, or 403.

HTML report is single static file

As of Playwright 1.17, the HTML report is a single static HTML file that can be sent by email or as a Slack attachment. The report supports dynamic filtering.

Install Edge on Linux

Playwright 1.17 allows installing stable version of Edge on Linux using the command: npx playwright install msedge

webServer option launches server before tests

The `webServer` option in the configuration file launches a server during tests. The server waits for a given URL to be available before running tests, and the URL is passed as `baseURL` when creating a context.

webServer configuration example

Example webServer configuration: { command: 'npm run start', url: 'http://127.0.0.1:3000', timeout: 120 * 1000, reuseExistingServer: !process.env.CI }

Reporter API introduced in 1.13

Reporter API was introduced in Playwright 1.13, allowing creation of custom reporters like the Allure Playwright reporter.

baseURL fixture for relative paths

The `baseURL` fixture (introduced in 1.13) supports using relative paths in tests.

Apple Silicon support for browser binaries

Playwright 1.7 now includes browser binaries for Apple Silicon in WebKit and Chromium.

Video.delete and Video.saveAs manage recordings

The `Video.delete()` and `Video.saveAs()` methods (introduced in 1.11) allow managing screen recordings.

BrowserType.launch channel option

The `BrowserType.launch()` method now accepts a new `'channel'` option (introduced in 1.10) to run Playwright against Google Chrome and Microsoft Edge stable channels.

HTML reporter configuration options

The HTML reporter received new configuration options in Playwright 1.17.

testConfig.snapshotDir option

The `testConfig.snapshotDir` option was introduced in Playwright 1.17 to configure the snapshot directory.

reporter.printsToStdio method

The `reporter.printsToStdio()` method (introduced in 1.17) was added to the reporter interface.

Browser versions tested in 1.10

Playwright 1.10 was tested with: Chromium 90.0.4430.0, Mozilla Firefox 87.0b10, WebKit 14.2, Google Chrome 89, and Microsoft Edge 89.

Browser versions tested in 1.7

Playwright 1.7 was tested with: Chromium 89.0.4344.0, Mozilla Firefox 84.0b9, WebKit 14.1.

Test timeout default and configuration

The default test timeout in Playwright Test is 30,000 milliseconds (30 seconds). This timeout applies to the test function, fixture setups, and beforeEach hooks combined. It can be set globally in the config with the timeout property or overridden per test using test.setTimeout().

Test timeout configuration in config file

To set test timeout globally in playwright.config.ts: use { timeout: 60_000 } in the defineConfig export.

Set test timeout per test with test.setTimeout

Call test.setTimeout(120_000) inside a test function to override the timeout for that specific test.

Use test.slow() to triple test timeout

Calling test.slow() inside a test function automatically triples the default timeout, making it 90 seconds instead of the default 30 seconds.

Global timeout for entire test run

Playwright Test supports a global timeout that applies to the entire test run. There is no default global timeout. When exceeded, the test runner produces an error stating the global timeout was exceeded (e.g., 'Timed out waiting 3600s for the entire test run'). Set it in the config with { globalTimeout: 3_600_000 }.

Action timeout configuration

Action timeout has no default value. It can be set globally in the config using { use: { actionTimeout: 10_000 } } or overridden per action using { timeout: 10_000 } option in the action call (e.g., locator.click({ timeout: 10_000 })).

Navigation timeout configuration

Navigation timeout has no default value. It can be set globally in the config using { use: { navigationTimeout: 30_000 } } or overridden per navigation action using { timeout: 30_000 } option (e.g., page.goto('/', { timeout: 30_000 })).

Set action and navigation timeouts in config

To set action and navigation timeouts in playwright.config.ts: use { use: { actionTimeout: 10 * 1000, navigationTimeout: 30 * 1000 } } in the defineConfig export.

Supported tsconfig.json options in Playwright

Playwright only supports the following tsconfig options: allowJs, baseUrl, paths, references, and extends. Other tsconfig options are not supported.

Example manual TypeScript compilation setup

To manually compile TypeScript tests, create tests/tsconfig.json with target ESNext, module commonjs, moduleResolution Node, sourceMap true, and outDir ../tests-out. In package.json, add: `"pretest": "tsc --incremental -p tests/tsconfig.json"` and `"test": "playwright test -c tests-out"`. Then run `npm run test` to build and run tests.

Manual TypeScript compilation before running tests

For experimental or recent TypeScript features that Playwright cannot transform correctly, compile TypeScript manually before sending tests to Playwright. Create a tsconfig.json in the tests directory with appropriate compiler options, add a pretest script using `tsc --incremental -p tests/tsconfig.json`, and configure Playwright to look in the output directory using `playwright test -c tests-out`.

Specify tsconfig in playwright.config.ts

Set the tsconfig option in playwright.config.ts using `defineConfig({ tsconfig: './tsconfig.test.json' })` to specify a single tsconfig file for loading test files and reporters. This tsconfig will not be used while loading the playwright config itself or files imported from it.

Specify a single tsconfig file via command line

Use `npx playwright test --tsconfig=tsconfig.test.json` to specify a single tsconfig file that Playwright will use for all imported files, not only test files.

Automatic tsconfig.json resolution

Playwright automatically looks up the closest tsconfig.json or jsconfig.json for each imported file by traversing up the directory structure. No configuration is required; run `npx playwright test` to use automatic resolution.

tsconfig path mapping support

Playwright supports path mapping declared in tsconfig.json under compilerOptions.paths. Path mappings are relative to the tsconfig.json file location and allow importing modules using mapped paths like `@myhelper/credentials`.

Separate tsconfig.json for tests directory

Create a test-specific tsconfig.json in the tests directory to set preferences specifically for tests, separate from the generic tsconfig.json in the project root.

Playwright supports TypeScript out of the box

Playwright reads TypeScript test files, transforms them to JavaScript, and runs them automatically. TypeScript compilation errors that are non-critical will not prevent tests from running.

TypeScript watch mode for local development

For local development, run `npx tsc -p tsconfig.json --noEmit -w` to continuously check types while developing tests.

Increasing webServer timeout for slow startup

The timeout property in webServer configuration controls how long to wait for the process to start up and be available, specified in milliseconds. Default is 60000ms. For slower startup times, increase this value, such as 120 * 1000 for 120 seconds.

webServer configuration options reference

The webServer configuration object accepts the following properties: | Property | Type | Description | Default | | :- | :- | :- | :- | | command | string | Shell command to start the local dev server of your app. | (required) | | cwd | string | Current working directory of the spawned process. | Directory of the configuration file | | env | object | Environment variables for the command. | Inherits process.env with PLAYWRIGHT_TEST=1 added | | gracefulShutdown | object | How to shut down the process. Format: `{ signal: 'SIGTERM'\|'SIGINT', timeout: number }`. Process group is forcefully SIGKILL'd if unspecified. Timeout of 0 means no SIGKILL will be sent. Windows ignores SIGTERM and SIGINT. | Defaults to forceful SIGKILL | | ignoreHTTPSErrors | boolean | Whether to ignore HTTPS errors when fetching the url. | false | | name | string | Custom name for the web server, prefixed to log messages. | [WebServer] | | port | string or number | **Deprecated.** Use url instead. The port the http server is expected to appear on. Either port or url should be specified. | N/A | | reuseExistingServer | boolean | If true, re-use an existing server on the port or url when available. If no server is running, start a new one. If false, throw if a process is listening on the port or url. Commonly set to !process.env.CI for local dev server reuse. | N/A | | stderr | string | Whether to pipe the stderr of the command to process stderr or ignore it. | pipe | | stdout | string | 'pipe' to pipe stdout to process stdout, 'ignore' to ignore it. | ignore | | timeout | number | How long to wait for the process to start up and be available in milliseconds. | 60000 | | url | string | URL of http server expected to return 2xx, 3xx, 400, 401, 402, or 403 status code when ready. Either port or url should be specified. If both url and wait are specified, server is considered started when at least one condition is met. | N/A | | wait | object | Consider command started when given output is produced. Takes object with optional stdout and/or stderr regular expressions. Named capture groups in regex are stored in environment variables prefixed with uppercase. If both url and wait are specified, server is considered started when at least one condition is met. | N/A |

baseURL in configuration enables relative URLs in tests

Setting baseURL in the use section of the config allows tests to use relative URLs instead of full URLs. When using page.goto(), page.route(), page.waitForURL(), page.waitForRequest(), or page.waitForResponse(), Playwright uses the URL() constructor to combine the baseURL with the relative path. For example, with baseURL set to 'http://localhost:3000' and navigating to './login', Playwright navigates to 'http://localhost:3000/login'.

Multiple webServers can run simultaneously

Multiple web servers or background processes can be launched simultaneously by providing an array of webServer configurations in the Playwright config file.

webServer configuration with baseURL example

Example of configuring webServer with baseURL: ```js import { defineConfig } from '@playwright/test'; export default defineConfig({ webServer: { command: 'npm run start', url: 'http://localhost:3000', reuseExistingServer: !process.env.CI, stdout: 'ignore', stderr: 'pipe', }, use: { baseURL: 'http://localhost:3000', }, }); ``` This launches the dev server, allows server reuse when testing locally (not in CI), ignores stdout, and pipes stderr.

Multiple webServers configuration example

Example of configuring multiple web servers: ```js import { defineConfig } from '@playwright/test'; export default defineConfig({ webServer: [ { command: 'npm run start', url: 'http://localhost:3000', name: 'Frontend', timeout: 120 * 1000, reuseExistingServer: !process.env.CI, }, { command: 'npm run backend', url: 'http://localhost:3333', name: 'Backend', timeout: 120 * 1000, reuseExistingServer: !process.env.CI, } ], use: { baseURL: 'http://localhost:3000', }, }); ``` This launches both a frontend server on port 3000 and a backend server on port 3333.

webServer configuration launches dev server before tests

The webServer property in the Playwright config launches a local development web server before running tests. This is ideal during development when you don't have a staging or production URL to test against.

Reset a configuration option to config value

To reset an option to its config-defined value, call test.use({ option: undefined }). This works inside describe blocks to reset for a subset of tests.

Give your agent this brain