TestConfig
Source URL: https://playwright.dev/docs/api/class-testconfig
TestConfig | Playwright
섹션 제목: “TestConfig | Playwright”Playwright Test provides many options to configure how your tests are collected and executed, for example timeout or testDir. These options are described in the TestConfig object in the configuration file. This type describes format of the configuration file, to access resolved configuration parameters at run time use FullConfig.
Playwright Test supports running multiple test projects at the same time. Project-specific options should be put to testConfig.projects, but top-level TestConfig can also define base options shared between all projects.
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ timeout: 30000, globalTimeout: 600000, reporter: 'list', testDir: './tests', });Properties
섹션 제목: “Properties”build
섹션 제목: “build”Added in: v1.35 testConfig.build
Playwright transpiler configuration.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ build: { external: ['**/*bundle.js'], }, });Type
Paths to exclude from the transpilation expressed as a list of glob patterns. Typically heavy JS bundles that your test uses are listed here.
captureGitInfo
섹션 제목: “captureGitInfo”Added in: v1.51 testConfig.captureGitInfo
These settings control whether git information is captured and stored in the config testConfig.metadata.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ captureGitInfo: { commit: true, diff: true } });Type
Whether to capture commit and pull request information such as hash, author, timestamp.
* `diff` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_Whether to capture commit diff.
Details
- Capturing
commitinformation is useful when you’d like to see it in your HTML (or a third party) report. - Capturing
diffinformation is useful to enrich the report with the actual source diff. This information can be used to provide intelligent advice on how to fix the test.
note
Default values for these settings depend on the environment. When tests run as a part of CI where it is safe to obtain git information, the default value is true, false otherwise.
note
The structure of the git commit metadata is subject to change.
expect
섹션 제목: “expect”Added in: v1.10 testConfig.expect
Configuration for the expect assertion library. Learn more about various timeouts.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ expect: { timeout: 10000, toMatchSnapshot: { maxDiffPixels: 10, }, }, });Type
Default timeout for async expect matchers in milliseconds, defaults to 5000ms.
* `toHaveScreenshot` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `animations` "allow" | "disabled" _(optional)_See animations in page.screenshot(). Defaults to "disabled".
* `caret` "hide" | "initial" _(optional)_See caret in page.screenshot(). Defaults to "hide".
* `maxDiffPixels` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_An acceptable amount of pixels that could be different, unset by default.
* `maxDiffPixelRatio` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_An acceptable ratio of pixels that are different to the total amount of pixels, between 0 and 1 , unset by default.
* `scale` "css" | "device" _(optional)_See scale in page.screenshot(). Defaults to "css".
* `stylePath` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")> _(optional)_See style in page.screenshot().
* `threshold` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_An acceptable perceived color difference between the same pixel in compared images, ranging from 0 (strict) and 1 (lax). "pixelmatch" comparator computes color difference in YIQ color space and defaults threshold value to 0.2.
* `pathTemplate` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_A template controlling location of the screenshots. See testConfig.snapshotPathTemplate for details.
Configuration for the expect(page).toHaveScreenshot() method.
* `toMatchAriaSnapshot` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `pathTemplate` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_A template controlling location of the aria snapshots. See testConfig.snapshotPathTemplate for details.
Configuration for the expect(locator).toMatchAriaSnapshot() method.
* `toMatchSnapshot` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `maxDiffPixels` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_An acceptable amount of pixels that could be different, unset by default.
* `maxDiffPixelRatio` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_An acceptable ratio of pixels that are different to the total amount of pixels, between 0 and 1 , unset by default.
* `threshold` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_An acceptable perceived color difference between the same pixel in compared images, ranging from 0 (strict) and 1 (lax). "pixelmatch" comparator computes color difference in YIQ color space and defaults threshold value to 0.2.
Configuration for the expect(value).toMatchSnapshot() method.
* `toPass` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `intervals` [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> _(optional)_Probe intervals for toPass method in milliseconds.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_Timeout for toPass method in milliseconds.
Configuration for the expect(value).toPass() method.
failOnFlakyTests
섹션 제목: “failOnFlakyTests”Added in: v1.52 testConfig.failOnFlakyTests
Whether to exit with an error if any tests are marked as flaky. Useful on CI.
Also available in the command line with the --fail-on-flaky-tests option.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ failOnFlakyTests: !!process.env.CI, });Type
forbidOnly
섹션 제목: “forbidOnly”Added in: v1.10 testConfig.forbidOnly
Whether to exit with an error if any tests or groups are marked as test.only() or test.describe.only(). Useful on CI.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ forbidOnly: !!process.env.CI, });Type
fullyParallel
섹션 제목: “fullyParallel”Added in: v1.20 testConfig.fullyParallel
Playwright Test runs tests in parallel. In order to achieve that, it runs several worker processes that run at the same time. By default, test files are run in parallel. Tests in a single file are run in order, in the same worker process.
You can configure entire test run to concurrently execute all tests in all files using this option.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ fullyParallel: true, });Type
globalSetup
섹션 제목: “globalSetup”Added in: v1.10 testConfig.globalSetup
Path to the global setup file. This file will be required and run before all the tests. It must export a single function that takes a FullConfig argument. Pass an array of paths to specify multiple global setup files.
Learn more about global setup and teardown.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ globalSetup: './global-setup', });Type
globalTeardown
섹션 제목: “globalTeardown”Added in: v1.10 testConfig.globalTeardown
Path to the global teardown file. This file will be required and run after all the tests. It must export a single function. See also testConfig.globalSetup. Pass an array of paths to specify multiple global teardown files.
Learn more about global setup and teardown.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ globalTeardown: './global-teardown', });Type
globalTimeout
섹션 제목: “globalTimeout”Added in: v1.10 testConfig.globalTimeout
Maximum time in milliseconds the whole test suite can run. Zero timeout (default) disables this behavior. Useful on CI to prevent broken setup from running too long and wasting resources. Learn more about various timeouts.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ globalTimeout: process.env.CI ? 60 * 60 * 1000 : undefined, });Type
grep
섹션 제목: “grep”Added in: v1.10 testConfig.grep
Filter to only run tests with a title matching one of the patterns. For example, passing grep: /cart/ should only run tests with “cart” in the title. Also available in the command line with the -g option. The regular expression will be tested against the string that consists of the project name, the test file name, the test.describe name (if any), the test name and the test tags divided by spaces, e.g. chromium my-test.spec.ts my-suite my-test.
grep option is also useful for tagging tests.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ grep: /smoke/, });Type
grepInvert
섹션 제목: “grepInvert”Added in: v1.10 testConfig.grepInvert
Filter to only run tests with a title not matching one of the patterns. This is the opposite of testConfig.grep. Also available in the command line with the --grep-invert option.
grepInvert option is also useful for tagging tests.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ grepInvert: /manual/, });Type
ignoreSnapshots
섹션 제목: “ignoreSnapshots”Added in: v1.26 testConfig.ignoreSnapshots
Whether to skip snapshot expectations, such as expect(value).toMatchSnapshot() and await expect(page).toHaveScreenshot().
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ ignoreSnapshots: !process.env.CI, });Type
maxFailures
섹션 제목: “maxFailures”Added in: v1.10 testConfig.maxFailures
The maximum number of test failures for the whole test suite run. After reaching this number, testing will stop and exit with an error. Setting to zero (default) disables this behavior.
Also available in the command line with the --max-failures and -x options.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ maxFailures: process.env.CI ? 1 : 0, });Type
metadata
섹션 제목: “metadata”Added in: v1.10 testConfig.metadata
Metadata contains key-value pairs to be included in the report. For example, the JSON report will include metadata serialized as JSON.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ metadata: { title: 'acceptance tests' }, });Type
name
섹션 제목: “name”Added in: v1.10 testConfig.name
Config name is visible in the report and during test execution, unless overridden by testProject.name.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ name: 'acceptance tests', });Type
outputDir
섹션 제목: “outputDir”Added in: v1.10 testConfig.outputDir
The output directory for files created during test execution. Defaults to <package.json-directory>/test-results.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ outputDir: './test-results', });Type
Details
This directory is cleaned at the start. When running a test, a unique subdirectory inside the testConfig.outputDir is created, guaranteeing that test running in parallel do not conflict. This directory can be accessed by testInfo.outputDir and testInfo.outputPath().
Here is an example that uses testInfo.outputPath() to create a temporary file.
import { test, expect } from '@playwright/test'; import fs from 'fs';
test('example test', async ({}, testInfo) => { const file = testInfo.outputPath('temporary-file.txt'); await fs.promises.writeFile(file, 'Put some data to the file', 'utf8'); });preserveOutput
섹션 제목: “preserveOutput”Added in: v1.10 testConfig.preserveOutput
Whether to preserve test output in the testConfig.outputDir. Defaults to 'always'.
'always'- preserve output for all tests;'never'- do not preserve output for any tests;'failures-only'- only preserve output for failed tests.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ preserveOutput: 'always', });Type
- “always” | “never” | “failures-only”
projects
섹션 제목: “projects”Added in: v1.10 testConfig.projects
Playwright Test supports running multiple test projects at the same time. See TestProject for more information.
Usage
playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({ projects: [ { name: 'chromium', use: devices['Desktop Chrome'] } ] });Type
quiet
섹션 제목: “quiet”Added in: v1.10 testConfig.quiet
Whether to suppress stdio and stderr output from the tests.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ quiet: !!process.env.CI, });Type
repeatEach
섹션 제목: “repeatEach”Added in: v1.10 testConfig.repeatEach
The number of times to repeat each test, useful for debugging flaky tests.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ repeatEach: 3, });Type
reportSlowTests
섹션 제목: “reportSlowTests”Added in: v1.10 testConfig.reportSlowTests
Whether to report slow test files. Pass null to disable this feature.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ reportSlowTests: null, });Type
The maximum number of slow test files to report. Defaults to 5.
* `threshold` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")Test file duration in milliseconds that is considered slow. Defaults to 5 minutes.
Details
Test files that took more than threshold milliseconds are considered slow, and the slowest ones are reported, no more than max number of them. Passing zero as max reports all test files that exceed the threshold.
reporter
섹션 제목: “reporter”Added in: v1.10 testConfig.reporter
The list of reporters to use. Each reporter can be:
- A builtin reporter name like
'list'or'json'. - A module name like
'my-awesome-reporter'. - A relative path to the reporter like
'./reporters/my-awesome-reporter.js'.
You can pass options to the reporter in a tuple like ['json', { outputFile: './report.json' }]. If the property is not specified, Playwright uses the 'dot' reporter when the CI environment variable is set, and the 'list' reporter otherwise.
Learn more in the reporters guide.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ reporter: 'line', });Type
- string | Array<Object> | “list” | “dot” | “line” | “github” | “json” | “junit” | “null” | “html”
0string
Reporter name or module or file path
* `1` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")An object with reporter options if any
respectGitIgnore
섹션 제목: “respectGitIgnore”Added in: v1.45 testConfig.respectGitIgnore
Whether to skip entries from .gitignore when searching for test files. By default, if neither testConfig.testDir nor testProject.testDir are explicitly specified, Playwright will ignore any test files matching .gitignore entries.
Usage
testConfig.respectGitIgnoreType
retries
섹션 제목: “retries”Added in: v1.10 testConfig.retries
The maximum number of retry attempts given to failed tests. By default failing tests are not retried. Learn more about test retries.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ retries: 2, });Type
shard
섹션 제목: “shard”Added in: v1.10 testConfig.shard
Shard tests and execute only the selected shard. Specify in the one-based form like { total: 5, current: 2 }.
Learn more about parallelism and sharding with Playwright Test.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ shard: { total: 10, current: 3 }, });Type
The index of the shard to execute, one-based.
* `total` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")The total number of shards.
snapshotPathTemplate
섹션 제목: “snapshotPathTemplate”Added in: v1.28 testConfig.snapshotPathTemplate
This option configures a template controlling location of snapshots generated by expect(page).toHaveScreenshot(), expect(locator).toMatchAriaSnapshot() and expect(value).toMatchSnapshot().
You can configure templates for each assertion separately in testConfig.expect.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ testDir: './tests',
// Single template for all assertions snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
// Assertion-specific templates expect: { toHaveScreenshot: { pathTemplate: '{testDir}/__screenshots__{/projectName}/{testFilePath}/{arg}{ext}', }, toMatchAriaSnapshot: { pathTemplate: '{testDir}/__snapshots__/{testFilePath}/{arg}{ext}', }, }, });Type
Details
The value might include some “tokens” that will be replaced with actual values during test execution.
Consider the following file structure:
playwright.config.ts tests/ └── page/ └── page-click.spec.tsAnd the following page-click.spec.ts that uses toHaveScreenshot() call:
page-click.spec.ts
import { test, expect } from '@playwright/test';
test.describe('suite', () => { test('test should work', async ({ page }) => { await expect(page).toHaveScreenshot(['foo', 'bar', 'baz.png']); }); });The list of supported tokens:
{arg}- Relative snapshot path without extension. This comes from the arguments passed totoHaveScreenshot(),toMatchAriaSnapshot()ortoMatchSnapshot(); if called without arguments, this will be an auto-generated snapshot name.- Value:
foo/bar/baz
- Value:
{ext}- Snapshot extension (with the leading dot).- Value:
.png
- Value:
{platform}- The value ofprocess.platform.{projectName}- Project’s file-system-sanitized name, if any.- Value:
''(empty string).
- Value:
{snapshotDir}- Project’s testProject.snapshotDir.- Value:
/home/playwright/tests(sincesnapshotDiris not provided in config, it defaults totestDir)
- Value:
{testDir}- Project’s testProject.testDir.- Value:
/home/playwright/tests(absolute path sincetestDiris resolved relative to directory with config)
- Value:
{testFileDir}- Directories in relative path fromtestDirto test file.- Value:
page
- Value:
{testFileName}- Test file name with extension.- Value:
page-click.spec.ts
- Value:
{testFilePath}- Relative path fromtestDirto test file.- Value:
page/page-click.spec.ts
- Value:
{testName}- File-system-sanitized test title, including parent describes but excluding file name.- Value:
suite-test-should-work
- Value:
Each token can be preceded with a single character that will be used only if this token has non-empty value.
Consider the following config:
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ snapshotPathTemplate: '__screenshots__{/projectName}/{testFilePath}/{arg}{ext}', testMatch: 'example.spec.ts', projects: [ { use: { browserName: 'firefox' } }, { name: 'chromium', use: { browserName: 'chromium' } }, ], });In this config:
- First project does not have a name, so its snapshots will be stored in
<configDir>/__screenshots__/example.spec.ts/.... - Second project does have a name, so its snapshots will be stored in
<configDir>/__screenshots__/chromium/example.spec.ts/... - Since
snapshotPathTemplateresolves to relative path, it will be resolved relative toconfigDir. - Forward slashes
"/"can be used as path separators on any platform.
Added in: v1.57 testConfig.tag
Tag or tags prepended to each test in the report. Useful for tagging your test run to differentiate between CI environments.
Note that each tag must start with @ symbol. Learn more about tagging.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ tag: process.env.CI_ENVIRONMENT_NAME, // for example "@APIv2" });Type
testDir
섹션 제목: “testDir”Added in: v1.10 testConfig.testDir
Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ testDir: './tests/playwright', });Type
testIgnore
섹션 제목: “testIgnore”Added in: v1.10 testConfig.testIgnore
Files matching one of these patterns are not executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.
For example, '**/test-assets/**' will ignore any files in the test-assets directory.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ testIgnore: '**/test-assets/**', });Type
testMatch
섹션 제목: “testMatch”Added in: v1.10 testConfig.testMatch
Only the files matching one of these patterns are executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.
By default, Playwright looks for files matching the following glob pattern: **/*.@(spec|test).?(c|m)[jt]s?(x). This means JavaScript or TypeScript files with ".test" or ".spec" suffix, for example login-screen.wrong-credentials.spec.ts.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ testMatch: /.*\.e2e\.js/, });Type
timeout
섹션 제목: “timeout”Added in: v1.10 testConfig.timeout
Timeout for each test in milliseconds. Defaults to 30 seconds.
This is a base timeout for all tests. In addition, each test can configure its own timeout with test.setTimeout(). Learn more about various timeouts.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ timeout: 5 * 60 * 1000, });Type
tsconfig
섹션 제목: “tsconfig”Added in: v1.49 testConfig.tsconfig
Path to a single tsconfig applicable to all imported files. By default, tsconfig for each imported file is looked up separately. Note that tsconfig property has no effect while the configuration file or any of its dependencies are loaded. Ignored when --tsconfig command line option is specified.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ tsconfig: './tsconfig.test.json', });Type
updateSnapshots
섹션 제목: “updateSnapshots”Added in: v1.10 testConfig.updateSnapshots
Whether to update expected snapshots with the actual results produced by the test run. Defaults to 'missing'.
'all'- All tests that are executed will update snapshots.'changed'- All tests that are executed will update snapshots that did not match. Matching snapshots will not be updated. Also creates missing snapshots.'missing'- Missing snapshots are created, for example when authoring a new test and running it for the first time. This is the default.'none'- No snapshots are updated.
Learn more about snapshots.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ updateSnapshots: 'missing', });Type
- “all” | “changed” | “missing” | “none”
updateSourceMethod
섹션 제목: “updateSourceMethod”Added in: v1.50 testConfig.updateSourceMethod
Defines how to update snapshots in the source code.
'patch'- Create a unified diff file that can be used to update the source code later. This is the default.'3way'- Generate merge conflict markers in source code. This allows user to manually pick relevant changes, as if they are resolving a merge conflict in the IDE.'overwrite'- Overwrite the source code with the new snapshot values.
Usage
testConfig.updateSourceMethodType
- “overwrite” | “3way” | “patch”
Added in: v1.10 testConfig.use
Global options for all tests, for example testOptions.browserName. Learn more about configuration and see available options.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ use: { browserName: 'chromium', }, });Type
webServer
섹션 제목: “webServer”Added in: v1.10 testConfig.webServer
Launch a development web server (or multiple) during the tests.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test'; export default defineConfig({ webServer: { command: 'npm run start', url: 'http://localhost:3000', timeout: 120 * 1000, reuseExistingServer: !process.env.CI, }, use: { baseURL: 'http://localhost:3000/', }, });Now you can use a relative path when navigating the page:
test.spec.ts
import { test } from '@playwright/test';
test('test', async ({ page }) => { // This will result in http://localhost:3000/foo await page.goto('/foo'); });Multiple web servers (or background processes) can be launched:
playwright.config.ts
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', }, });If your webserver runs on varying ports, use wait to capture the port:
import { defineConfig } from '@playwright/test';
export default defineConfig({ webServer: { command: 'npm run start', wait: { stdout: /Listening on port (?<my_server_port>\d+)/ }, }, }); import { test, expect } from '@playwright/test';
test.use({ baseUrl: `http://localhost:${process.env.MY_SERVER_PORT ?? 3000}` });
test('homepage', async ({ page }) => { await page.goto('/'); });Type
Shell command to start. For example npm run start..
* `cwd` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_Current working directory of the spawned process, defaults to the directory of the configuration file.
* `env` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string"), [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")> _(optional)_Environment variables to set for the command, process.env by default.
* `gracefulShutdown` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `signal` "SIGINT" | "SIGTERM"
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")How to shut down the process. If unspecified, the process group is forcefully SIGKILLed. If set to { signal: 'SIGTERM', timeout: 500 }, the process group is sent a SIGTERM signal, followed by SIGKILL if it doesn’t exit within 500ms. You can also use SIGINT as the signal instead. A 0 timeout means no SIGKILL will be sent. Windows doesn’t support SIGTERM and SIGINT signals, so this option is ignored on Windows. Note that shutting down a Docker container requires SIGTERM.
* `ignoreHTTPSErrors` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_Whether to ignore HTTPS errors when fetching the url. Defaults to false.
* `name` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_Specifies a custom name for the web server. This name will be prefixed to log messages. Defaults to [WebServer].
* `port` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_The port that your http server is expected to appear on. It does wait until it accepts connections. Either port or url should be specified.
* `reuseExistingServer` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_If true, it will re-use an existing server on the port or url when available. If no server is running on that port or url, it will run the command to start a new server. If false, it will throw if an existing process is listening on the port or url. This should be commonly set to !process.env.CI to allow the local dev server when running tests locally.
* `stderr` "pipe" | "ignore" _(optional)_Whether to pipe the stderr of the command to the process stderr or ignore it. Defaults to "pipe".
* `stdout` "pipe" | "ignore" _(optional)_If "pipe", it will pipe the stdout of the command to the process stdout. If "ignore", it will ignore the stdout of the command. Default to "ignore".
* `wait` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `stdout` [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") _(optional)_Regular expression to wait for in the stdout of the command output. Named capture groups are stored in the environment, for example /Listening on port (?<my_server_port>\d+)/ will store the port number in process.env['MY_SERVER_PORT'].
* `stderr` [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") _(optional)_Regular expression to wait for in the stderr of the command output. Named capture groups are stored in the environment, for example /Listening on port (?<my_server_port>\d+)/ will store the port number in process.env['MY_SERVER_PORT'].
Consider command started only when given output has been produced.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_How long to wait for the process to start up and be available in milliseconds. Defaults to 60000.
* `url` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_The url on your http server that is expected to return a 2xx, 3xx, 400, 401, 402, or 403 status code when the server is ready to accept connections. Redirects (3xx status codes) are being followed and the new location is checked. Either port or url should be specified.
Details
If the port is specified, Playwright Test will wait for it to be available on 127.0.0.1 or ::1, before running the tests. If the url is specified, Playwright Test will wait for the URL to return a 2xx, 3xx, 400, 401, 402, or 403 status code before running the tests.
For continuous integration, you may want to use the reuseExistingServer: !process.env.CI option which does not use an existing server on the CI. To see the stdout, you can set the DEBUG=pw:webserver environment variable.
The port (but not the url) gets passed over to Playwright as a testOptions.baseURL. For example port 8080 produces baseURL equal http://localhost:8080. If webServer is specified as an array, you must explicitly configure the baseURL (even if it only has one entry).
note
It is also recommended to specify testOptions.baseURL in the config, so that tests could use relative urls.
workers
섹션 제목: “workers”Added in: v1.10 testConfig.workers
The maximum number of concurrent worker processes to use for parallelizing tests. Can also be set as percentage of logical CPU cores, e.g. '50%'.
Playwright Test uses worker processes to run tests. There is always at least one worker process, but more can be used to speed up test execution.
Defaults to half of the number of logical CPU cores. Learn more about parallelism and sharding with Playwright Test.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ workers: 3, });Type
Deprecated
섹션 제목: “Deprecated”snapshotDir
섹션 제목: “snapshotDir”Added in: v1.10 testConfig.snapshotDir
Discouraged
Use testConfig.snapshotPathTemplate to configure snapshot paths.
The base directory, relative to the config file, for snapshot files created with toMatchSnapshot. Defaults to testConfig.testDir.
Usage
playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({ snapshotDir: './snapshots', });Type
Details
The directory for each test can be accessed by testInfo.snapshotDir and testInfo.snapshotPath().
This path will serve as the base directory for each test file snapshot directory. Setting snapshotDir to 'snapshots', the testInfo.snapshotDir would resolve to snapshots/a.spec.js-snapshots.