Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: move implementation of Config and Project to TestConfig and TestProject (#30212)
Yury Semikhatsky5c5f0d77e4c4
diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.tsindex d4662d4498..9d065280ac 100644--- a/packages/playwright/types/test.d.ts+++ b/packages/playwright/types/test.d.ts@@ -82,7 +82,7 @@ type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;* ```**/-export interface Project<TestArgs = {}, WorkerArgs = {}> extends TestProject {+interface TestProject<TestArgs = {}, WorkerArgs = {}> {/*** Options for all tests in this project, for example* [testOptions.browserName](https://playwright.dev/docs/api/class-testoptions#test-options-browser-name). Learn more@@ -108,6 +108,485 @@ export interface Project<TestArgs = {}, WorkerArgs = {}> extends TestProject {* all projects.*/use?: UseOptions<TestArgs, WorkerArgs>;+ /**+ * List of projects that need to run before any test in this project runs. Dependencies can be useful for configuring+ * the global setup actions in a way that every action is in a form of a test. Passing `--no-deps` argument ignores+ * the dependencies and behaves as if they were not specified.+ *+ * Using dependencies allows global setup to produce traces and other artifacts, see the setup steps in the test+ * report, etc.+ *+ * **Usage**+ *+ * ```js+ * // playwright.config.ts+ * import { defineConfig } from '@playwright/test';+ *+ * export default defineConfig({+ * projects: [+ * {+ * name: 'setup',+ * testMatch: /global.setup\.ts/,+ * },+ * {+ * name: 'chromium',+ * use: devices['Desktop Chrome'],+ * dependencies: ['setup'],+ * },+ * {+ * name: 'firefox',+ * use: devices['Desktop Firefox'],+ * dependencies: ['setup'],+ * },+ * {+ * name: 'webkit',+ * use: devices['Desktop Safari'],+ * dependencies: ['setup'],+ * },+ * ],+ * });+ * ```+ *+ */+ dependencies?: Array<string>;++ /**+ * Configuration for the `expect` assertion library.+ *+ * Use [testConfig.expect](https://playwright.dev/docs/api/class-testconfig#test-config-expect) to change this option+ * for all projects.+ */+ expect?: {+ /**+ * Default timeout for async expect matchers in milliseconds, defaults to 5000ms.+ */+ timeout?: number;++ /**+ * Configuration for the+ * [expect(page).toHaveScreenshot(name[, options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1)+ * method.+ */+ toHaveScreenshot?: {+ /**+ * 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](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.+ */+ threshold?: number;++ /**+ * an acceptable amount of pixels that could be different, unset by default.+ */+ maxDiffPixels?: number;++ /**+ * an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by+ * default.+ */+ maxDiffPixelRatio?: number;++ /**+ * See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot).+ * Defaults to `"disabled"`.+ */+ animations?: "allow"|"disabled";++ /**+ * See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults+ * to `"hide"`.+ */+ caret?: "hide"|"initial";++ /**+ * See `scale` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults+ * to `"css"`.+ */+ scale?: "css"|"device";++ /**+ * See `style` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot).+ */+ stylePath?: string|Array<string>;+ };++ /**+ * Configuration for the+ * [expect(value).toMatchSnapshot(name[, options])](https://playwright.dev/docs/api/class-snapshotassertions#snapshot-assertions-to-match-snapshot-1)+ * method.+ */+ toMatchSnapshot?: {+ /**+ * 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](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.+ */+ threshold?: number;++ /**+ * an acceptable amount of pixels that could be different, unset by default.+ */+ maxDiffPixels?: number;++ /**+ * an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by+ * default.+ */+ maxDiffPixelRatio?: number;+ };++ /**+ * Configuration for the [expect(value).toPass()](https://playwright.dev/docs/test-assertions) method.+ */+ toPass?: {+ /**+ * timeout for toPass method in milliseconds.+ */+ timeout?: number;++ /**+ * probe intervals for toPass method in milliseconds.+ */+ intervals?: Array<number>;+ };+ };++ /**+ * 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 project to concurrently run all tests in all files using this option.+ */+ fullyParallel?: boolean;++ /**+ * 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 globally and in the [command line](https://playwright.dev/docs/test-cli) with the `-g`+ * option. The regular expression will be tested against the string that consists of the test file name,+ * `test.describe` name (if any) and the test name divided by spaces, e.g. `my-test.spec.ts my-suite my-test`.+ *+ * `grep` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests).+ */+ grep?: RegExp|Array<RegExp>;++ /**+ * Filter to only run tests with a title **not** matching one of the patterns. This is the opposite of+ * [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep). Also available globally+ * and in the [command line](https://playwright.dev/docs/test-cli) with the `--grep-invert` option.+ *+ * `grepInvert` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests).+ */+ grepInvert?: RegExp|Array<RegExp>;++ /**+ * Metadata that will be put directly to the test report serialized as JSON.+ */+ metadata?: Metadata;++ /**+ * Project name is visible in the report and during test execution.+ */+ name?: string;++ /**+ * The output directory for files created during test execution. Defaults to `<package.json-directory>/test-results`.+ *+ * This directory is cleaned at the start. When running a test, a unique subdirectory inside the+ * [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir) is created,+ * guaranteeing that test running in parallel do not conflict. This directory can be accessed by+ * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) and+ * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path).+ *+ * Here is an example that uses+ * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path) to+ * create a temporary file.+ *+ * ```js+ * 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');+ * });+ * ```+ *+ * Use [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir) to change this+ * option for all projects.+ */+ outputDir?: string;++ /**+ * The number of times to repeat each test, useful for debugging flaky tests.+ *+ * Use [testConfig.repeatEach](https://playwright.dev/docs/api/class-testconfig#test-config-repeat-each) to change+ * this option for all projects.+ */+ repeatEach?: number;++ /**+ * The maximum number of retry attempts given to failed tests. Learn more about+ * [test retries](https://playwright.dev/docs/test-retries#retries).+ *+ * Use [test.describe.configure([options])](https://playwright.dev/docs/api/class-test#test-describe-configure) to+ * change the number of retries for a specific file or a group of tests.+ *+ * Use [testConfig.retries](https://playwright.dev/docs/api/class-testconfig#test-config-retries) to change this+ * option for all projects.+ */+ retries?: number;++ /**+ * The base directory, relative to the config file, for snapshot files created with `toMatchSnapshot`. Defaults to+ * [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir).+ *+ * The directory for each test can be accessed by+ * [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir) and+ * [testInfo.snapshotPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-path).+ *+ * This path will serve as the base directory for each test file snapshot directory. Setting `snapshotDir` to+ * `'snapshots'`, the [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir)+ * would resolve to `snapshots/a.spec.js-snapshots`.+ */+ snapshotDir?: string;++ /**+ * This option configures a template controlling location of snapshots generated by+ * [expect(page).toHaveScreenshot(name[, options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1)+ * and+ * [expect(value).toMatchSnapshot(name[, options])](https://playwright.dev/docs/api/class-snapshotassertions#snapshot-assertions-to-match-snapshot-1).+ *+ * **Usage**+ *+ * ```js+ * // playwright.config.ts+ * import { defineConfig } from '@playwright/test';+ *+ * export default defineConfig({+ * testDir: './tests',+ * snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',+ * });+ * ```+ *+ * **Details**+ *+ * The value might include some "tokens" that will be replaced with actual values during test execution.+ *+ * Consider the following file structure:+ *+ * ```txt+ * playwright.config.ts+ * tests/+ * └── page/+ * └── page-click.spec.ts+ * ```+ *+ * And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call:+ *+ * ```js+ * // 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:+ * - `{testDir}` - Project's+ * [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir).+ * - Value: `/home/playwright/tests` (absolute path is since `testDir` is resolved relative to directory with+ * config)+ * - `{snapshotDir}` - Project's+ * [testConfig.snapshotDir](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-dir).+ * - Value: `/home/playwright/tests` (since `snapshotDir` is not provided in config, it defaults to `testDir`)+ * - `{platform}` - The value of `process.platform`.+ * - `{projectName}` - Project's file-system-sanitized name, if any.+ * - Value: `''` (empty string).+ * - `{testFileDir}` - Directories in relative path from `testDir` to **test file**.+ * - Value: `page`+ * - `{testFileName}` - Test file name with extension.+ * - Value: `page-click.spec.ts`+ * - `{testFilePath}` - Relative path from `testDir` to **test file**+ * - Value: `page/page-click.spec.ts`+ * - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.+ * - Value: `suite-test-should-work`+ * - `{arg}` - Relative snapshot path **without extension**. These come from the arguments passed to the+ * `toHaveScreenshot()` and `toMatchSnapshot()` calls; if called without arguments, this will be an auto-generated+ * snapshot name.+ * - Value: `foo/bar/baz`+ * - `{ext}` - snapshot extension (with dots)+ * - Value: `.png`+ *+ * 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:+ *+ * ```js+ * // 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:+ * 1. First project **does not** have a name, so its snapshots will be stored in+ * `<configDir>/__screenshots__/example.spec.ts/...`.+ * 1. Second project **does** have a name, so its snapshots will be stored in+ * `<configDir>/__screenshots__/chromium/example.spec.ts/..`.+ * 1. Since `snapshotPathTemplate` resolves to relative path, it will be resolved relative to `configDir`.+ * 1. Forward slashes `"/"` can be used as path separators on any platform.+ */+ snapshotPathTemplate?: string;++ /**+ * Name of a project that needs to run after this and all dependent projects have finished. Teardown is useful to+ * cleanup any resources acquired by this project.+ *+ * Passing `--no-deps` argument ignores+ * [testProject.teardown](https://playwright.dev/docs/api/class-testproject#test-project-teardown) and behaves as if+ * it was not specified.+ *+ * **Usage**+ *+ * A common pattern is a "setup" dependency that has a corresponding "teardown":+ *+ * ```js+ * // playwright.config.ts+ * import { defineConfig } from '@playwright/test';+ *+ * export default defineConfig({+ * projects: [+ * {+ * name: 'setup',+ * testMatch: /global.setup\.ts/,+ * teardown: 'teardown',+ * },+ * {+ * name: 'teardown',+ * testMatch: /global.teardown\.ts/,+ * },+ * {+ * name: 'chromium',+ * use: devices['Desktop Chrome'],+ * dependencies: ['setup'],+ * },+ * {+ * name: 'firefox',+ * use: devices['Desktop Firefox'],+ * dependencies: ['setup'],+ * },+ * {+ * name: 'webkit',+ * use: devices['Desktop Safari'],+ * dependencies: ['setup'],+ * },+ * ],+ * });+ * ```+ *+ */+ teardown?: string;++ /**+ * Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file.+ *+ * Each project can use a different directory. Here is an example that runs smoke tests in three browsers and all+ * other tests in stable Chrome browser.+ *+ * ```js+ * // playwright.config.ts+ * import { defineConfig } from '@playwright/test';+ *+ * export default defineConfig({+ * projects: [+ * {+ * name: 'Smoke Chromium',+ * testDir: './smoke-tests',+ * use: {+ * browserName: 'chromium',+ * }+ * },+ * {+ * name: 'Smoke WebKit',+ * testDir: './smoke-tests',+ * use: {+ * browserName: 'webkit',+ * }+ * },+ * {+ * name: 'Smoke Firefox',+ * testDir: './smoke-tests',+ * use: {+ * browserName: 'firefox',+ * }+ * },+ * {+ * name: 'Chrome Stable',+ * testDir: './',+ * use: {+ * browserName: 'chromium',+ * channel: 'chrome',+ * }+ * },+ * ],+ * });+ * ```+ *+ * Use [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir) to change this+ * option for all projects.+ */+ testDir?: string;++ /**+ * 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.+ *+ * Use [testConfig.testIgnore](https://playwright.dev/docs/api/class-testconfig#test-config-test-ignore) to change+ * this option for all projects.+ */+ testIgnore?: string|RegExp|Array<string|RegExp>;++ /**+ * 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`.+ *+ * Use [testConfig.testMatch](https://playwright.dev/docs/api/class-testconfig#test-config-test-match) to change this+ * option for all projects.+ */+ testMatch?: string|RegExp|Array<string|RegExp>;++ /**+ * Timeout for each test in milliseconds. Defaults to 30 seconds.+ *+ * This is a base timeout for all tests. Each test can configure its own timeout with+ * [test.setTimeout(timeout)](https://playwright.dev/docs/api/class-test#test-set-timeout). Each file or a group of+ * tests can configure the timeout with+ * [test.describe.configure([options])](https://playwright.dev/docs/api/class-test#test-describe-configure).+ *+ * Use [testConfig.timeout](https://playwright.dev/docs/api/class-testconfig#test-config-timeout) to change this+ * option for all projects.+ */+ timeout?: number;+}++export interface Project<TestArgs = {}, WorkerArgs = {}> extends TestProject<TestArgs, WorkerArgs> {}/**@@ -215,7 +694,26 @@ type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });* ```**/-interface TestConfig {+interface TestConfig<TestArgs = {}, WorkerArgs = {}> {+ /**+ * Playwright Test supports running multiple test projects at the same time. See {@link TestProject} for more+ * information.+ *+ * **Usage**+ *+ * ```js+ * // playwright.config.ts+ * import { defineConfig, devices } from '@playwright/test';+ *+ * export default defineConfig({+ * projects: [+ * { name: 'chromium', use: devices['Desktop Chrome'] }+ * ]+ * });+ * ```+ *+ */+ projects?: Project<TestArgs, WorkerArgs>[];/*** The list of reporters to use. Each reporter can be:* - A builtin reporter name like `'list'` or `'json'`.@@ -239,6 +737,26 @@ interface TestConfig {**/reporter?: LiteralUnion<'list'|'dot'|'line'|'github'|'json'|'junit'|'null'|'html', string> | ReporterDescription[];+ /**+ * Global options for all tests, for example+ * [testOptions.browserName](https://playwright.dev/docs/api/class-testoptions#test-options-browser-name). Learn more+ * about [configuration](https://playwright.dev/docs/test-configuration) and see [available options]{@link TestOptions}.+ *+ * **Usage**+ *+ * ```js+ * // playwright.config.ts+ * import { defineConfig } from '@playwright/test';+ *+ * export default defineConfig({+ * use: {+ * browserName: 'chromium',+ * },+ * });+ * ```+ *+ */+ use?: UseOptions<TestArgs, WorkerArgs>;/*** Launch a development web server (or multiple) during the tests.*@@ -736,26 +1254,6 @@ interface TestConfig {*/preserveOutput?: "always"|"never"|"failures-only";- /**- * Playwright Test supports running multiple test projects at the same time. See {@link TestProject} for more- * information.- *- * **Usage**- *- * ```js- * // playwright.config.ts- * import { defineConfig, devices } from '@playwright/test';- *- * export default defineConfig({- * projects: [- * { name: 'chromium', use: devices['Desktop Chrome'] }- * ]- * });- * ```- *- */- projects?: Array<TestProject>;-/*** Whether to suppress stdio and stderr output from the tests.*@@ -1126,68 +1624,7 @@ interface TestConfig {workers?: number|string;}-/**- * 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 {@link TestConfig} object in the- * [configuration file](https://playwright.dev/docs/test-configuration).- *- * Playwright Test supports running multiple test projects at the same time. Project-specific options should be put to- * [testConfig.projects](https://playwright.dev/docs/api/class-testconfig#test-config-projects), but top-level {@link- * TestConfig} can also define base options shared between all projects.- *- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- *- * export default defineConfig({- * timeout: 30000,- * globalTimeout: 600000,- * reporter: 'list',- * testDir: './tests',- * });- * ```- *- */-export interface Config<TestArgs = {}, WorkerArgs = {}> extends TestConfig {- /**- * Playwright Test supports running multiple test projects at the same time. See {@link TestProject} for more- * information.- *- * **Usage**- *- * ```js- * // playwright.config.ts- * import { defineConfig, devices } from '@playwright/test';- *- * export default defineConfig({- * projects: [- * { name: 'chromium', use: devices['Desktop Chrome'] }- * ]- * });- * ```- *- */- projects?: Project<TestArgs, WorkerArgs>[];- /**- * Global options for all tests, for example- * [testOptions.browserName](https://playwright.dev/docs/api/class-testoptions#test-options-browser-name). Learn more- * about [configuration](https://playwright.dev/docs/test-configuration) and see [available options]{@link TestOptions}.- *- * **Usage**- *- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- *- * export default defineConfig({- * use: {- * browserName: 'chromium',- * },- * });- * ```- *- */- use?: UseOptions<TestArgs, WorkerArgs>;+export interface Config<TestArgs = {}, WorkerArgs = {}> extends TestConfig<TestArgs, WorkerArgs> {}export type Metadata = { [key: string]: any };@@ -7422,354 +7859,72 @@ export interface TestInfo {*/contentType?: string;- /**- * Path on the filesystem to the attached file. Mutually exclusive with `body`.- */- path?: string;- }): Promise<void>;-- /**- * Marks the currently running test as "should fail". Playwright Test runs this test and ensures that it is actually- * failing. This is useful for documentation purposes to acknowledge that some functionality is broken until it is- * fixed. This is similar to- * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail).- */- fail(): void;-- /**- * Conditionally mark the currently running test as "should fail" with an optional description. This is similar to- * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail).- * @param condition Test is marked as "should fail" when the condition is `true`.- * @param description Optional description that will be reflected in a test report.- */- fail(condition: boolean, description?: string): void;-- /**- * Mark a test as "fixme", with the intention to fix it. Test is immediately aborted. This is similar to- * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme).- */- fixme(): void;-- /**- * Conditionally mark the currently running test as "fixme" with an optional description. This is similar to- * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme).- * @param condition Test is marked as "fixme" when the condition is `true`.- * @param description Optional description that will be reflected in a test report.- */- fixme(condition: boolean, description?: string): void;-- /**- * Returns a path inside the [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir)- * where the test can safely put a temporary file. Guarantees that tests running in parallel will not interfere with- * each other.- *- * ```js- * import { test, expect } from '@playwright/test';- * import fs from 'fs';- *- * test('example test', async ({}, testInfo) => {- * const file = testInfo.outputPath('dir', 'temporary-file.txt');- * await fs.promises.writeFile(file, 'Put some data to the dir/temporary-file.txt', 'utf8');- * });- * ```- *- * > Note that `pathSegments` accepts path segments to the test output directory such as- * `testInfo.outputPath('relative', 'path', 'to', 'output')`.- * > However, this path must stay within the- * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) directory for each test- * (i.e. `test-results/a-test-title`), otherwise it will throw.- * @param pathSegments Path segments to append at the end of the resulting path.- */- outputPath(...pathSegments: ReadonlyArray<string>): string;-- /**- * Changes the timeout for the currently running test. Zero means no timeout. Learn more about- * [various timeouts](https://playwright.dev/docs/test-timeouts).- *- * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration), but it could be useful to- * change the timeout in certain scenarios:- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.beforeEach(async ({ page }, testInfo) => {- * // Extend timeout for all tests running this hook by 30 seconds.- * testInfo.setTimeout(testInfo.timeout + 30000);- * });- * ```- *- * @param timeout Timeout in milliseconds.- */- setTimeout(timeout: number): void;-- /**- * Unconditionally skip the currently running test. Test is immediately aborted. This is similar to- * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip).- */- skip(): void;-- /**- * Conditionally skips the currently running test with an optional description. This is similar to- * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip).- * @param condition A skip condition. Test is skipped when the condition is `true`.- * @param description Optional description that will be reflected in a test report.- */- skip(condition: boolean, description?: string): void;-- /**- * Marks the currently running test as "slow", giving it triple the default timeout. This is similar to- * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow).- */- slow(): void;-- /**- * Conditionally mark the currently running test as "slow" with an optional description, giving it triple the default- * timeout. This is similar to- * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow).- * @param condition Test is marked as "slow" when the condition is `true`.- * @param description Optional description that will be reflected in a test report.- */- slow(condition: boolean, description?: string): void;-- /**- * Returns a path to a snapshot file with the given `pathSegments`. Learn more about- * [snapshots](https://playwright.dev/docs/test-snapshots).- *- * > Note that `pathSegments` accepts path segments to the snapshot file such as `testInfo.snapshotPath('relative',- * 'path', 'to', 'snapshot.png')`.- * > However, this path must stay within the snapshots directory for each test file (i.e. `a.spec.js-snapshots`),- * otherwise it will throw.- * @param pathSegments The name of the snapshot or the path segments to define the snapshot file path. Snapshots with the same name in the- * same test file are expected to be the same.- */- snapshotPath(...pathSegments: ReadonlyArray<string>): string;-- /**- * The list of annotations applicable to the current test. Includes annotations from the test, annotations from all- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe) groups the- * test belongs to and file-level annotations for the test file.- *- * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).- */- annotations: Array<{- /**- * Annotation type, for example `'skip'` or `'fail'`.- */- type: string;-- /**- * Optional description.- */- description?: string;- }>;-- /**- * The list of files or buffers attached to the current test. Some reporters show test attachments.- *- * To add an attachment, use- * [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach) instead of- * directly pushing onto this array.- */- attachments: Array<{- /**- * Attachment name.- */- name: string;-- /**- * Content type of this attachment to properly present in the report, for example `'application/json'` or- * `'image/png'`.- */- contentType: string;-- /**- * Optional path on the filesystem to the attached file.- */- path?: string;-- /**- * Optional attachment body used instead of a file.- */- body?: Buffer;- }>;-- /**- * Column number where the currently running test is declared.- */- column: number;-- /**- * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration).- */- config: ConfigInWorker;-- /**- * The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or- * not. Can be used in- * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each) hook.- */- duration: number;-- /**- * First error thrown during test execution, if any. This is equal to the first element in- * [testInfo.errors](https://playwright.dev/docs/api/class-testinfo#test-info-errors).- */- error?: TestInfoError;-- /**- * Errors thrown during test execution, if any.- */- errors: Array<TestInfoError>;-- /**- * Expected status for the currently running test. This is usually `'passed'`, except for a few cases:- * - `'skipped'` for skipped tests, e.g. with- * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip);- * - `'failed'` for tests marked as failed with- * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail).- *- * Expected status is usually compared with the actual- * [testInfo.status](https://playwright.dev/docs/api/class-testinfo#test-info-status):- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.afterEach(async ({}, testInfo) => {- * if (testInfo.status !== testInfo.expectedStatus)- * console.log(`${testInfo.title} did not run as expected!`);- * });- * ```- *- */- expectedStatus: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";-- /**- * Absolute path to a file where the currently running test is declared.- */- file: string;-- /**- * Test function as passed to `test(title, testFunction)`.- */- fn: Function;-- /**- * Line number where the currently running test is declared.- */- line: number;-- /**- * Absolute path to the output directory for this specific test run. Each test run gets its own directory so they- * cannot conflict.- */- outputDir: string;-- /**- * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have- * a different `parallelIndex`. When a worker is restarted, for example after a failure, the new worker process has- * the same `parallelIndex`.- *- * Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about- * [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test.- */- parallelIndex: number;-- /**- * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration).- */- project: ProjectInWorker;+ /**+ * Path on the filesystem to the attached file. Mutually exclusive with `body`.+ */+ path?: string;+ }): Promise<void>;/**- * Specifies a unique repeat index when running in "repeat each" mode. This mode is enabled by passing `--repeat-each`- * to the [command line](https://playwright.dev/docs/test-cli).+ * Marks the currently running test as "should fail". Playwright Test runs this test and ensures that it is actually+ * failing. This is useful for documentation purposes to acknowledge that some functionality is broken until it is+ * fixed. This is similar to+ * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail).*/- repeatEachIndex: number;+ fail(): void;/**- * Specifies the retry number when the test is retried after a failure. The first test run has- * [testInfo.retry](https://playwright.dev/docs/api/class-testinfo#test-info-retry) equal to zero, the first retry has- * it equal to one, and so on. Learn more about [retries](https://playwright.dev/docs/test-retries#retries).- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.beforeEach(async ({}, testInfo) => {- * // You can access testInfo.retry in any hook or fixture.- * if (testInfo.retry > 0)- * console.log(`Retrying!`);- * });- *- * test('my test', async ({ page }, testInfo) => {- * // Here we clear some server-side state when retrying.- * if (testInfo.retry)- * await cleanSomeCachesOnTheServer();- * // ...- * });- * ```- *+ * Conditionally mark the currently running test as "should fail" with an optional description. This is similar to+ * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail).+ * @param condition Test is marked as "should fail" when the condition is `true`.+ * @param description Optional description that will be reflected in a test report.*/- retry: number;+ fail(condition: boolean, description?: string): void;/**- * Absolute path to the snapshot output directory for this specific test. Each test suite gets its own directory so- * they cannot conflict.- *- * This property does not account for the- * [testProject.snapshotPathTemplate](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-path-template)- * configuration.+ * Mark a test as "fixme", with the intention to fix it. Test is immediately aborted. This is similar to+ * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme).*/- snapshotDir: string;+ fixme(): void;/**- * **NOTE** Use of [testInfo.snapshotSuffix](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-suffix)- * is discouraged. Please use- * [testConfig.snapshotPathTemplate](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-path-template)- * to configure snapshot paths.- *- * Suffix used to differentiate snapshots between multiple test configurations. For example, if snapshots depend on- * the platform, you can set `testInfo.snapshotSuffix` equal to `process.platform`. In this case- * `expect(value).toMatchSnapshot(snapshotName)` will use different snapshots depending on the platform. Learn more- * about [snapshots](https://playwright.dev/docs/test-snapshots).+ * Conditionally mark the currently running test as "fixme" with an optional description. This is similar to+ * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme).+ * @param condition Test is marked as "fixme" when the condition is `true`.+ * @param description Optional description that will be reflected in a test report.*/- snapshotSuffix: string;+ fixme(condition: boolean, description?: string): void;/**- * Actual status for the currently running test. Available after the test has finished in- * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each) hook and- * fixtures.- *- * Status is usually compared with the- * [testInfo.expectedStatus](https://playwright.dev/docs/api/class-testinfo#test-info-expected-status):+ * Returns a path inside the [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir)+ * where the test can safely put a temporary file. Guarantees that tests running in parallel will not interfere with+ * each other.** ```js* import { test, expect } from '@playwright/test';+ * import fs from 'fs';*- * test.afterEach(async ({}, testInfo) => {- * if (testInfo.status !== testInfo.expectedStatus)- * console.log(`${testInfo.title} did not run as expected!`);+ * test('example test', async ({}, testInfo) => {+ * const file = testInfo.outputPath('dir', 'temporary-file.txt');+ * await fs.promises.writeFile(file, 'Put some data to the dir/temporary-file.txt', 'utf8');* });* ```*+ * > Note that `pathSegments` accepts path segments to the test output directory such as+ * `testInfo.outputPath('relative', 'path', 'to', 'output')`.+ * > However, this path must stay within the+ * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) directory for each test+ * (i.e. `test-results/a-test-title`), otherwise it will throw.+ * @param pathSegments Path segments to append at the end of the resulting path.*/- status?: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";-- /**- * Tags that apply to the test. Learn more about [tags](https://playwright.dev/docs/test-annotations#tag-tests).- *- * Note that any changes made to this list while the test is running will not be visible to test reporters.- */- tags: Array<string>;-- /**- * Test id matching the test case id in the reporter API.- */- testId: string;+ outputPath(...pathSegments: ReadonlyArray<string>): string;/**- * Timeout in milliseconds for the currently running test. Zero means no timeout. Learn more about+ * Changes the timeout for the currently running test. Zero means no timeout. Learn more about* [various timeouts](https://playwright.dev/docs/test-timeouts).*- * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration)+ * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration), but it could be useful to+ * change the timeout in certain scenarios:** ```js* import { test, expect } from '@playwright/test';@@ -7780,576 +7935,329 @@ export interface TestInfo {* });* ```*+ * @param timeout Timeout in milliseconds.*/- timeout: number;-- /**- * The title of the currently running test as passed to `test(title, testFunction)`.- */- title: string;+ setTimeout(timeout: number): void;/**- * The full title path starting with the project.+ * Unconditionally skip the currently running test. Test is immediately aborted. This is similar to+ * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip).*/- titlePath: Array<string>;+ skip(): void;/**- * The unique index of the worker process that is running the test. When a worker is restarted, for example after a- * failure, the new worker process gets a new unique `workerIndex`.- *- * Also available as `process.env.TEST_WORKER_INDEX`. Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel)- * with Playwright Test.+ * Conditionally skips the currently running test with an optional description. This is similar to+ * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip).+ * @param condition A skip condition. Test is skipped when the condition is `true`.+ * @param description Optional description that will be reflected in a test report.*/- workerIndex: number;-}+ skip(condition: boolean, description?: string): void;-/**- * Information about an error thrown during test execution.- */-export interface TestInfoError {/**- * Error message. Set when [Error] (or its subclass) has been thrown.+ * Marks the currently running test as "slow", giving it triple the default timeout. This is similar to+ * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow).*/- message?: string;+ slow(): void;/**- * Error stack. Set when [Error] (or its subclass) has been thrown.+ * Conditionally mark the currently running test as "slow" with an optional description, giving it triple the default+ * timeout. This is similar to+ * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow).+ * @param condition Test is marked as "slow" when the condition is `true`.+ * @param description Optional description that will be reflected in a test report.*/- stack?: string;+ slow(condition: boolean, description?: string): void;/**- * The value that was thrown. Set when anything except the [Error] (or its subclass) has been thrown.+ * Returns a path to a snapshot file with the given `pathSegments`. Learn more about+ * [snapshots](https://playwright.dev/docs/test-snapshots).+ *+ * > Note that `pathSegments` accepts path segments to the snapshot file such as `testInfo.snapshotPath('relative',+ * 'path', 'to', 'snapshot.png')`.+ * > However, this path must stay within the snapshots directory for each test file (i.e. `a.spec.js-snapshots`),+ * otherwise it will throw.+ * @param pathSegments The name of the snapshot or the path segments to define the snapshot file path. Snapshots with the same name in the+ * same test file are expected to be the same.*/- value?: string;-}+ snapshotPath(...pathSegments: ReadonlyArray<string>): string;-/**- * Playwright Test supports running multiple test projects at the same time. This is useful for running tests in- * multiple configurations. For example, consider running tests against multiple browsers.- *- * `TestProject` encapsulates configuration specific to a single project. Projects are configured in- * [testConfig.projects](https://playwright.dev/docs/api/class-testconfig#test-config-projects) specified in the- * [configuration file](https://playwright.dev/docs/test-configuration). Note that all properties of {@link TestProject} are available in- * the top-level {@link TestConfig}, in which case they are shared between all projects.- *- * Here is an example configuration that runs every test in Chromium, Firefox and WebKit, both Desktop and Mobile- * versions.- *- * ```js- * // playwright.config.ts- * import { defineConfig, devices } from '@playwright/test';- *- * export default defineConfig({- * // Options shared for all projects.- * timeout: 30000,- * use: {- * ignoreHTTPSErrors: true,- * },- *- * // Options specific to each project.- * projects: [- * {- * name: 'chromium',- * use: devices['Desktop Chrome'],- * },- * {- * name: 'firefox',- * use: devices['Desktop Firefox'],- * },- * {- * name: 'webkit',- * use: devices['Desktop Safari'],- * },- * {- * name: 'Mobile Chrome',- * use: devices['Pixel 5'],- * },- * {- * name: 'Mobile Safari',- * use: devices['iPhone 12'],- * },- * ],- * });- * ```- *- */-interface TestProject {/**- * List of projects that need to run before any test in this project runs. Dependencies can be useful for configuring- * the global setup actions in a way that every action is in a form of a test. Passing `--no-deps` argument ignores- * the dependencies and behaves as if they were not specified.- *- * Using dependencies allows global setup to produce traces and other artifacts, see the setup steps in the test- * report, etc.- *- * **Usage**- *- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- *- * export default defineConfig({- * projects: [- * {- * name: 'setup',- * testMatch: /global.setup\.ts/,- * },- * {- * name: 'chromium',- * use: devices['Desktop Chrome'],- * dependencies: ['setup'],- * },- * {- * name: 'firefox',- * use: devices['Desktop Firefox'],- * dependencies: ['setup'],- * },- * {- * name: 'webkit',- * use: devices['Desktop Safari'],- * dependencies: ['setup'],- * },- * ],- * });- * ```+ * The list of annotations applicable to the current test. Includes annotations from the test, annotations from all+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe) groups the+ * test belongs to and file-level annotations for the test file.*+ * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).*/- dependencies?: Array<string>;+ annotations: Array<{+ /**+ * Annotation type, for example `'skip'` or `'fail'`.+ */+ type: string;++ /**+ * Optional description.+ */+ description?: string;+ }>;/**- * Configuration for the `expect` assertion library.+ * The list of files or buffers attached to the current test. Some reporters show test attachments.*- * Use [testConfig.expect](https://playwright.dev/docs/api/class-testconfig#test-config-expect) to change this option- * for all projects.+ * To add an attachment, use+ * [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach) instead of+ * directly pushing onto this array.*/- expect?: {+ attachments: Array<{/**- * Default timeout for async expect matchers in milliseconds, defaults to 5000ms.+ * Attachment name.*/- timeout?: number;+ name: string;/**- * Configuration for the- * [expect(page).toHaveScreenshot(name[, options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1)- * method.+ * Content type of this attachment to properly present in the report, for example `'application/json'` or+ * `'image/png'`.*/- toHaveScreenshot?: {- /**- * 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](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.- */- threshold?: number;-- /**- * an acceptable amount of pixels that could be different, unset by default.- */- maxDiffPixels?: number;-- /**- * an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by- * default.- */- maxDiffPixelRatio?: number;-- /**- * See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot).- * Defaults to `"disabled"`.- */- animations?: "allow"|"disabled";-- /**- * See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults- * to `"hide"`.- */- caret?: "hide"|"initial";-- /**- * See `scale` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults- * to `"css"`.- */- scale?: "css"|"device";-- /**- * See `style` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot).- */- stylePath?: string|Array<string>;- };+ contentType: string;/**- * Configuration for the- * [expect(value).toMatchSnapshot(name[, options])](https://playwright.dev/docs/api/class-snapshotassertions#snapshot-assertions-to-match-snapshot-1)- * method.+ * Optional path on the filesystem to the attached file.*/- toMatchSnapshot?: {- /**- * 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](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.- */- threshold?: number;-- /**- * an acceptable amount of pixels that could be different, unset by default.- */- maxDiffPixels?: number;-- /**- * an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by- * default.- */- maxDiffPixelRatio?: number;- };+ path?: string;/**- * Configuration for the [expect(value).toPass()](https://playwright.dev/docs/test-assertions) method.+ * Optional attachment body used instead of a file.*/- toPass?: {- /**- * timeout for toPass method in milliseconds.- */- timeout?: number;-- /**- * probe intervals for toPass method in milliseconds.- */- intervals?: Array<number>;- };- };+ body?: Buffer;+ }>;/**- * 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 project to concurrently run all tests in all files using this option.+ * Column number where the currently running test is declared.*/- fullyParallel?: boolean;+ column: number;/**- * 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 globally and in the [command line](https://playwright.dev/docs/test-cli) with the `-g`- * option. The regular expression will be tested against the string that consists of the test file name,- * `test.describe` name (if any) and the test name divided by spaces, e.g. `my-test.spec.ts my-suite my-test`.- *- * `grep` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests).+ * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration).*/- grep?: RegExp|Array<RegExp>;+ config: ConfigInWorker;/**- * Filter to only run tests with a title **not** matching one of the patterns. This is the opposite of- * [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep). Also available globally- * and in the [command line](https://playwright.dev/docs/test-cli) with the `--grep-invert` option.- *- * `grepInvert` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests).+ * The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or+ * not. Can be used in+ * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each) hook.*/- grepInvert?: RegExp|Array<RegExp>;+ duration: number;/**- * Metadata that will be put directly to the test report serialized as JSON.+ * First error thrown during test execution, if any. This is equal to the first element in+ * [testInfo.errors](https://playwright.dev/docs/api/class-testinfo#test-info-errors).*/- metadata?: Metadata;+ error?: TestInfoError;/**- * Project name is visible in the report and during test execution.+ * Errors thrown during test execution, if any.*/- name?: string;+ errors: Array<TestInfoError>;/**- * The output directory for files created during test execution. Defaults to `<package.json-directory>/test-results`.- *- * This directory is cleaned at the start. When running a test, a unique subdirectory inside the- * [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir) is created,- * guaranteeing that test running in parallel do not conflict. This directory can be accessed by- * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) and- * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path).+ * Expected status for the currently running test. This is usually `'passed'`, except for a few cases:+ * - `'skipped'` for skipped tests, e.g. with+ * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip);+ * - `'failed'` for tests marked as failed with+ * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail).*- * Here is an example that uses- * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path) to- * create a temporary file.+ * Expected status is usually compared with the actual+ * [testInfo.status](https://playwright.dev/docs/api/class-testinfo#test-info-status):** ```js* 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');+ * test.afterEach(async ({}, testInfo) => {+ * if (testInfo.status !== testInfo.expectedStatus)+ * console.log(`${testInfo.title} did not run as expected!`);* });* ```*- * Use [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir) to change this- * option for all projects.*/- outputDir?: string;+ expectedStatus: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";/**- * The number of times to repeat each test, useful for debugging flaky tests.- *- * Use [testConfig.repeatEach](https://playwright.dev/docs/api/class-testconfig#test-config-repeat-each) to change- * this option for all projects.+ * Absolute path to a file where the currently running test is declared.*/- repeatEach?: number;+ file: string;/**- * The maximum number of retry attempts given to failed tests. Learn more about- * [test retries](https://playwright.dev/docs/test-retries#retries).- *- * Use [test.describe.configure([options])](https://playwright.dev/docs/api/class-test#test-describe-configure) to- * change the number of retries for a specific file or a group of tests.- *- * Use [testConfig.retries](https://playwright.dev/docs/api/class-testconfig#test-config-retries) to change this- * option for all projects.+ * Test function as passed to `test(title, testFunction)`.*/- retries?: number;+ fn: Function;/**- * The base directory, relative to the config file, for snapshot files created with `toMatchSnapshot`. Defaults to- * [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir).- *- * The directory for each test can be accessed by- * [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir) and- * [testInfo.snapshotPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-path).- *- * This path will serve as the base directory for each test file snapshot directory. Setting `snapshotDir` to- * `'snapshots'`, the [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir)- * would resolve to `snapshots/a.spec.js-snapshots`.+ * Line number where the currently running test is declared.*/- snapshotDir?: string;+ line: number;/**- * This option configures a template controlling location of snapshots generated by- * [expect(page).toHaveScreenshot(name[, options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1)- * and- * [expect(value).toMatchSnapshot(name[, options])](https://playwright.dev/docs/api/class-snapshotassertions#snapshot-assertions-to-match-snapshot-1).- *- * **Usage**- *- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- *- * export default defineConfig({- * testDir: './tests',- * snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',- * });- * ```- *- * **Details**- *- * The value might include some "tokens" that will be replaced with actual values during test execution.- *- * Consider the following file structure:- *- * ```txt- * playwright.config.ts- * tests/- * └── page/- * └── page-click.spec.ts- * ```+ * Absolute path to the output directory for this specific test run. Each test run gets its own directory so they+ * cannot conflict.+ */+ outputDir: string;++ /**+ * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have+ * a different `parallelIndex`. When a worker is restarted, for example after a failure, the new worker process has+ * the same `parallelIndex`.*- * And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call:+ * Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about+ * [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test.+ */+ parallelIndex: number;++ /**+ * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration).+ */+ project: ProjectInWorker;++ /**+ * Specifies a unique repeat index when running in "repeat each" mode. This mode is enabled by passing `--repeat-each`+ * to the [command line](https://playwright.dev/docs/test-cli).+ */+ repeatEachIndex: number;++ /**+ * Specifies the retry number when the test is retried after a failure. The first test run has+ * [testInfo.retry](https://playwright.dev/docs/api/class-testinfo#test-info-retry) equal to zero, the first retry has+ * it equal to one, and so on. Learn more about [retries](https://playwright.dev/docs/test-retries#retries).** ```js- * // 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']);- * });+ * test.beforeEach(async ({}, testInfo) => {+ * // You can access testInfo.retry in any hook or fixture.+ * if (testInfo.retry > 0)+ * console.log(`Retrying!`);* });- * ```- *- * The list of supported tokens:- * - `{testDir}` - Project's- * [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir).- * - Value: `/home/playwright/tests` (absolute path is since `testDir` is resolved relative to directory with- * config)- * - `{snapshotDir}` - Project's- * [testConfig.snapshotDir](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-dir).- * - Value: `/home/playwright/tests` (since `snapshotDir` is not provided in config, it defaults to `testDir`)- * - `{platform}` - The value of `process.platform`.- * - `{projectName}` - Project's file-system-sanitized name, if any.- * - Value: `''` (empty string).- * - `{testFileDir}` - Directories in relative path from `testDir` to **test file**.- * - Value: `page`- * - `{testFileName}` - Test file name with extension.- * - Value: `page-click.spec.ts`- * - `{testFilePath}` - Relative path from `testDir` to **test file**- * - Value: `page/page-click.spec.ts`- * - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.- * - Value: `suite-test-should-work`- * - `{arg}` - Relative snapshot path **without extension**. These come from the arguments passed to the- * `toHaveScreenshot()` and `toMatchSnapshot()` calls; if called without arguments, this will be an auto-generated- * snapshot name.- * - Value: `foo/bar/baz`- * - `{ext}` - snapshot extension (with dots)- * - Value: `.png`- *- * 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:- *- * ```js- * // 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' } },- * ],+ * test('my test', async ({ page }, testInfo) => {+ * // Here we clear some server-side state when retrying.+ * if (testInfo.retry)+ * await cleanSomeCachesOnTheServer();+ * // ...* });* ```*- * In this config:- * 1. First project **does not** have a name, so its snapshots will be stored in- * `<configDir>/__screenshots__/example.spec.ts/...`.- * 1. Second project **does** have a name, so its snapshots will be stored in- * `<configDir>/__screenshots__/chromium/example.spec.ts/..`.- * 1. Since `snapshotPathTemplate` resolves to relative path, it will be resolved relative to `configDir`.- * 1. Forward slashes `"/"` can be used as path separators on any platform.*/- snapshotPathTemplate?: string;+ retry: number;/**- * Name of a project that needs to run after this and all dependent projects have finished. Teardown is useful to- * cleanup any resources acquired by this project.+ * Absolute path to the snapshot output directory for this specific test. Each test suite gets its own directory so+ * they cannot conflict.*- * Passing `--no-deps` argument ignores- * [testProject.teardown](https://playwright.dev/docs/api/class-testproject#test-project-teardown) and behaves as if- * it was not specified.+ * This property does not account for the+ * [testProject.snapshotPathTemplate](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-path-template)+ * configuration.+ */+ snapshotDir: string;++ /**+ * **NOTE** Use of [testInfo.snapshotSuffix](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-suffix)+ * is discouraged. Please use+ * [testConfig.snapshotPathTemplate](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-path-template)+ * to configure snapshot paths.*- * **Usage**+ * Suffix used to differentiate snapshots between multiple test configurations. For example, if snapshots depend on+ * the platform, you can set `testInfo.snapshotSuffix` equal to `process.platform`. In this case+ * `expect(value).toMatchSnapshot(snapshotName)` will use different snapshots depending on the platform. Learn more+ * about [snapshots](https://playwright.dev/docs/test-snapshots).+ */+ snapshotSuffix: string;++ /**+ * Actual status for the currently running test. Available after the test has finished in+ * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each) hook and+ * fixtures.*- * A common pattern is a "setup" dependency that has a corresponding "teardown":+ * Status is usually compared with the+ * [testInfo.expectedStatus](https://playwright.dev/docs/api/class-testinfo#test-info-expected-status):** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * projects: [- * {- * name: 'setup',- * testMatch: /global.setup\.ts/,- * teardown: 'teardown',- * },- * {- * name: 'teardown',- * testMatch: /global.teardown\.ts/,- * },- * {- * name: 'chromium',- * use: devices['Desktop Chrome'],- * dependencies: ['setup'],- * },- * {- * name: 'firefox',- * use: devices['Desktop Firefox'],- * dependencies: ['setup'],- * },- * {- * name: 'webkit',- * use: devices['Desktop Safari'],- * dependencies: ['setup'],- * },- * ],+ * test.afterEach(async ({}, testInfo) => {+ * if (testInfo.status !== testInfo.expectedStatus)+ * console.log(`${testInfo.title} did not run as expected!`);* });* ```**/- teardown?: string;+ status?: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";/**- * Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file.+ * Tags that apply to the test. Learn more about [tags](https://playwright.dev/docs/test-annotations#tag-tests).*- * Each project can use a different directory. Here is an example that runs smoke tests in three browsers and all- * other tests in stable Chrome browser.+ * Note that any changes made to this list while the test is running will not be visible to test reporters.+ */+ tags: Array<string>;++ /**+ * Test id matching the test case id in the reporter API.+ */+ testId: string;++ /**+ * Timeout in milliseconds for the currently running test. Zero means no timeout. Learn more about+ * [various timeouts](https://playwright.dev/docs/test-timeouts).+ *+ * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration)** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * projects: [- * {- * name: 'Smoke Chromium',- * testDir: './smoke-tests',- * use: {- * browserName: 'chromium',- * }- * },- * {- * name: 'Smoke WebKit',- * testDir: './smoke-tests',- * use: {- * browserName: 'webkit',- * }- * },- * {- * name: 'Smoke Firefox',- * testDir: './smoke-tests',- * use: {- * browserName: 'firefox',- * }- * },- * {- * name: 'Chrome Stable',- * testDir: './',- * use: {- * browserName: 'chromium',- * channel: 'chrome',- * }- * },- * ],+ * test.beforeEach(async ({ page }, testInfo) => {+ * // Extend timeout for all tests running this hook by 30 seconds.+ * testInfo.setTimeout(testInfo.timeout + 30000);* });* ```*- * Use [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir) to change this- * option for all projects.*/- testDir?: string;+ timeout: number;/**- * 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.- *- * Use [testConfig.testIgnore](https://playwright.dev/docs/api/class-testconfig#test-config-test-ignore) to change- * this option for all projects.+ * The title of the currently running test as passed to `test(title, testFunction)`.*/- testIgnore?: string|RegExp|Array<string|RegExp>;+ title: string;/**- * 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`.- *- * Use [testConfig.testMatch](https://playwright.dev/docs/api/class-testconfig#test-config-test-match) to change this- * option for all projects.+ * The full title path starting with the project.*/- testMatch?: string|RegExp|Array<string|RegExp>;+ titlePath: Array<string>;/**- * Timeout for each test in milliseconds. Defaults to 30 seconds.- *- * This is a base timeout for all tests. Each test can configure its own timeout with- * [test.setTimeout(timeout)](https://playwright.dev/docs/api/class-test#test-set-timeout). Each file or a group of- * tests can configure the timeout with- * [test.describe.configure([options])](https://playwright.dev/docs/api/class-test#test-describe-configure).+ * The unique index of the worker process that is running the test. When a worker is restarted, for example after a+ * failure, the new worker process gets a new unique `workerIndex`.*- * Use [testConfig.timeout](https://playwright.dev/docs/api/class-testconfig#test-config-timeout) to change this- * option for all projects.+ * Also available as `process.env.TEST_WORKER_INDEX`. Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel)+ * with Playwright Test.*/- timeout?: number;+ workerIndex: number;+}++/**+ * Information about an error thrown during test execution.+ */+export interface TestInfoError {+ /**+ * Error message. Set when [Error] (or its subclass) has been thrown.+ */+ message?: string;++ /**+ * Error stack. Set when [Error] (or its subclass) has been thrown.+ */+ stack?: string;++ /**+ * The value that was thrown. Set when anything except the [Error] (or its subclass) has been thrown.+ */+ value?: string;}/**diff --git a/utils/generate_types/index.js b/utils/generate_types/index.jsindex 06863d9c9f..34fa8fae56 100644--- a/utils/generate_types/index.js+++ b/utils/generate_types/index.js@@ -493,7 +493,14 @@ class TypesGenerator {const coreDocumentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'api'));const testDocumentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'test-api'), path.join(PROJECT_DIR, 'docs', 'src', 'api', 'params.md'));const reporterDocumentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'test-reporter-api'));- const assertionClasses = new Set(['GenericAssertions', 'LocatorAssertions', 'PageAssertions', 'APIResponseAssertions', 'SnapshotAssertions', 'PlaywrightAssertions']);+ const assertionClasses = new Set([+ 'APIResponseAssertions',+ 'GenericAssertions',+ 'LocatorAssertions',+ 'PageAssertions',+ 'PlaywrightAssertions',+ 'SnapshotAssertions',+ ]);/*** @param {boolean} includeExperimental@@ -503,7 +510,7 @@ class TypesGenerator {const documentation = coreDocumentation.clone();const generator = new TypesGenerator({documentation,- doNotGenerate: new Set([...assertionClasses]),+ doNotGenerate: assertionClasses,includeExperimental,});let types = await generator.generateTypes(path.join(__dirname, 'overrides.d.ts'));@@ -536,12 +543,7 @@ class TypesGenerator {documentation,doNotGenerate: new Set([...coreDocumentation.classesArray.map(cls => cls.name).filter(name => !assertionClasses.has(name)),- 'PlaywrightAssertions',- 'Test','Fixtures',- 'TestOptions',- 'TestConfig.use',- 'TestProject.use','GenericAssertions.any','GenericAssertions.anything','GenericAssertions.arrayContaining',@@ -549,26 +551,29 @@ class TypesGenerator {'GenericAssertions.objectContaining','GenericAssertions.stringContaining','GenericAssertions.stringMatching',+ 'PlaywrightAssertions',+ 'Test',+ 'TestOptions',]),overridesToDocsClassMapping: new Map([- ['TestType', 'Test'],- ['Config', 'TestConfig'],- ['Project', 'TestProject'],- ['PlaywrightWorkerOptions', 'TestOptions'],+ ['AsymmetricMatchers', 'GenericAssertions'],+ ['PlaywrightTestArgs', 'Fixtures'],['PlaywrightTestOptions', 'TestOptions'],['PlaywrightWorkerArgs', 'Fixtures'],- ['PlaywrightTestArgs', 'Fixtures'],- ['AsymmetricMatchers', 'GenericAssertions'],+ ['PlaywrightWorkerOptions', 'TestOptions'],+ ['TestType', 'Test'],]),ignoreMissing: new Set([+ 'Config',+ 'ExpectMatcherUtils',+ 'Matchers',+ 'PlaywrightWorkerArgs.playwright',+ 'PlaywrightWorkerOptions.defaultBrowserType',+ 'Project','SuiteFunction','TestFunction',- 'PlaywrightWorkerOptions.defaultBrowserType',- 'PlaywrightWorkerArgs.playwright',- 'Matchers',- 'ExpectMatcherUtils',]),- doNotExportClassNames: new Set([...assertionClasses, 'TestProject']),+ doNotExportClassNames: assertionClasses,includeExperimental,});return await generator.generateTypes(path.join(__dirname, 'overrides-test.d.ts'));@@ -590,8 +595,8 @@ class TypesGenerator {'FullResult','JSONReport','JSONReportError',- 'JSONReportSuite','JSONReportSpec',+ 'JSONReportSuite','JSONReportTest','JSONReportTestResult','JSONReportTestStep',diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.tsindex a10938a49a..2d1ba769e6 100644--- a/utils/generate_types/overrides-test.d.ts+++ b/utils/generate_types/overrides-test.d.ts@@ -31,24 +31,27 @@ export type ReporterDescription =type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;-export interface Project<TestArgs = {}, WorkerArgs = {}> extends TestProject {+interface TestProject<TestArgs = {}, WorkerArgs = {}> {use?: UseOptions<TestArgs, WorkerArgs>;}+export interface Project<TestArgs = {}, WorkerArgs = {}> extends TestProject<TestArgs, WorkerArgs> {+}+export interface ProjectInWorker<TestArgs = {}, WorkerArgs = {}> {use: UseOptions<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;}type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });-interface TestConfig {+interface TestConfig<TestArgs = {}, WorkerArgs = {}> {+ projects?: Project<TestArgs, WorkerArgs>[];reporter?: LiteralUnion<'list'|'dot'|'line'|'github'|'json'|'junit'|'null'|'html', string> | ReporterDescription[];+ use?: UseOptions<TestArgs, WorkerArgs>;webServer?: TestConfigWebServer | TestConfigWebServer[];}-export interface Config<TestArgs = {}, WorkerArgs = {}> extends TestConfig {- projects?: Project<TestArgs, WorkerArgs>[];- use?: UseOptions<TestArgs, WorkerArgs>;+export interface Config<TestArgs = {}, WorkerArgs = {}> extends TestConfig<TestArgs, WorkerArgs> {}export type Metadata = { [key: string]: any };