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
docs: document FullReporter API (#30186)
Yury Semikhatsky81bcf2a53b5d
diff --git a/docs/src/test-api/class-configinworker.md b/docs/src/test-api/class-configinworker.mdnew file mode 100644index 0000000000..5832dca885--- /dev/null+++ b/docs/src/test-api/class-configinworker.md@@ -0,0 +1,135 @@+# class: ConfigInWorker+* since: v1.10+* langs: js++Resolved configuration available via [`property: TestInfo.config`] and [`property: WorkerInfo.config`].++## property: ConfigInWorker.configFile+* since: v1.20+- type: ?<[string]>++Path to the configuration file (if any) used to run the tests.++## property: ConfigInWorker.forbidOnly+* since: v1.10+- type: <[boolean]>++See [`property: TestConfig.forbidOnly`].++## property: ConfigInWorker.fullyParallel+* since: v1.20+- type: <[boolean]>++See [`property: TestConfig.fullyParallel`].++## property: ConfigInWorker.globalSetup+* since: v1.10+- type: <[null]|[string]>++See [`property: TestConfig.globalSetup`].++## property: ConfigInWorker.globalTeardown+* since: v1.10+- type: <[null]|[string]>++See [`property: TestConfig.globalTeardown`].++## property: ConfigInWorker.globalTimeout+* since: v1.10+- type: <[int]>++See [`property: TestConfig.globalTimeout`].++## property: ConfigInWorker.grep+* since: v1.10+- type: <[RegExp]|[Array]<[RegExp]>>++See [`property: TestConfig.grep`].++## property: ConfigInWorker.grepInvert+* since: v1.10+- type: <[null]|[RegExp]|[Array]<[RegExp]>>++See [`property: TestConfig.grepInvert`].++## property: ConfigInWorker.maxFailures+* since: v1.10+- type: <[int]>++See [`property: TestConfig.maxFailures`].++## property: ConfigInWorker.metadata+* since: v1.10+- type: <[Metadata]>++See [`property: TestConfig.metadata`].++## property: ConfigInWorker.preserveOutput+* since: v1.10+- type: <[PreserveOutput]<"always"|"never"|"failures-only">>++See [`property: TestConfig.preserveOutput`].++## property: ConfigInWorker.projects+* since: v1.10+- type: <[Array]<[ProjectInWorker]>>++List of resolved projects.++## property: ConfigInWorker.quiet+* since: v1.10+- type: <[boolean]>++See [`property: TestConfig.quiet`].++## property: ConfigInWorker.reporter+* since: v1.10+- type: <[string]|[Array]<[Object]>|[BuiltInReporter]<"list"|"dot"|"line"|"github"|"json"|"junit"|"null"|"html">>+ - `0` <[string]> Reporter name or module or file path+ - `1` <[Object]> An object with reporter options if any++See [`property: TestConfig.reporter`].++## property: ConfigInWorker.reportSlowTests+* since: v1.10+- type: <[null]|[Object]>+ - `max` <[int]> The maximum number of slow test files to report. Defaults to `5`.+ - `threshold` <[float]> Test duration in milliseconds that is considered slow. Defaults to 15 seconds.++See [`property: TestConfig.reportSlowTests`].++## property: ConfigInWorker.rootDir+* since: v1.20+- type: <[string]>++## property: ConfigInWorker.shard+* since: v1.10+- type: <[null]|[Object]>+ - `total` <[int]> The total number of shards.+ - `current` <[int]> The index of the shard to execute, one-based.++See [`property: TestConfig.shard`].++## property: ConfigInWorker.updateSnapshots+* since: v1.10+- type: <[UpdateSnapshots]<"all"|"none"|"missing">>++See [`property: TestConfig.updateSnapshots`].++## property: ConfigInWorker.version+* since: v1.20+- type: <[string]>++Playwright version.++## property: ConfigInWorker.webServer+* since: v1.10+- type: <[null]|[Object]>++See [`property: TestConfig.webServer`].++## property: ConfigInWorker.workers+* since: v1.10+- type: <[int]>++See [`property: TestConfig.workers`].diff --git a/docs/src/test-api/class-projectinworker.md b/docs/src/test-api/class-projectinworker.mdnew file mode 100644index 0000000000..c8ede102ba--- /dev/null+++ b/docs/src/test-api/class-projectinworker.md@@ -0,0 +1,96 @@+# class: ProjectInWorker+* since: v1.10+* langs: js++Runtime representation of the test project configuration that can be accessed+in the tests via [`property: TestInfo.project`] and [`property: WorkerInfo.project`].++## property: ProjectInWorker.dependencies+* since: v1.31+- type: <[Array]<[string]>>++See [`property: TestProject.dependencies`].++## property: ProjectInWorker.grep+* since: v1.10+- type: <[RegExp]|[Array]<[RegExp]>>++See [`property: TestProject.grep`].++## property: ProjectInWorker.grepInvert+* since: v1.10+- type: <[null]|[RegExp]|[Array]<[RegExp]>>++See [`property: TestProject.grepInvert`].++## property: ProjectInWorker.metadata+* since: v1.10+- type: <[Metadata]>++See [`property: TestProject.metadata`].++## property: ProjectInWorker.name+* since: v1.10+- type: <[string]>++See [`property: TestProject.name`].++## property: ProjectInWorker.snapshotDir+* since: v1.10+- type: <[string]>++See [`property: TestProject.snapshotDir`].++## property: ProjectInWorker.outputDir+* since: v1.10+- type: <[string]>++See [`property: TestProject.outputDir`].++## property: ProjectInWorker.repeatEach+* since: v1.10+- type: <[int]>++See [`property: TestProject.repeatEach`].++## property: ProjectInWorker.retries+* since: v1.10+- type: <[int]>++See [`property: TestProject.retries`].++## property: ProjectInWorker.teardown+* since: v1.34+- type: ?<[string]>++See [`property: TestProject.teardown`].++## property: ProjectInWorker.testDir+* since: v1.10+- type: <[string]>++See [`property: TestProject.testDir`].++## property: ProjectInWorker.testIgnore+* since: v1.10+- type: <[string]|[RegExp]|[Array]<[string]|[RegExp]>>++See [`property: TestProject.testIgnore`].++## property: ProjectInWorker.testMatch+* since: v1.10+- type: <[string]|[RegExp]|[Array]<[string]|[RegExp]>>++See [`property: TestProject.testMatch`].++## property: ProjectInWorker.timeout+* since: v1.10+- type: <[int]>++See [`property: TestProject.timeout`].++## property: ProjectInWorker.use+* since: v1.10+- type: <[Fixtures]>++See [`property: TestProject.use`].diff --git a/docs/src/test-api/class-testinfo.md b/docs/src/test-api/class-testinfo.mdindex 97e9c16ebf..096fbfcc10 100644--- a/docs/src/test-api/class-testinfo.md+++ b/docs/src/test-api/class-testinfo.md@@ -106,7 +106,7 @@ Column number where the currently running test is declared.## property: TestInfo.config* since: v1.10-- type: <[TestConfig]>+- type: <[ConfigInWorker]>Processed configuration from the [configuration file](../test-configuration.md).@@ -279,7 +279,7 @@ Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about [paralleli## property: TestInfo.project* since: v1.10-- type: <[TestProject]>+- type: <[ProjectInWorker]>Processed project configuration from the [configuration file](../test-configuration.md).diff --git a/docs/src/test-api/class-workerinfo.md b/docs/src/test-api/class-workerinfo.mdindex ac8927bfc9..e7ae892190 100644--- a/docs/src/test-api/class-workerinfo.md+++ b/docs/src/test-api/class-workerinfo.md@@ -6,7 +6,7 @@## property: WorkerInfo.config* since: v1.10-- type: <[TestConfig]>+- type: <[ConfigInWorker]>Processed configuration from the [configuration file](../test-configuration.md).@@ -22,7 +22,7 @@ Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about [paralleli## property: WorkerInfo.project* since: v1.10-- type: <[TestProject]>+- type: <[ProjectInWorker]>Processed project configuration from the [configuration file](../test-configuration.md).diff --git a/docs/src/test-reporter-api/class-fullconfig.md b/docs/src/test-reporter-api/class-fullconfig.mdnew file mode 100644index 0000000000..ce4318560f--- /dev/null+++ b/docs/src/test-reporter-api/class-fullconfig.md@@ -0,0 +1,135 @@+# class: FullConfig+* since: v1.10+* langs: js++Resolved configuration passed to [`method: Reporter.onBegin`].++## property: FullConfig.configFile+* since: v1.20+- type: ?<[string]>++Path to the configuration file (if any) used to run the tests.++## property: FullConfig.forbidOnly+* since: v1.10+- type: <[boolean]>++See [`property: TestConfig.forbidOnly`].++## property: FullConfig.fullyParallel+* since: v1.20+- type: <[boolean]>++See [`property: TestConfig.fullyParallel`].++## property: FullConfig.globalSetup+* since: v1.10+- type: <[null]|[string]>++See [`property: TestConfig.globalSetup`].++## property: FullConfig.globalTeardown+* since: v1.10+- type: <[null]|[string]>++See [`property: TestConfig.globalTeardown`].++## property: FullConfig.globalTimeout+* since: v1.10+- type: <[int]>++See [`property: TestConfig.globalTimeout`].++## property: FullConfig.grep+* since: v1.10+- type: <[RegExp]|[Array]<[RegExp]>>++See [`property: TestConfig.grep`].++## property: FullConfig.grepInvert+* since: v1.10+- type: <[null]|[RegExp]|[Array]<[RegExp]>>++See [`property: TestConfig.grepInvert`].++## property: FullConfig.maxFailures+* since: v1.10+- type: <[int]>++See [`property: TestConfig.maxFailures`].++## property: FullConfig.metadata+* since: v1.10+- type: <[Metadata]>++See [`property: TestConfig.metadata`].++## property: FullConfig.preserveOutput+* since: v1.10+- type: <[PreserveOutput]<"always"|"never"|"failures-only">>++See [`property: TestConfig.preserveOutput`].++## property: FullConfig.projects+* since: v1.10+- type: <[Array]<[FullProject]>>++List of resolved projects.++## property: FullConfig.quiet+* since: v1.10+- type: <[boolean]>++See [`property: TestConfig.quiet`].++## property: FullConfig.reporter+* since: v1.10+- type: <[string]|[Array]<[Object]>|[BuiltInReporter]<"list"|"dot"|"line"|"github"|"json"|"junit"|"null"|"html">>+ - `0` <[string]> Reporter name or module or file path+ - `1` <[Object]> An object with reporter options if any++See [`property: TestConfig.reporter`].++## property: FullConfig.reportSlowTests+* since: v1.10+- type: <[null]|[Object]>+ - `max` <[int]> The maximum number of slow test files to report. Defaults to `5`.+ - `threshold` <[float]> Test duration in milliseconds that is considered slow. Defaults to 15 seconds.++See [`property: TestConfig.reportSlowTests`].++## property: FullConfig.rootDir+* since: v1.20+- type: <[string]>++## property: FullConfig.shard+* since: v1.10+- type: <[null]|[Object]>+ - `total` <[int]> The total number of shards.+ - `current` <[int]> The index of the shard to execute, one-based.++See [`property: TestConfig.shard`].++## property: FullConfig.updateSnapshots+* since: v1.10+- type: <[UpdateSnapshots]<"all"|"none"|"missing">>++See [`property: TestConfig.updateSnapshots`].++## property: FullConfig.version+* since: v1.20+- type: <[string]>++Playwright version.++## property: FullConfig.webServer+* since: v1.10+- type: <[null]|[Object]>++See [`property: TestConfig.webServer`].++## property: FullConfig.workers+* since: v1.10+- type: <[int]>++See [`property: TestConfig.workers`].diff --git a/docs/src/test-reporter-api/class-fullproject.md b/docs/src/test-reporter-api/class-fullproject.mdnew file mode 100644index 0000000000..9a744115df--- /dev/null+++ b/docs/src/test-reporter-api/class-fullproject.md@@ -0,0 +1,98 @@+# class: FullProject+* since: v1.10+* langs: js++Runtime representation of the test project configuration that is passed+to [Reporter]. It exposes some of the resolved fields declared in+[TestProject]. You can get [FullProject] instance from [`property: FullConfig.projects`]+or [`method: Suite.project`].++## property: FullProject.dependencies+* since: v1.31+- type: <[Array]<[string]>>++See [`property: TestProject.dependencies`].++## property: FullProject.grep+* since: v1.10+- type: <[RegExp]|[Array]<[RegExp]>>++See [`property: TestProject.grep`].++## property: FullProject.grepInvert+* since: v1.10+- type: <[null]|[RegExp]|[Array]<[RegExp]>>++See [`property: TestProject.grepInvert`].++## property: FullProject.metadata+* since: v1.10+- type: <[Metadata]>++See [`property: TestProject.metadata`].++## property: FullProject.name+* since: v1.10+- type: <[string]>++See [`property: TestProject.name`].++## property: FullProject.snapshotDir+* since: v1.10+- type: <[string]>++See [`property: TestProject.snapshotDir`].++## property: FullProject.outputDir+* since: v1.10+- type: <[string]>++See [`property: TestProject.outputDir`].++## property: FullProject.repeatEach+* since: v1.10+- type: <[int]>++See [`property: TestProject.repeatEach`].++## property: FullProject.retries+* since: v1.10+- type: <[int]>++See [`property: TestProject.retries`].++## property: FullProject.teardown+* since: v1.34+- type: ?<[string]>++See [`property: TestProject.teardown`].++## property: FullProject.testDir+* since: v1.10+- type: <[string]>++See [`property: TestProject.testDir`].++## property: FullProject.testIgnore+* since: v1.10+- type: <[string]|[RegExp]|[Array]<[string]|[RegExp]>>++See [`property: TestProject.testIgnore`].++## property: FullProject.testMatch+* since: v1.10+- type: <[string]|[RegExp]|[Array]<[string]|[RegExp]>>++See [`property: TestProject.testMatch`].++## property: FullProject.timeout+* since: v1.10+- type: <[int]>++See [`property: TestProject.timeout`].++## property: FullProject.use+* since: v1.10+- type: <[Fixtures]>++See [`property: TestProject.use`].diff --git a/docs/src/test-reporter-api/class-reporter.md b/docs/src/test-reporter-api/class-reporter.mdindex ead4002171..7b3d394cc8 100644--- a/docs/src/test-reporter-api/class-reporter.md+++ b/docs/src/test-reporter-api/class-reporter.md@@ -103,7 +103,7 @@ Called once before running tests. All tests have been already discovered and put### param: Reporter.onBegin.config* since: v1.10-- `config` <[TestConfig]>+- `config` <[FullConfig]>Resolved configuration.diff --git a/docs/src/test-reporter-api/class-suite.md b/docs/src/test-reporter-api/class-suite.mdindex fc6b3e0aa9..80642def9e 100644--- a/docs/src/test-reporter-api/class-suite.md+++ b/docs/src/test-reporter-api/class-suite.md@@ -4,7 +4,7 @@`Suite` is a group of tests. All tests in Playwright Test form the following hierarchy:-* Root suite has a child suite for each [TestProject].+* Root suite has a child suite for each [FullProject].* Project suite #1. Has a child suite for each test file in the project.* File suite #1* [TestCase] #1@@ -46,7 +46,7 @@ Parent suite, missing for the root suite.## method: Suite.project* since: v1.10-- returns: ?<[TestProject]>+- returns: <[FullProject]|[undefined]>Configuration of the project this suite belongs to, or [void] for the root suite.diff --git a/packages/playwright-ct-core/src/cliOverrides.ts b/packages/playwright-ct-core/src/cliOverrides.tsindex 3ebcd09cbc..aaa456427c 100644--- a/packages/playwright-ct-core/src/cliOverrides.ts+++ b/packages/playwright-ct-core/src/cliOverrides.ts@@ -19,8 +19,7 @@ import { removeFolder } from 'playwright/lib/program';import { affectedTestFiles, cacheDir } from 'playwright/lib/transform/compilationCache';import { buildBundle } from './vitePlugin';import { resolveDirs } from './viteUtils';-import type { Suite } from 'playwright/lib/common/test';-import type { FullConfig } from 'playwright/test';+import type { FullConfig, Suite } from 'playwright/types/testReporter';export async function clearCacheCommand(config: FullConfig, configDir: string) {const dirs = await resolveDirs(configDir, config);diff --git a/packages/playwright-ct-core/src/vitePlugin.ts b/packages/playwright-ct-core/src/vitePlugin.tsindex cc26fdc807..26964e079b 100644--- a/packages/playwright-ct-core/src/vitePlugin.ts+++ b/packages/playwright-ct-core/src/vitePlugin.ts@@ -22,8 +22,7 @@ import { assert, calculateSha1, getPlaywrightVersion, isURLAvailable } from 'plaimport { debug } from 'playwright-core/lib/utilsBundle';import { internalDependenciesForTestFile, setExternalDependencies } from 'playwright/lib/transform/compilationCache';import { stoppable } from 'playwright/lib/utilsBundle';-import type { FullConfig } from 'playwright/test';-import type { Suite } from 'playwright/types/testReporter';+import type { FullConfig, Suite } from 'playwright/types/testReporter';import type { PluginContext } from 'rollup';import type { Plugin, ResolveFn, ResolvedConfig } from 'vite';import type { TestRunnerPlugin } from '../../playwright/src/plugins';diff --git a/packages/playwright-ct-core/src/viteUtils.ts b/packages/playwright-ct-core/src/viteUtils.tsindex 00da627432..505301c48e 100644--- a/packages/playwright-ct-core/src/viteUtils.ts+++ b/packages/playwright-ct-core/src/viteUtils.ts@@ -18,7 +18,8 @@ import fs from 'fs';import path from 'path';import { debug } from 'playwright-core/lib/utilsBundle';import { getUserData } from 'playwright/lib/transform/compilationCache';-import type { PlaywrightTestConfig as BasePlaywrightTestConfig, FullConfig } from 'playwright/test';+import type { PlaywrightTestConfig as BasePlaywrightTestConfig } from 'playwright/types/test';+import type { FullConfig } from 'playwright/types/testReporter';import type { InlineConfig, Plugin, TransformResult, UserConfig } from 'vite';import type { ImportInfo } from './tsxTransform';import { resolveHook } from 'playwright/lib/transform/transform';diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.tsindex cfe294a75c..9b8be8e730 100644--- a/packages/playwright/src/common/config.ts+++ b/packages/playwright/src/common/config.ts@@ -23,7 +23,7 @@ import type { TestRunnerPluginRegistration } from '../plugins';import { getPackageJsonPath, mergeObjects } from '../util';import type { Matcher } from '../util';import type { ConfigCLIOverrides } from './ipc';-import type { FullConfig, FullProject } from '../../types/test';+import type { FullConfig, FullProject } from '../../types/testReporter';import { setTransformConfig } from '../transform/transform';export type ConfigLocation = {@@ -46,7 +46,7 @@ export class FullConfigInternal {readonly configCLIOverrides: ConfigCLIOverrides;readonly ignoreSnapshots: boolean;readonly preserveOutputDir: boolean;- readonly webServers: Exclude<FullConfig['webServer'], null>[];+ readonly webServers: NonNullable<FullConfig['webServer']>[];readonly plugins: TestRunnerPluginRegistration[];readonly projects: FullProjectInternal[] = [];cliArgs: string[] = [];@@ -182,7 +182,7 @@ export class FullProjectInternal {// project is top-level vs dependency. See collectProjectsAndTestFiles in loadUtils.repeatEach: takeFirst(projectConfig.repeatEach, config.repeatEach, 1),retries: takeFirst(configCLIOverrides.retries, projectConfig.retries, config.retries, 0),- metadata: takeFirst(projectConfig.metadata, config.metadata, undefined),+ metadata: takeFirst(projectConfig.metadata, config.metadata, {}),name: takeFirst(projectConfig.name, config.name, ''),testDir,snapshotDir: takeFirst(pathResolve(configDir, projectConfig.snapshotDir), pathResolve(configDir, config.snapshotDir), testDir),diff --git a/packages/playwright/src/common/test.ts b/packages/playwright/src/common/test.tsindex 50f547b6ee..5f22f8fe3b 100644--- a/packages/playwright/src/common/test.ts+++ b/packages/playwright/src/common/test.ts@@ -19,8 +19,7 @@ import type * as reporterTypes from '../../types/testReporter';import type { TestTypeImpl } from './testType';import { rootTestType } from './testType';import type { Annotation, FixturesWithLocation, FullProjectInternal } from './config';-import type { FullProject } from '../../types/test';-import type { Location } from '../../types/testReporter';+import type { Location, FullProject } from '../../types/testReporter';class Base {title: string;diff --git a/packages/playwright/src/isomorphic/teleReceiver.ts b/packages/playwright/src/isomorphic/teleReceiver.tsindex 879d37e010..5b23b4a7b3 100644--- a/packages/playwright/src/isomorphic/teleReceiver.ts+++ b/packages/playwright/src/isomorphic/teleReceiver.ts@@ -15,7 +15,7 @@*/import type { Annotation } from '../common/config';-import type { FullProject, Metadata } from '../../types/test';+import type { Metadata } from '../../types/test';import type * as reporterTypes from '../../types/testReporter';import type { ReporterV2 } from '../reporters/reporterV2';@@ -590,7 +590,7 @@ class TeleTestResult implements reporterTypes.TestResult {}}-export type TeleFullProject = FullProject;+export type TeleFullProject = reporterTypes.FullProject;export const baseFullConfig: reporterTypes.FullConfig = {forbidOnly: false,diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.tsindex 3e0dab8b95..cb3d352f40 100644--- a/packages/playwright/src/worker/testInfo.ts+++ b/packages/playwright/src/worker/testInfo.ts@@ -17,7 +17,7 @@import fs from 'fs';import path from 'path';import { captureRawStack, monotonicTime, zones, sanitizeForFilePath, stringifyStackFrames } from 'playwright-core/lib/utils';-import type { TestInfoError, TestInfo, TestStatus, FullProject, FullConfig } from '../../types/test';+import type { TestInfoError, TestInfo, TestStatus, ProjectInWorker, ConfigInWorker } from '../../types/test';import type { AttachmentPayload, StepBeginPayload, StepEndPayload, WorkerInitParams } from '../common/ipc';import type { TestCase } from '../common/test';import { TimeoutManager, TimeoutManagerError, kMaxDeadline } from './timeoutManager';@@ -81,8 +81,8 @@ export class TestInfoImpl implements TestInfo {readonly retry: number;readonly workerIndex: number;readonly parallelIndex: number;- readonly project: FullProject;- readonly config: FullConfig;+ readonly project: ProjectInWorker;+ readonly config: ConfigInWorker;readonly title: string;readonly titlePath: string[];readonly file: string;diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.tsindex 8bdfe088c8..5d9911f07c 100644--- a/packages/playwright/types/test.d.ts+++ b/packages/playwright/types/test.d.ts@@ -30,7 +30,7 @@ export type ReporterDescription =['null'] |[string] | [string, any];-type UseOptions<TestArgs, WorkerArgs> = { [K in keyof WorkerArgs]?: WorkerArgs[K] } & { [K in keyof TestArgs]?: TestArgs[K] };+type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;/*** Playwright Test supports running multiple test projects at the same time. This is useful for running tests in@@ -111,88 +111,120 @@ export interface Project<TestArgs = {}, WorkerArgs = {}> extends TestProject {}/**- * 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.+ * Runtime representation of the test project configuration that can be accessed in the tests via+ * [testInfo.project](https://playwright.dev/docs/api/class-testinfo#test-info-project) and+ * [workerInfo.project](https://playwright.dev/docs/api/class-workerinfo#worker-info-project).+ */+export interface ProjectInWorker<TestArgs = {}, WorkerArgs = {}> {+ /**+ * See [testProject.use](https://playwright.dev/docs/api/class-testproject#test-project-use).+ */+ use: UseOptions<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;+ /**+ * See [testProject.dependencies](https://playwright.dev/docs/api/class-testproject#test-project-dependencies).+ */+ dependencies: Array<string>;++ /**+ * See [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep).+ */+ grep: RegExp|Array<RegExp>;++ /**+ * See [testProject.grepInvert](https://playwright.dev/docs/api/class-testproject#test-project-grep-invert).+ */+ grepInvert: null|RegExp|Array<RegExp>;++ /**+ * See [testProject.metadata](https://playwright.dev/docs/api/class-testproject#test-project-metadata).+ */+ metadata: Metadata;++ /**+ * See [testProject.name](https://playwright.dev/docs/api/class-testproject#test-project-name).+ */+ name: string;++ /**+ * See [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir).+ */+ outputDir: string;++ /**+ * See [testProject.repeatEach](https://playwright.dev/docs/api/class-testproject#test-project-repeat-each).+ */+ repeatEach: number;++ /**+ * See [testProject.retries](https://playwright.dev/docs/api/class-testproject#test-project-retries).+ */+ retries: number;++ /**+ * See [testProject.snapshotDir](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-dir).+ */+ snapshotDir: string;++ /**+ * See [testProject.teardown](https://playwright.dev/docs/api/class-testproject#test-project-teardown).+ */+ teardown?: string;++ /**+ * See [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir).+ */+ testDir: string;++ /**+ * See [testProject.testIgnore](https://playwright.dev/docs/api/class-testproject#test-project-test-ignore).+ */+ testIgnore: string|RegExp|Array<string|RegExp>;++ /**+ * See [testProject.testMatch](https://playwright.dev/docs/api/class-testproject#test-project-test-match).+ */+ testMatch: string|RegExp|Array<string|RegExp>;++ /**+ * See [testProject.timeout](https://playwright.dev/docs/api/class-testproject#test-project-timeout).+ */+ timeout: number;+}++type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });++/**+ * 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).*- * Here is an example configuration that runs every test in Chromium, Firefox and WebKit, both Desktop and Mobile- * versions.+ * 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, devices } from '@playwright/test';+ * import { defineConfig } 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'],- * },- * ],+ * globalTimeout: 600000,+ * reporter: 'list',+ * testDir: './tests',* });* ```**/-export interface FullProject<TestArgs = {}, WorkerArgs = {}> {- /**- * 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 | RegExp[];+interface TestConfig {/**- * 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.+ * 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'`.*- * `grepInvert` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests).- */- grepInvert: RegExp | RegExp[] | null;- /**- * 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;- /**- * 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.+ * You can pass options to the reporter in a tuple like `['json', { outputFile: './report.json' }]`.*- * Using dependencies allows global setup to produce traces and other artifacts, see the setup steps in the test- * report, etc.+ * Learn more in the [reporters guide](https://playwright.dev/docs/test-reporters).** **Usage***@@ -201,348 +233,64 @@ export interface FullProject<TestArgs = {}, WorkerArgs = {}> {* 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'],- * },- * ],+ * reporter: 'line',* });* ```**/- dependencies: string[];+ reporter?: LiteralUnion<'list'|'dot'|'line'|'github'|'json'|'junit'|'null'|'html', string> | ReporterDescription[];/**- * 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).+ * Launch a development web server (or multiple) during the tests.*- * 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).+ * **Details***- * 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;- /**- * The output directory for files created during test execution. Defaults to `<package.json-directory>/test-results`.+ * 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.*- * 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).+ * 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.*- * 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.+ * The `port` (but not the `url`) gets passed over to Playwright as a+ * [testOptions.baseURL](https://playwright.dev/docs/api/class-testoptions#test-options-base-url). 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).*- * ```js- * import { test, expect } from '@playwright/test';- * import fs from 'fs';+ * **NOTE** It is also recommended to specify+ * [testOptions.baseURL](https://playwright.dev/docs/api/class-testoptions#test-options-base-url) in the config, so+ * that tests could use relative urls.*- * test('example test', async ({}, testInfo) => {- * const file = testInfo.outputPath('temporary-file.txt');- * await fs.promises.writeFile(file, 'Put some data to the file', 'utf8');+ * **Usage**+ *+ * ```js+ * // playwright.config.ts+ * import { defineConfig } from '@playwright/test';+ * export default defineConfig({+ * webServer: {+ * command: 'npm run start',+ * url: 'http://127.0.0.1:3000',+ * timeout: 120 * 1000,+ * reuseExistingServer: !process.env.CI,+ * },+ * use: {+ * baseURL: 'http://localhost:3000/',+ * },* });* ```*- * 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).+ * Now you can use a relative path when navigating the page:*- * 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.+ * ```js+ * // test.spec.ts+ * import { test } from '@playwright/test';*- * Use [testConfig.retries](https://playwright.dev/docs/api/class-testconfig#test-config-retries) to change this- * option for all projects.- */- retries: 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.+ * test('test', async ({ page }) => {+ * // This will result in http://localhost:3000/foo+ * await page.goto('/foo');+ * });+ * ```*- * 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 | (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 | (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;- /**- * Options for all tests in this project, 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}.- *- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- *- * export default defineConfig({- * projects: [- * {- * name: 'Chromium',- * use: {- * browserName: 'chromium',- * },- * },- * ],- * });- * ```- *- * Use [testConfig.use](https://playwright.dev/docs/api/class-testconfig#test-config-use) to change this option for- * all projects.- */- use: UseOptions<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;-}--type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });--/**- * 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',- * });- * ```- *- */-interface TestConfig {- /**- * 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' }]`.- *- * Learn more in the [reporters guide](https://playwright.dev/docs/test-reporters).- *- * **Usage**- *- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- *- * export default defineConfig({- * reporter: 'line',- * });- * ```- *- */- reporter?: LiteralUnion<'list'|'dot'|'line'|'github'|'json'|'junit'|'null'|'html', string> | ReporterDescription[];- /**- * Launch a development web server (or multiple) during the tests.- *- * **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](https://playwright.dev/docs/api/class-testoptions#test-options-base-url). 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](https://playwright.dev/docs/api/class-testoptions#test-options-base-url) in the config, so- * that tests could use relative urls.- *- * **Usage**- *- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- * export default defineConfig({- * webServer: {- * command: 'npm run start',- * url: 'http://127.0.0.1:3000',- * timeout: 120 * 1000,- * reuseExistingServer: !process.env.CI,- * },- * use: {- * baseURL: 'http://localhost:3000/',- * },- * });- * ```- *- * Now you can use a relative path when navigating the page:- *- * ```js- * // 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:+ * Multiple web servers (or background processes) can be launched:** ```js* // playwright.config.ts@@ -1445,1435 +1193,640 @@ export interface Config<TestArgs = {}, WorkerArgs = {}> extends TestConfig {export type Metadata = { [key: string]: any };/**- * 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',- * });- * ```- *+ * Resolved configuration available via+ * [testInfo.config](https://playwright.dev/docs/api/class-testinfo#test-info-config) and+ * [workerInfo.config](https://playwright.dev/docs/api/class-workerinfo#worker-info-config).*/-export interface FullConfig<TestArgs = {}, WorkerArgs = {}> {+export interface ConfigInWorker<TestArgs = {}, WorkerArgs = {}> {/**- * Whether to exit with an error if any tests or groups are marked as- * [test.only(title[, details, body])](https://playwright.dev/docs/api/class-test#test-only) or- * [test.describe.only([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe-only).- * Useful on CI.+ * List of resolved projects.+ */+ projects: ProjectInWorker<TestArgs, WorkerArgs>[];+ /**+ * See [testConfig.reporter](https://playwright.dev/docs/api/class-testconfig#test-config-reporter).+ */+ reporter: ReporterDescription[];+ /**+ * See [testConfig.webServer](https://playwright.dev/docs/api/class-testconfig#test-config-web-server).+ */+ webServer: TestConfigWebServer | null;+ /**+ * Path to the configuration file (if any) used to run the tests.+ */+ configFile?: string;++ /**+ * See [testConfig.forbidOnly](https://playwright.dev/docs/api/class-testconfig#test-config-forbid-only).+ */+ forbidOnly: boolean;++ /**+ * See [testConfig.fullyParallel](https://playwright.dev/docs/api/class-testconfig#test-config-fully-parallel).+ */+ fullyParallel: boolean;++ /**+ * See [testConfig.globalSetup](https://playwright.dev/docs/api/class-testconfig#test-config-global-setup).+ */+ globalSetup: null|string;++ /**+ * See [testConfig.globalTeardown](https://playwright.dev/docs/api/class-testconfig#test-config-global-teardown).+ */+ globalTeardown: null|string;++ /**+ * See [testConfig.globalTimeout](https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout).+ */+ globalTimeout: number;++ /**+ * See [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep).+ */+ grep: RegExp|Array<RegExp>;++ /**+ * See [testConfig.grepInvert](https://playwright.dev/docs/api/class-testconfig#test-config-grep-invert).+ */+ grepInvert: null|RegExp|Array<RegExp>;++ /**+ * See [testConfig.maxFailures](https://playwright.dev/docs/api/class-testconfig#test-config-max-failures).+ */+ maxFailures: number;++ /**+ * See [testConfig.metadata](https://playwright.dev/docs/api/class-testconfig#test-config-metadata).+ */+ metadata: Metadata;++ /**+ * See [testConfig.preserveOutput](https://playwright.dev/docs/api/class-testconfig#test-config-preserve-output).+ */+ preserveOutput: "always"|"never"|"failures-only";++ /**+ * See [testConfig.quiet](https://playwright.dev/docs/api/class-testconfig#test-config-quiet).+ */+ quiet: boolean;++ /**+ * See [testConfig.reportSlowTests](https://playwright.dev/docs/api/class-testconfig#test-config-report-slow-tests).+ */+ reportSlowTests: null|{+ /**+ * The maximum number of slow test files to report. Defaults to `5`.+ */+ max: number;++ /**+ * Test duration in milliseconds that is considered slow. Defaults to 15 seconds.+ */+ threshold: number;+ };++ rootDir: string;++ /**+ * See [testConfig.shard](https://playwright.dev/docs/api/class-testconfig#test-config-shard).+ */+ shard: null|{+ /**+ * The total number of shards.+ */+ total: number;++ /**+ * The index of the shard to execute, one-based.+ */+ current: number;+ };++ /**+ * See [testConfig.updateSnapshots](https://playwright.dev/docs/api/class-testconfig#test-config-update-snapshots).+ */+ updateSnapshots: "all"|"none"|"missing";++ /**+ * Playwright version.+ */+ version: string;++ /**+ * See [testConfig.workers](https://playwright.dev/docs/api/class-testconfig#test-config-workers).+ */+ workers: number;+}++export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped' | 'interrupted';++type TestDetailsAnnotation = {+ type: string;+ description?: string;+};++export type TestDetails = {+ tag?: string | string[];+ annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];+}++interface SuiteFunction {+ /**+ * Declares a group of tests.+ * - `test.describe(title, callback)`+ * - `test.describe(callback)`+ * - `test.describe(title, details, callback)`** **Usage***+ * You can declare a group of tests with a title. The title will be visible in the test report as a part of each+ * test's title.+ ** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * test.describe('two tests', () => {+ * test('one', async ({ page }) => {+ * // ...+ * });*- * export default defineConfig({- * forbidOnly: !!process.env.CI,+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- forbidOnly: boolean;- /**- * 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.+ * **Anonymous group***- * **Usage**+ * You can also declare a test group without a title. This is convenient to give a group of tests a common option with+ * [test.use(options)](https://playwright.dev/docs/api/class-test#test-use).** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * test.describe(() => {+ * test.use({ colorScheme: 'dark' });*- * export default defineConfig({- * fullyParallel: true,+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- fullyParallel: boolean;- /**- * 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 [`TestConfig`] argument.- *- * Learn more about [global setup and teardown](https://playwright.dev/docs/test-global-setup-teardown).+ * **Tags***- * **Usage**+ * You can tag all tests in a group by providing additional details. Note that each tag must start with `@` symbol.** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * globalSetup: './global-setup',+ * test.describe('two tagged tests', {+ * tag: '@smoke',+ * }, () => {+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- globalSetup: string | null;- /**- * 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](https://playwright.dev/docs/api/class-testconfig#test-config-global-setup).+ * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).*- * Learn more about [global setup and teardown](https://playwright.dev/docs/test-global-setup-teardown).+ * **Annotations***- * **Usage**+ * You can annotate all tests in a group by providing additional details.** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * globalTeardown: './global-teardown',+ * test.describe('two annotated tests', {+ * annotation: {+ * type: 'issue',+ * description: 'https://github.com/microsoft/playwright/issues/23180',+ * },+ * }, () => {+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*+ * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).+ * @param title Group title.+ * @param details Additional details for all tests in the group.+ * @param callback A callback that is run immediately when calling+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe). Any tests+ * declared in this callback will belong to the group.*/- globalTeardown: string | null;+ (title: string, callback: () => void): void;/**- * 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](https://playwright.dev/docs/test-timeouts).+ * Declares a group of tests.+ * - `test.describe(title, callback)`+ * - `test.describe(callback)`+ * - `test.describe(title, details, callback)`** **Usage***+ * You can declare a group of tests with a title. The title will be visible in the test report as a part of each+ * test's title.+ ** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * test.describe('two tests', () => {+ * test('one', async ({ page }) => {+ * // ...+ * });*- * export default defineConfig({- * globalTimeout: process.env.CI ? 60 * 60 * 1000 : undefined,+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- globalTimeout: 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 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`.+ * **Anonymous group***- * `grep` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests).- *- * **Usage**+ * You can also declare a test group without a title. This is convenient to give a group of tests a common option with+ * [test.use(options)](https://playwright.dev/docs/api/class-test#test-use).** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * test.describe(() => {+ * test.use({ colorScheme: 'dark' });*- * export default defineConfig({- * grep: /smoke/,+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- grep: RegExp | RegExp[];- /**- * Filter to only run tests with a title **not** matching one of the patterns. This is the opposite of- * [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep). Also available 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).+ * **Tags***- * **Usage**+ * You can tag all tests in a group by providing additional details. Note that each tag must start with `@` symbol.** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * grepInvert: /manual/,+ * test.describe('two tagged tests', {+ * tag: '@smoke',+ * }, () => {+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- grepInvert: RegExp | RegExp[] | null;- /**- * 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.+ * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).*- * Also available in the [command line](https://playwright.dev/docs/test-cli) with the `--max-failures` and `-x` options.+ * **Annotations***- * **Usage**+ * You can annotate all tests in a group by providing additional details.** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * maxFailures: process.env.CI ? 1 : 0,+ * test.describe('two annotated tests', {+ * annotation: {+ * type: 'issue',+ * description: 'https://github.com/microsoft/playwright/issues/23180',+ * },+ * }, () => {+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*+ * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).+ * @param title Group title.+ * @param details Additional details for all tests in the group.+ * @param callback A callback that is run immediately when calling+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe). Any tests+ * declared in this callback will belong to the group.*/- maxFailures: number;+ (callback: () => void): void;/**- * Metadata that will be put directly to the test report serialized as JSON.+ * Declares a group of tests.+ * - `test.describe(title, callback)`+ * - `test.describe(callback)`+ * - `test.describe(title, details, callback)`** **Usage***+ * You can declare a group of tests with a title. The title will be visible in the test report as a part of each+ * test's title.+ ** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * test.describe('two tests', () => {+ * test('one', async ({ page }) => {+ * // ...+ * });*- * export default defineConfig({- * metadata: 'acceptance tests',+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- metadata: Metadata;- version: string;- /**- * Whether to preserve test output in the- * [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir). 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.+ * **Anonymous group***- * **Usage**+ * You can also declare a test group without a title. This is convenient to give a group of tests a common option with+ * [test.use(options)](https://playwright.dev/docs/api/class-test#test-use).** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * test.describe(() => {+ * test.use({ colorScheme: 'dark' });*- * export default defineConfig({- * preserveOutput: 'always',+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- preserveOutput: 'always' | 'never' | 'failures-only';- /**- * Playwright Test supports running multiple test projects at the same time. See {@link TestProject} for more- * information.+ * **Tags***- * **Usage**+ * You can tag all tests in a group by providing additional details. Note that each tag must start with `@` symbol.** ```js- * // playwright.config.ts- * import { defineConfig, devices } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * projects: [- * { name: 'chromium', use: devices['Desktop Chrome'] }- * ]+ * test.describe('two tagged tests', {+ * tag: '@smoke',+ * }, () => {+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*- */- projects: FullProject<TestArgs, WorkerArgs>[];- /**- * 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' }]`.+ * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).*- * Learn more in the [reporters guide](https://playwright.dev/docs/test-reporters).+ * **Annotations***- * **Usage**+ * You can annotate all tests in a group by providing additional details.** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * reporter: 'line',+ * test.describe('two annotated tests', {+ * annotation: {+ * type: 'issue',+ * description: 'https://github.com/microsoft/playwright/issues/23180',+ * },+ * }, () => {+ * test('one', async ({ page }) => {+ * // ...+ * });+ *+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*+ * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).+ * @param title Group title.+ * @param details Additional details for all tests in the group.+ * @param callback A callback that is run immediately when calling+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe). Any tests+ * declared in this callback will belong to the group.*/- reporter: ReporterDescription[];+ (title: string, details: TestDetails, callback: () => void): void;+}++interface TestFunction<TestArgs> {/**- * Whether to report slow test files. Pass `null` to disable this feature.+ * Declares a test.+ * - `test(title, body)`+ * - `test(title, details, body)`** **Usage**** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * reportSlowTests: null,+ * test('basic test', async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * // ...* });* ```*- * **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.- */- reportSlowTests: { max: number, threshold: number } | null;- rootDir: string;- /**- * Whether to suppress stdio and stderr output from the tests.+ * **Tags***- * **Usage**+ * You can tag tests by providing additional test details. Alternatively, you can include tags in the test title. Note+ * that each tag must start with `@` symbol.** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * quiet: !!process.env.CI,+ * test('basic test', {+ * tag: '@smoke',+ * }, async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * // ...+ * });+ *+ * test('another test @smoke', async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * // ...* });* ```*- */- quiet: boolean;- /**- * Shard tests and execute only the selected shard. Specify in the one-based form like `{ total: 5, current: 2 }`.+ * Test tags are displayed in the test report, and are available to a custom reporter via `TestCase.tags` property.*- * Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test.+ * You can also filter tests by their tags during test execution:+ * - in the [command line](https://playwright.dev/docs/test-cli#reference);+ * - in the config with [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep) and+ * [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep);*- * **Usage**+ * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).+ *+ * **Annotations**+ *+ * You can annotate tests by providing additional test details.** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * shard: { total: 10, current: 3 },+ * test('basic test', {+ * annotation: {+ * type: 'issue',+ * description: 'https://github.com/microsoft/playwright/issues/23180',+ * },+ * }, async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * // ...* });* ```*- */- shard: { total: number, current: number } | null;- /**- * 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 that did not match. Matching snapshots will not be- * updated.- * - `'none'` - No snapshots are updated.- * - `'missing'` - Missing snapshots are created, for example when authoring a new test and running it for the first- * time. This is the default.- *- * Learn more about [snapshots](https://playwright.dev/docs/test-snapshots).- *- * **Usage**- *- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * Test annotations are displayed in the test report, and are available to a custom reporter via+ * `TestCase.annotations` property.*- * export default defineConfig({- * updateSnapshots: 'missing',- * });- * ```+ * You can also add annotations during runtime by manipulating+ * [testInfo.annotations](https://playwright.dev/docs/api/class-testinfo#test-info-annotations).*+ * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).+ * @param title Test title.+ * @param details Additional test details.+ * @param body Test body that takes one or two arguments: an object with fixtures and optional {@link TestInfo}.*/- updateSnapshots: 'all' | 'none' | 'missing';+ (title: string, body: (args: TestArgs, testInfo: TestInfo) => Promise<void> | void): void;/**- * 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](https://playwright.dev/docs/test-parallel) with Playwright Test.+ * Declares a test.+ * - `test(title, body)`+ * - `test(title, details, body)`** **Usage**** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';+ * import { test, expect } from '@playwright/test';*- * export default defineConfig({- * workers: 3,+ * test('basic test', async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * // ...* });* ```*- */- workers: number;- /**- * Launch a development web server (or multiple) during the tests.- *- * **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.+ * **Tags***- * The `port` (but not the `url`) gets passed over to Playwright as a- * [testOptions.baseURL](https://playwright.dev/docs/api/class-testoptions#test-options-base-url). 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).+ * You can tag tests by providing additional test details. Alternatively, you can include tags in the test title. Note+ * that each tag must start with `@` symbol.*- * **NOTE** It is also recommended to specify- * [testOptions.baseURL](https://playwright.dev/docs/api/class-testoptions#test-options-base-url) in the config, so- * that tests could use relative urls.+ * ```js+ * import { test, expect } from '@playwright/test';*- * **Usage**+ * test('basic test', {+ * tag: '@smoke',+ * }, async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * // ...+ * });*- * ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- * export default defineConfig({- * webServer: {- * command: 'npm run start',- * url: 'http://127.0.0.1:3000',- * timeout: 120 * 1000,- * reuseExistingServer: !process.env.CI,- * },- * use: {- * baseURL: 'http://localhost:3000/',- * },+ * test('another test @smoke', async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * // ...* });* ```*- * Now you can use a relative path when navigating the page:+ * Test tags are displayed in the test report, and are available to a custom reporter via `TestCase.tags` property.*- * ```js- * // test.spec.ts- * import { test } from '@playwright/test';+ * You can also filter tests by their tags during test execution:+ * - in the [command line](https://playwright.dev/docs/test-cli#reference);+ * - in the config with [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep) and+ * [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep);*- * test('test', async ({ page }) => {- * // This will result in http://localhost:3000/foo- * await page.goto('/foo');- * });- * ```+ * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).*- * Multiple web servers (or background processes) can be launched:+ * **Annotations**+ *+ * You can annotate tests by providing additional test details.** ```js- * // playwright.config.ts- * import { defineConfig } from '@playwright/test';- * export default defineConfig({- * webServer: [- * {- * command: 'npm run start',- * url: 'http://127.0.0.1:3000',- * timeout: 120 * 1000,- * reuseExistingServer: !process.env.CI,- * },- * {- * command: 'npm run backend',- * url: 'http://127.0.0.1:3333',- * timeout: 120 * 1000,- * reuseExistingServer: !process.env.CI,- * }- * ],- * use: {- * baseURL: 'http://127.0.0.1:3000',+ * import { test, expect } from '@playwright/test';+ *+ * test('basic test', {+ * annotation: {+ * type: 'issue',+ * description: 'https://github.com/microsoft/playwright/issues/23180',* },+ * }, async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * // ...* });* ```*- */- webServer: TestConfigWebServer | null;- configFile?: string;-}--export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped' | 'interrupted';--/**- * `WorkerInfo` contains information about the worker that is running tests and is available to worker-scoped- * fixtures. `WorkerInfo` is a subset of {@link TestInfo} that is available in many other places.- */-export interface WorkerInfo {- /**- * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration).- */- config: FullConfig;- /**- * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration).- */- project: FullProject;- /**- * 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`.+ * Test annotations are displayed in the test report, and are available to a custom reporter via+ * `TestCase.annotations` property.*- * 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;-- /**- * 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`.+ * You can also add annotations during runtime by manipulating+ * [testInfo.annotations](https://playwright.dev/docs/api/class-testinfo#test-info-annotations).*- * Also available as `process.env.TEST_WORKER_INDEX`. Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel)- * with Playwright Test.+ * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).+ * @param title Test title.+ * @param details Additional test details.+ * @param body Test body that takes one or two arguments: an object with fixtures and optional {@link TestInfo}.*/- workerIndex: number;+ (title: string, details: TestDetails, body: (args: TestArgs, testInfo: TestInfo) => Promise<void> | void): void;}/**- * `TestInfo` contains information about currently running test. It is available to test functions,- * [test.beforeEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-before-each),- * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each),- * [test.beforeAll([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-before-all) and- * [test.afterAll([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-all) hooks, and- * test-scoped fixtures. `TestInfo` provides utilities to control test execution: attach files, update test timeout,- * determine which test is currently running and whether it was retried, etc.+ * Playwright Test provides a `test` function to declare tests and `expect` function to write assertions.** ```js* import { test, expect } from '@playwright/test';*- * test('basic test', async ({ page }, testInfo) => {- * expect(testInfo.title).toBe('basic test');- * await page.screenshot(testInfo.outputPath('screenshot.png'));+ * test('basic test', async ({ page }) => {+ * await page.goto('https://playwright.dev/');+ * const name = await page.innerText('.navbar__title');+ * expect(name).toBe('Playwright');* });* ```**/-export interface TestInfo {- /**- * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration).- */- config: FullConfig;- /**- * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration).- */- project: FullProject;+export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue> extends TestFunction<TestArgs & WorkerArgs> {/**- * Attach a value or a file from disk to the current test. Some reporters show test attachments. Either `path` or- * `body` must be specified, but not both.+ * Declares a focused test. If there are some focused tests or suites, all of them will be run but nothing else.+ * - `test.only(title, body)`+ * - `test.only(title, details, body)`*- * For example, you can attach a screenshot to the test:+ * **Usage**** ```js- * import { test, expect } from '@playwright/test';- *- * test('basic test', async ({ page }, testInfo) => {- * await page.goto('https://playwright.dev');- * const screenshot = await page.screenshot();- * await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' });+ * test.only('focus this test', async ({ page }) => {+ * // Run only focused tests in the entire project.* });* ```*- * Or you can attach files returned by your APIs:+ * @param title Test title.+ * @param details See [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) for test details+ * description.+ * @param body Test body that takes one or two arguments: an object with fixtures and optional {@link TestInfo}.+ */+ only: TestFunction<TestArgs & WorkerArgs>;+ /**+ * Declares a group of tests.+ * - `test.describe(title, callback)`+ * - `test.describe(callback)`+ * - `test.describe(title, details, callback)`+ *+ * **Usage**+ *+ * You can declare a group of tests with a title. The title will be visible in the test report as a part of each+ * test's title.** ```js- * import { test, expect } from '@playwright/test';- * import { download } from './my-custom-helpers';+ * test.describe('two tests', () => {+ * test('one', async ({ page }) => {+ * // ...+ * });*- * test('basic test', async ({}, testInfo) => {- * const tmpPath = await download('a');- * await testInfo.attach('downloaded', { path: tmpPath });- * });- * ```- *- * **NOTE** [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach)- * automatically takes care of copying attached files to a location that is accessible to reporters. You can safely- * remove the attachment after awaiting the attach call.- * @param name Attachment name. The name will also be sanitized and used as the prefix of file name when saving to disk.- * @param options- */- attach(name: string, options?: {- /**- * Attachment body. Mutually exclusive with `path`.- */- body?: string|Buffer;-- /**- * Content type of this attachment to properly present in the report, for example `'application/json'` or- * `'image/png'`. If omitted, content type is inferred based on the `path`, or defaults to `text/plain` for [string]- * attachments and `application/octet-stream` for [Buffer] attachments.- */- 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;-- /**- * 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;-- /**- * 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- * 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();- * // ...- * });- * ```- *- */- retry: number;-- /**- * 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.- */- 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.- *- * 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.- *- * Status is usually compared with the- * [testInfo.expectedStatus](https://playwright.dev/docs/api/class-testinfo#test-info-expected-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!`);- * });- * ```- *- */- 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;-- /**- * 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- * 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);- * });- * ```- *- */- timeout: number;-- /**- * The title of the currently running test as passed to `test(title, testFunction)`.- */- title: string;-- /**- * The full title path starting with the project.- */- titlePath: Array<string>;-- /**- * 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.- */- workerIndex: number;-}--type TestDetailsAnnotation = {- type: string;- description?: string;-};--export type TestDetails = {- tag?: string | string[];- annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];-}--interface SuiteFunction {- /**- * Declares a group of tests.- * - `test.describe(title, callback)`- * - `test.describe(callback)`- * - `test.describe(title, details, callback)`- *- * **Usage**- *- * You can declare a group of tests with a title. The title will be visible in the test report as a part of each- * test's title.- *- * ```js- * test.describe('two tests', () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * **Anonymous group**- *- * You can also declare a test group without a title. This is convenient to give a group of tests a common option with- * [test.use(options)](https://playwright.dev/docs/api/class-test#test-use).- *- * ```js- * test.describe(() => {- * test.use({ colorScheme: 'dark' });- *- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * **Tags**- *- * You can tag all tests in a group by providing additional details. Note that each tag must start with `@` symbol.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.describe('two tagged tests', {- * tag: '@smoke',- * }, () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).- *- * **Annotations**- *- * You can annotate all tests in a group by providing additional details.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.describe('two annotated tests', {- * annotation: {- * type: 'issue',- * description: 'https://github.com/microsoft/playwright/issues/23180',- * },- * }, () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).- * @param title Group title.- * @param details Additional details for all tests in the group.- * @param callback A callback that is run immediately when calling- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe). Any tests- * declared in this callback will belong to the group.- */- (title: string, callback: () => void): void;- /**- * Declares a group of tests.- * - `test.describe(title, callback)`- * - `test.describe(callback)`- * - `test.describe(title, details, callback)`- *- * **Usage**- *- * You can declare a group of tests with a title. The title will be visible in the test report as a part of each- * test's title.- *- * ```js- * test.describe('two tests', () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * **Anonymous group**- *- * You can also declare a test group without a title. This is convenient to give a group of tests a common option with- * [test.use(options)](https://playwright.dev/docs/api/class-test#test-use).- *- * ```js- * test.describe(() => {- * test.use({ colorScheme: 'dark' });- *- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * **Tags**- *- * You can tag all tests in a group by providing additional details. Note that each tag must start with `@` symbol.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.describe('two tagged tests', {- * tag: '@smoke',- * }, () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).- *- * **Annotations**- *- * You can annotate all tests in a group by providing additional details.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.describe('two annotated tests', {- * annotation: {- * type: 'issue',- * description: 'https://github.com/microsoft/playwright/issues/23180',- * },- * }, () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).- * @param title Group title.- * @param details Additional details for all tests in the group.- * @param callback A callback that is run immediately when calling- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe). Any tests- * declared in this callback will belong to the group.- */- (callback: () => void): void;- /**- * Declares a group of tests.- * - `test.describe(title, callback)`- * - `test.describe(callback)`- * - `test.describe(title, details, callback)`- *- * **Usage**- *- * You can declare a group of tests with a title. The title will be visible in the test report as a part of each- * test's title.- *- * ```js- * test.describe('two tests', () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * **Anonymous group**- *- * You can also declare a test group without a title. This is convenient to give a group of tests a common option with- * [test.use(options)](https://playwright.dev/docs/api/class-test#test-use).- *- * ```js- * test.describe(() => {- * test.use({ colorScheme: 'dark' });- *- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * **Tags**- *- * You can tag all tests in a group by providing additional details. Note that each tag must start with `@` symbol.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.describe('two tagged tests', {- * tag: '@smoke',- * }, () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).- *- * **Annotations**- *- * You can annotate all tests in a group by providing additional details.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test.describe('two annotated tests', {- * annotation: {- * type: 'issue',- * description: 'https://github.com/microsoft/playwright/issues/23180',- * },- * }, () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });- * });- * ```- *- * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).- * @param title Group title.- * @param details Additional details for all tests in the group.- * @param callback A callback that is run immediately when calling- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe). Any tests- * declared in this callback will belong to the group.- */- (title: string, details: TestDetails, callback: () => void): void;-}--interface TestFunction<TestArgs> {- /**- * Declares a test.- * - `test(title, body)`- * - `test(title, details, body)`- *- * **Usage**- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('basic test', async ({ page }) => {- * await page.goto('https://playwright.dev/');- * // ...- * });- * ```- *- * **Tags**- *- * You can tag tests by providing additional test details. Alternatively, you can include tags in the test title. Note- * that each tag must start with `@` symbol.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('basic test', {- * tag: '@smoke',- * }, async ({ page }) => {- * await page.goto('https://playwright.dev/');- * // ...- * });- *- * test('another test @smoke', async ({ page }) => {- * await page.goto('https://playwright.dev/');- * // ...- * });- * ```- *- * Test tags are displayed in the test report, and are available to a custom reporter via `TestCase.tags` property.- *- * You can also filter tests by their tags during test execution:- * - in the [command line](https://playwright.dev/docs/test-cli#reference);- * - in the config with [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep) and- * [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep);- *- * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).- *- * **Annotations**- *- * You can annotate tests by providing additional test details.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('basic test', {- * annotation: {- * type: 'issue',- * description: 'https://github.com/microsoft/playwright/issues/23180',- * },- * }, async ({ page }) => {- * await page.goto('https://playwright.dev/');- * // ...- * });- * ```- *- * Test annotations are displayed in the test report, and are available to a custom reporter via- * `TestCase.annotations` property.- *- * You can also add annotations during runtime by manipulating- * [testInfo.annotations](https://playwright.dev/docs/api/class-testinfo#test-info-annotations).- *- * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).- * @param title Test title.- * @param details Additional test details.- * @param body Test body that takes one or two arguments: an object with fixtures and optional {@link TestInfo}.- */- (title: string, body: (args: TestArgs, testInfo: TestInfo) => Promise<void> | void): void;- /**- * Declares a test.- * - `test(title, body)`- * - `test(title, details, body)`- *- * **Usage**- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('basic test', async ({ page }) => {- * await page.goto('https://playwright.dev/');- * // ...- * });- * ```- *- * **Tags**- *- * You can tag tests by providing additional test details. Alternatively, you can include tags in the test title. Note- * that each tag must start with `@` symbol.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('basic test', {- * tag: '@smoke',- * }, async ({ page }) => {- * await page.goto('https://playwright.dev/');- * // ...- * });- *- * test('another test @smoke', async ({ page }) => {- * await page.goto('https://playwright.dev/');- * // ...- * });- * ```- *- * Test tags are displayed in the test report, and are available to a custom reporter via `TestCase.tags` property.- *- * You can also filter tests by their tags during test execution:- * - in the [command line](https://playwright.dev/docs/test-cli#reference);- * - in the config with [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep) and- * [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep);- *- * Learn more about [tagging](https://playwright.dev/docs/test-annotations#tag-tests).- *- * **Annotations**- *- * You can annotate tests by providing additional test details.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('basic test', {- * annotation: {- * type: 'issue',- * description: 'https://github.com/microsoft/playwright/issues/23180',- * },- * }, async ({ page }) => {- * await page.goto('https://playwright.dev/');- * // ...- * });- * ```- *- * Test annotations are displayed in the test report, and are available to a custom reporter via- * `TestCase.annotations` property.- *- * You can also add annotations during runtime by manipulating- * [testInfo.annotations](https://playwright.dev/docs/api/class-testinfo#test-info-annotations).- *- * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).- * @param title Test title.- * @param details Additional test details.- * @param body Test body that takes one or two arguments: an object with fixtures and optional {@link TestInfo}.- */- (title: string, details: TestDetails, body: (args: TestArgs, testInfo: TestInfo) => Promise<void> | void): void;-}--/**- * Playwright Test provides a `test` function to declare tests and `expect` function to write assertions.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('basic test', async ({ page }) => {- * await page.goto('https://playwright.dev/');- * const name = await page.innerText('.navbar__title');- * expect(name).toBe('Playwright');- * });- * ```- *- */-export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue> extends TestFunction<TestArgs & WorkerArgs> {- /**- * Declares a focused test. If there are some focused tests or suites, all of them will be run but nothing else.- * - `test.only(title, body)`- * - `test.only(title, details, body)`- *- * **Usage**- *- * ```js- * test.only('focus this test', async ({ page }) => {- * // Run only focused tests in the entire project.- * });- * ```- *- * @param title Test title.- * @param details See [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) for test details- * description.- * @param body Test body that takes one or two arguments: an object with fixtures and optional {@link TestInfo}.- */- only: TestFunction<TestArgs & WorkerArgs>;- /**- * Declares a group of tests.- * - `test.describe(title, callback)`- * - `test.describe(callback)`- * - `test.describe(title, details, callback)`- *- * **Usage**- *- * You can declare a group of tests with a title. The title will be visible in the test report as a part of each- * test's title.- *- * ```js- * test.describe('two tests', () => {- * test('one', async ({ page }) => {- * // ...- * });- *- * test('two', async ({ page }) => {- * // ...- * });+ * test('two', async ({ page }) => {+ * // ...+ * });* });* ```*@@ -7102,108 +6055,414 @@ export default test;export const _baseTest: TestType<{}, {}>;export const expect: Expect<{}>;-/**- * Defines Playwright config- */-export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;-export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;-export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;-export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;-export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;-export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;+/**+ * Defines Playwright config+ */+export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;+export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;+export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;+export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;++type MergedT<List> = List extends [TestType<infer T, any>, ...(infer Rest)] ? T & MergedT<Rest> : {};+type MergedW<List> = List extends [TestType<any, infer W>, ...(infer Rest)] ? W & MergedW<Rest> : {};+type MergedTestType<List> = TestType<MergedT<List>, MergedW<List>>;++/**+ * Merges fixtures+ */+export function mergeTests<List extends any[]>(...tests: List): MergedTestType<List>;++type MergedExpectMatchers<List> = List extends [Expect<infer M>, ...(infer Rest)] ? M & MergedExpectMatchers<Rest> : {};+type MergedExpect<List> = Expect<MergedExpectMatchers<List>>;++/**+ * Merges expects+ */+export function mergeExpects<List extends any[]>(...expects: List): MergedExpect<List>;++// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459+export { };++++/**+ * The {@link APIResponseAssertions} class provides assertion methods that can be used to make assertions about the+ * {@link APIResponse} in the tests.+ *+ * ```js+ * import { test, expect } from '@playwright/test';+ *+ * test('navigates to login', async ({ page }) => {+ * // ...+ * const response = await page.request.get('https://playwright.dev');+ * await expect(response).toBeOK();+ * });+ * ```+ *+ */+interface APIResponseAssertions {+ /**+ * Ensures the response status code is within `200..299` range.+ *+ * **Usage**+ *+ * ```js+ * await expect(response).toBeOK();+ * ```+ *+ */+ toBeOK(): Promise<void>;++ /**+ * Makes the assertion check for the opposite condition. For example, this code tests that the response status is not+ * successful:+ *+ * ```js+ * await expect(response).not.toBeOK();+ * ```+ *+ */+ not: APIResponseAssertions;+}++/**+ * The {@link LocatorAssertions} class provides assertion methods that can be used to make assertions about the {@link+ * Locator} state in the tests.+ *+ * ```js+ * import { test, expect } from '@playwright/test';+ *+ * test('status becomes submitted', async ({ page }) => {+ * // ...+ * await page.getByRole('button').click();+ * await expect(page.locator('.status')).toHaveText('Submitted');+ * });+ * ```+ *+ */+interface LocatorAssertions {+ /**+ * Ensures that {@link Locator} points to an element that is+ * [connected](https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected) to a Document or a ShadowRoot.+ *+ * **Usage**+ *+ * ```js+ * await expect(page.getByText('Hidden text')).toBeAttached();+ * ```+ *+ * @param options+ */+ toBeAttached(options?: {+ attached?: boolean;++ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;++ /**+ * Ensures the {@link Locator} points to a checked input.+ *+ * **Usage**+ *+ * ```js+ * const locator = page.getByLabel('Subscribe to newsletter');+ * await expect(locator).toBeChecked();+ * ```+ *+ * @param options+ */+ toBeChecked(options?: {+ checked?: boolean;++ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;++ /**+ * Ensures the {@link Locator} points to a disabled element. Element is disabled if it has "disabled" attribute or is+ * disabled via+ * ['aria-disabled'](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled). Note+ * that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` can be+ * disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.+ *+ * **Usage**+ *+ * ```js+ * const locator = page.locator('button.submit');+ * await expect(locator).toBeDisabled();+ * ```+ *+ * @param options+ */+ toBeDisabled(options?: {+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;++ /**+ * Ensures the {@link Locator} points to an editable element.+ *+ * **Usage**+ *+ * ```js+ * const locator = page.getByRole('textbox');+ * await expect(locator).toBeEditable();+ * ```+ *+ * @param options+ */+ toBeEditable(options?: {+ editable?: boolean;++ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;-type MergedT<List> = List extends [TestType<infer T, any>, ...(infer Rest)] ? T & MergedT<Rest> : {};-type MergedW<List> = List extends [TestType<any, infer W>, ...(infer Rest)] ? W & MergedW<Rest> : {};-type MergedTestType<List> = TestType<MergedT<List>, MergedW<List>>;+ /**+ * Ensures the {@link Locator} points to an empty editable element or to a DOM node that has no text.+ *+ * **Usage**+ *+ * ```js+ * const locator = page.locator('div.warning');+ * await expect(locator).toBeEmpty();+ * ```+ *+ * @param options+ */+ toBeEmpty(options?: {+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;-/**- * Merges fixtures- */-export function mergeTests<List extends any[]>(...tests: List): MergedTestType<List>;+ /**+ * Ensures the {@link Locator} points to an enabled element.+ *+ * **Usage**+ *+ * ```js+ * const locator = page.locator('button.submit');+ * await expect(locator).toBeEnabled();+ * ```+ *+ * @param options+ */+ toBeEnabled(options?: {+ enabled?: boolean;-type MergedExpectMatchers<List> = List extends [Expect<infer M>, ...(infer Rest)] ? M & MergedExpectMatchers<Rest> : {};-type MergedExpect<List> = Expect<MergedExpectMatchers<List>>;+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;-/**- * Merges expects- */-export function mergeExpects<List extends any[]>(...expects: List): MergedExpect<List>;+ /**+ * Ensures the {@link Locator} points to a focused DOM node.+ *+ * **Usage**+ *+ * ```js+ * const locator = page.getByRole('textbox');+ * await expect(locator).toBeFocused();+ * ```+ *+ * @param options+ */+ toBeFocused(options?: {+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;-// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459-export { };+ /**+ * Ensures that {@link Locator} either does not resolve to any DOM node, or resolves to a+ * [non-visible](https://playwright.dev/docs/actionability#visible) one.+ *+ * **Usage**+ *+ * ```js+ * const locator = page.locator('.my-element');+ * await expect(locator).toBeHidden();+ * ```+ *+ * @param options+ */+ toBeHidden(options?: {+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;+ /**+ * Ensures the {@link Locator} points to an element that intersects viewport, according to the+ * [intersection observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).+ *+ * **Usage**+ *+ * ```js+ * const locator = page.getByRole('button');+ * // Make sure at least some part of element intersects viewport.+ * await expect(locator).toBeInViewport();+ * // Make sure element is fully outside of viewport.+ * await expect(locator).not.toBeInViewport();+ * // Make sure that at least half of the element intersects viewport.+ * await expect(locator).toBeInViewport({ ratio: 0.5 });+ * ```+ *+ * @param options+ */+ toBeInViewport(options?: {+ /**+ * The minimal ratio of the element to intersect viewport. If equals to `0`, then element should intersect viewport at+ * any positive ratio. Defaults to `0`.+ */+ ratio?: number;+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;-/**- * The {@link APIResponseAssertions} class provides assertion methods that can be used to make assertions about the- * {@link APIResponse} in the tests.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('navigates to login', async ({ page }) => {- * // ...- * const response = await page.request.get('https://playwright.dev');- * await expect(response).toBeOK();- * });- * ```- *- */-interface APIResponseAssertions {/**- * Ensures the response status code is within `200..299` range.+ * Ensures that {@link Locator} points to an attached and [visible](https://playwright.dev/docs/actionability#visible) DOM node.+ *+ * To check that at least one element from the list is visible, use+ * [locator.first()](https://playwright.dev/docs/api/class-locator#locator-first).** **Usage**** ```js- * await expect(response).toBeOK();+ * // A specific element is visible.+ * await expect(page.getByText('Welcome')).toBeVisible();+ *+ * // At least one item in the list is visible.+ * await expect(page.getByTestId('todo-item').first()).toBeVisible();+ *+ * // At least one of the two elements is visible, possibly both.+ * await expect(+ * page.getByRole('button', { name: 'Sign in' })+ * .or(page.getByRole('button', { name: 'Sign up' }))+ * .first()+ * ).toBeVisible();* ```*+ * @param options*/- toBeOK(): Promise<void>;+ toBeVisible(options?: {+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;++ visible?: boolean;+ }): Promise<void>;/**- * Makes the assertion check for the opposite condition. For example, this code tests that the response status is not- * successful:+ * Ensures the {@link Locator} points to an element that contains the given text. All nested elements will be+ * considered when computing the text content of the element. You can use regular expressions for the value as well.+ *+ * **Details**+ *+ * When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual+ * text and in the expected string before matching. When regular expression is used, the actual text is matched as is.+ *+ * **Usage**** ```js- * await expect(response).not.toBeOK();+ * const locator = page.locator('.title');+ * await expect(locator).toContainText('substring');+ * await expect(locator).toContainText(/\d messages/);+ * ```+ *+ * If you pass an array as an expected value, the expectations are:+ * 1. Locator resolves to a list of elements.+ * 1. Elements from a **subset** of this list contain text from the expected array, respectively.+ * 1. The matching subset of elements has the same order as the expected array.+ * 1. Each text value from the expected array is matched by some element from the list.+ *+ * For example, consider the following list:+ *+ * ```html+ * <ul>+ * <li>Item Text 1</li>+ * <li>Item Text 2</li>+ * <li>Item Text 3</li>+ * </ul>+ * ```+ *+ * Let's see how we can use the assertion:+ *+ * ```js+ * // ✓ Contains the right items in the right order+ * await expect(page.locator('ul > li')).toContainText(['Text 1', 'Text 3']);+ *+ * // ✖ Wrong order+ * await expect(page.locator('ul > li')).toContainText(['Text 3', 'Text 2']);+ *+ * // ✖ No item contains this text+ * await expect(page.locator('ul > li')).toContainText(['Some 33']);+ *+ * // ✖ Locator points to the outer list element, not to the list items+ * await expect(page.locator('ul')).toContainText(['Text 3']);* ```*+ * @param expected Expected substring or RegExp or a list of those.+ * @param options*/- not: APIResponseAssertions;-}+ toContainText(expected: string|RegExp|ReadonlyArray<string|RegExp>, options?: {+ /**+ * Whether to perform case-insensitive match. `ignoreCase` option takes precedence over the corresponding regular+ * expression flag if specified.+ */+ ignoreCase?: boolean;++ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;++ /**+ * Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.+ */+ useInnerText?: boolean;+ }): Promise<void>;-/**- * The {@link LocatorAssertions} class provides assertion methods that can be used to make assertions about the {@link- * Locator} state in the tests.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('status becomes submitted', async ({ page }) => {- * // ...- * await page.getByRole('button').click();- * await expect(page.locator('.status')).toHaveText('Submitted');- * });- * ```- *- */-interface LocatorAssertions {/**- * Ensures that {@link Locator} points to an element that is- * [connected](https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected) to a Document or a ShadowRoot.+ * Ensures the {@link Locator} points to an element with given attribute.** **Usage**** ```js- * await expect(page.getByText('Hidden text')).toBeAttached();+ * const locator = page.locator('input');+ * await expect(locator).toHaveAttribute('type', 'text');* ```*+ * @param name Attribute name.+ * @param value Expected attribute value.* @param options*/- toBeAttached(options?: {- attached?: boolean;+ toHaveAttribute(name: string, value: string|RegExp, options?: {+ /**+ * Whether to perform case-insensitive match. `ignoreCase` option takes precedence over the corresponding regular+ * expression flag if specified.+ */+ ignoreCase?: boolean;/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.@@ -7212,20 +6471,19 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to a checked input.- *- * **Usage**+ * Ensures the {@link Locator} points to an element with given attribute. The method will assert attribute presence.** ```js- * const locator = page.getByLabel('Subscribe to newsletter');- * await expect(locator).toBeChecked();+ * const locator = page.locator('input');+ * // Assert attribute existence.+ * await expect(locator).toHaveAttribute('disabled');+ * await expect(locator).not.toHaveAttribute('open');* ```*+ * @param name Attribute name.* @param options*/- toBeChecked(options?: {- checked?: boolean;-+ toHaveAttribute(name: string, options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7233,22 +6491,32 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to a disabled element. Element is disabled if it has "disabled" attribute or is- * disabled via- * ['aria-disabled'](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled). Note- * that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` can be- * disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.+ * Ensures the {@link Locator} points to an element with given CSS classes. This needs to be a full match or using a+ * relaxed regular expression.** **Usage***+ * ```html+ * <div class='selected row' id='component'></div>+ * ```+ ** ```js- * const locator = page.locator('button.submit');- * await expect(locator).toBeDisabled();+ * const locator = page.locator('#component');+ * await expect(locator).toHaveClass(/selected/);+ * await expect(locator).toHaveClass('selected row');+ * ```+ *+ * Note that if array is passed as an expected value, entire lists of elements can be asserted:+ *+ * ```js+ * const locator = page.locator('list > .component');+ * await expect(locator).toHaveClass(['component', 'component selected', 'component']);* ```*+ * @param expected Expected class or RegExp or a list of those.* @param options*/- toBeDisabled(options?: {+ toHaveClass(expected: string|RegExp|ReadonlyArray<string|RegExp>, options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7256,20 +6524,19 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to an editable element.+ * Ensures the {@link Locator} resolves to an exact number of DOM nodes.** **Usage**** ```js- * const locator = page.getByRole('textbox');- * await expect(locator).toBeEditable();+ * const list = page.locator('list > .component');+ * await expect(list).toHaveCount(3);* ```*+ * @param count Expected count.* @param options*/- toBeEditable(options?: {- editable?: boolean;-+ toHaveCount(count: number, options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7277,18 +6544,20 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to an empty editable element or to a DOM node that has no text.+ * Ensures the {@link Locator} resolves to an element with the given computed CSS style.** **Usage**** ```js- * const locator = page.locator('div.warning');- * await expect(locator).toBeEmpty();+ * const locator = page.getByRole('button');+ * await expect(locator).toHaveCSS('display', 'flex');* ```*+ * @param name CSS property name.+ * @param value CSS property value.* @param options*/- toBeEmpty(options?: {+ toHaveCSS(name: string, value: string|RegExp, options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7296,20 +6565,19 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to an enabled element.+ * Ensures the {@link Locator} points to an element with the given DOM Node ID.** **Usage**** ```js- * const locator = page.locator('button.submit');- * await expect(locator).toBeEnabled();+ * const locator = page.getByRole('textbox');+ * await expect(locator).toHaveId('lastname');* ```*+ * @param id Element id.* @param options*/- toBeEnabled(options?: {- enabled?: boolean;-+ toHaveId(id: string|RegExp, options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7317,18 +6585,21 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to a focused DOM node.+ * Ensures the {@link Locator} points to an element with given JavaScript property. Note that this property can be of+ * a primitive type as well as a plain serializable JavaScript object.** **Usage**** ```js- * const locator = page.getByRole('textbox');- * await expect(locator).toBeFocused();+ * const locator = page.locator('.component');+ * await expect(locator).toHaveJSProperty('loaded', true);* ```*+ * @param name Property name.+ * @param value Property value.* @param options*/- toBeFocused(options?: {+ toHaveJSProperty(name: string, value: any, options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7336,19 +6607,90 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures that {@link Locator} either does not resolve to any DOM node, or resolves to a- * [non-visible](https://playwright.dev/docs/actionability#visible) one.+ * This function will wait until two consecutive locator screenshots yield the same result, and then compare the last+ * screenshot with the expectation.** **Usage**** ```js- * const locator = page.locator('.my-element');- * await expect(locator).toBeHidden();+ * const locator = page.getByRole('button');+ * await expect(locator).toHaveScreenshot('image.png');* ```*+ * Note that screenshot assertions only work with Playwright test runner.+ * @param name Snapshot name.* @param options*/- toBeHidden(options?: {+ toHaveScreenshot(name: string|ReadonlyArray<string>, options?: {+ /**+ * When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different+ * treatment depending on their duration:+ * - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event.+ * - infinite animations are canceled to initial state, and then played over after the screenshot.+ *+ * Defaults to `"disabled"` that disables animations.+ */+ animations?: "disabled"|"allow";++ /**+ * When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be+ * changed. Defaults to `"hide"`.+ */+ caret?: "hide"|"initial";++ /**+ * Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink+ * box `#FF00FF` (customized by `maskColor`) that completely covers its bounding box.+ */+ mask?: Array<Locator>;++ /**+ * Specify the color of the overlay box for masked elements, in+ * [CSS color format](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). Default color is pink `#FF00FF`.+ */+ maskColor?: string;++ /**+ * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is+ * configurable with `TestConfig.expect`. Unset by default.+ */+ maxDiffPixelRatio?: number;++ /**+ * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by+ * default.+ */+ maxDiffPixels?: number;++ /**+ * Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.+ * Defaults to `false`.+ */+ omitBackground?: boolean;++ /**+ * When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this+ * will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so+ * screenshots of high-dpi devices will be twice as large or even larger.+ *+ * Defaults to `"css"`.+ */+ scale?: "css"|"device";++ /**+ * File name containing the stylesheet to apply while making the screenshot. This is where you can hide dynamic+ * elements, make elements invisible or change their properties to help you creating repeatable screenshots. This+ * stylesheet pierces the Shadow DOM and applies to the inner frames.+ */+ stylePath?: string|Array<string>;++ /**+ * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the+ * same pixel in compared images, between zero (strict) and one (lax), default is configurable with+ * `TestConfig.expect`. Defaults to `0.2`.+ */+ threshold?: number;+/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7356,73 +6698,98 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to an element that intersects viewport, according to the- * [intersection observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).+ * This function will wait until two consecutive locator screenshots yield the same result, and then compare the last+ * screenshot with the expectation.** **Usage**** ```js* const locator = page.getByRole('button');- * // Make sure at least some part of element intersects viewport.- * await expect(locator).toBeInViewport();- * // Make sure element is fully outside of viewport.- * await expect(locator).not.toBeInViewport();- * // Make sure that at least half of the element intersects viewport.- * await expect(locator).toBeInViewport({ ratio: 0.5 });+ * await expect(locator).toHaveScreenshot();* ```*+ * Note that screenshot assertions only work with Playwright test runner.* @param options*/- toBeInViewport(options?: {+ toHaveScreenshot(options?: {+ /**+ * When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different+ * treatment depending on their duration:+ * - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event.+ * - infinite animations are canceled to initial state, and then played over after the screenshot.+ *+ * Defaults to `"disabled"` that disables animations.+ */+ animations?: "disabled"|"allow";++ /**+ * When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be+ * changed. Defaults to `"hide"`.+ */+ caret?: "hide"|"initial";++ /**+ * Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink+ * box `#FF00FF` (customized by `maskColor`) that completely covers its bounding box.+ */+ mask?: Array<Locator>;++ /**+ * Specify the color of the overlay box for masked elements, in+ * [CSS color format](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). Default color is pink `#FF00FF`.+ */+ maskColor?: string;++ /**+ * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is+ * configurable with `TestConfig.expect`. Unset by default.+ */+ maxDiffPixelRatio?: number;++ /**+ * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by+ * default.+ */+ maxDiffPixels?: number;++ /**+ * Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.+ * Defaults to `false`.+ */+ omitBackground?: boolean;++ /**+ * When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this+ * will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so+ * screenshots of high-dpi devices will be twice as large or even larger.+ *+ * Defaults to `"css"`.+ */+ scale?: "css"|"device";+/**- * The minimal ratio of the element to intersect viewport. If equals to `0`, then element should intersect viewport at- * any positive ratio. Defaults to `0`.+ * File name containing the stylesheet to apply while making the screenshot. This is where you can hide dynamic+ * elements, make elements invisible or change their properties to help you creating repeatable screenshots. This+ * stylesheet pierces the Shadow DOM and applies to the inner frames.*/- ratio?: number;+ stylePath?: string|Array<string>;/**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the+ * same pixel in compared images, between zero (strict) and one (lax), default is configurable with+ * `TestConfig.expect`. Defaults to `0.2`.*/- timeout?: number;- }): Promise<void>;+ threshold?: number;- /**- * Ensures that {@link Locator} points to an attached and [visible](https://playwright.dev/docs/actionability#visible) DOM node.- *- * To check that at least one element from the list is visible, use- * [locator.first()](https://playwright.dev/docs/api/class-locator#locator-first).- *- * **Usage**- *- * ```js- * // A specific element is visible.- * await expect(page.getByText('Welcome')).toBeVisible();- *- * // At least one item in the list is visible.- * await expect(page.getByTestId('todo-item').first()).toBeVisible();- *- * // At least one of the two elements is visible, possibly both.- * await expect(- * page.getByRole('button', { name: 'Sign in' })- * .or(page.getByRole('button', { name: 'Sign up' }))- * .first()- * ).toBeVisible();- * ```- *- * @param options- */- toBeVisible(options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/timeout?: number;-- visible?: boolean;}): Promise<void>;/**- * Ensures the {@link Locator} points to an element that contains the given text. All nested elements will be- * considered when computing the text content of the element. You can use regular expressions for the value as well.+ * Ensures the {@link Locator} points to an element with the given text. All nested elements will be considered when+ * computing the text content of the element. You can use regular expressions for the value as well.** **Details***@@ -7433,46 +6800,45 @@ interface LocatorAssertions {** ```js* const locator = page.locator('.title');- * await expect(locator).toContainText('substring');- * await expect(locator).toContainText(/\d messages/);+ * await expect(locator).toHaveText(/Welcome, Test User/);+ * await expect(locator).toHaveText(/Welcome, .*\/);* ```** If you pass an array as an expected value, the expectations are:* 1. Locator resolves to a list of elements.- * 1. Elements from a **subset** of this list contain text from the expected array, respectively.- * 1. The matching subset of elements has the same order as the expected array.- * 1. Each text value from the expected array is matched by some element from the list.+ * 1. The number of elements equals the number of expected values in the array.+ * 1. Elements from the list have text matching expected array values, one by one, in order.** For example, consider the following list:** ```html* <ul>- * <li>Item Text 1</li>- * <li>Item Text 2</li>- * <li>Item Text 3</li>+ * <li>Text 1</li>+ * <li>Text 2</li>+ * <li>Text 3</li>* </ul>* ```** Let's see how we can use the assertion:** ```js- * // ✓ Contains the right items in the right order- * await expect(page.locator('ul > li')).toContainText(['Text 1', 'Text 3']);+ * // ✓ Has the right items in the right order+ * await expect(page.locator('ul > li')).toHaveText(['Text 1', 'Text 2', 'Text 3']);** // ✖ Wrong order- * await expect(page.locator('ul > li')).toContainText(['Text 3', 'Text 2']);+ * await expect(page.locator('ul > li')).toHaveText(['Text 3', 'Text 2', 'Text 1']);*- * // ✖ No item contains this text- * await expect(page.locator('ul > li')).toContainText(['Some 33']);+ * // ✖ Last item does not match+ * await expect(page.locator('ul > li')).toHaveText(['Text 1', 'Text 2', 'Text']);** // ✖ Locator points to the outer list element, not to the list items- * await expect(page.locator('ul')).toContainText(['Text 3']);+ * await expect(page.locator('ul')).toHaveText(['Text 1', 'Text 2', 'Text 3']);* ```*- * @param expected Expected substring or RegExp or a list of those.+ * @param expected Expected string or RegExp or a list of those.* @param options*/- toContainText(expected: string|RegExp|ReadonlyArray<string|RegExp>, options?: {+ toHaveText(expected: string|RegExp|ReadonlyArray<string|RegExp>, options?: {/*** Whether to perform case-insensitive match. `ignoreCase` option takes precedence over the corresponding regular* expression flag if specified.@@ -7491,79 +6857,20 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to an element with given attribute.- *- * **Usage**- *- * ```js- * const locator = page.locator('input');- * await expect(locator).toHaveAttribute('type', 'text');- * ```- *- * @param name Attribute name.- * @param value Expected attribute value.- * @param options- */- toHaveAttribute(name: string, value: string|RegExp, options?: {- /**- * Whether to perform case-insensitive match. `ignoreCase` option takes precedence over the corresponding regular- * expression flag if specified.- */- ignoreCase?: boolean;-- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;-- /**- * Ensures the {@link Locator} points to an element with given attribute. The method will assert attribute presence.- *- * ```js- * const locator = page.locator('input');- * // Assert attribute existence.- * await expect(locator).toHaveAttribute('disabled');- * await expect(locator).not.toHaveAttribute('open');- * ```- *- * @param name Attribute name.- * @param options- */- toHaveAttribute(name: string, options?: {- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;-- /**- * Ensures the {@link Locator} points to an element with given CSS classes. This needs to be a full match or using a- * relaxed regular expression.+ * Ensures the {@link Locator} points to an element with the given input value. You can use regular expressions for+ * the value as well.** **Usage***- * ```html- * <div class='selected row' id='component'></div>- * ```- *- * ```js- * const locator = page.locator('#component');- * await expect(locator).toHaveClass(/selected/);- * await expect(locator).toHaveClass('selected row');- * ```- *- * Note that if array is passed as an expected value, entire lists of elements can be asserted:- ** ```js- * const locator = page.locator('list > .component');- * await expect(locator).toHaveClass(['component', 'component selected', 'component']);+ * const locator = page.locator('input[type=number]');+ * await expect(locator).toHaveValue(/[0-9]/);* ```*- * @param expected Expected class or RegExp or a list of those.+ * @param value Expected value.* @param options*/- toHaveClass(expected: string|RegExp|ReadonlyArray<string|RegExp>, options?: {+ toHaveValue(value: string|RegExp, options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7571,60 +6878,31 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} resolves to an exact number of DOM nodes.+ * Ensures the {@link Locator} points to multi-select/combobox (i.e. a `select` with the `multiple` attribute) and the+ * specified values are selected.** **Usage***- * ```js- * const list = page.locator('list > .component');- * await expect(list).toHaveCount(3);- * ```- *- * @param count Expected count.- * @param options- */- toHaveCount(count: number, options?: {- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;-- /**- * Ensures the {@link Locator} resolves to an element with the given computed CSS style.- *- * **Usage**+ * For example, given the following element:*- * ```js- * const locator = page.getByRole('button');- * await expect(locator).toHaveCSS('display', 'flex');+ * ```html+ * <select id="favorite-colors" multiple>+ * <option value="R">Red</option>+ * <option value="G">Green</option>+ * <option value="B">Blue</option>+ * </select>* ```*- * @param name CSS property name.- * @param value CSS property value.- * @param options- */- toHaveCSS(name: string, value: string|RegExp, options?: {- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;-- /**- * Ensures the {@link Locator} points to an element with the given DOM Node ID.- *- * **Usage**- ** ```js- * const locator = page.getByRole('textbox');- * await expect(locator).toHaveId('lastname');+ * const locator = page.locator('id=favorite-colors');+ * await locator.selectOption(['R', 'G']);+ * await expect(locator).toHaveValues([/R/, /G/]);* ```*- * @param id Element id.+ * @param values Expected options currently selected.* @param options*/- toHaveId(id: string|RegExp, options?: {+ toHaveValues(values: ReadonlyArray<string|RegExp>, options?: {/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/@@ -7632,36 +6910,41 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to an element with given JavaScript property. Note that this property can be of- * a primitive type as well as a plain serializable JavaScript object.- *- * **Usage**+ * Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain+ * text `"error"`:** ```js- * const locator = page.locator('.component');- * await expect(locator).toHaveJSProperty('loaded', true);+ * await expect(locator).not.toContainText('error');* ```*- * @param name Property name.- * @param value Property value.- * @param options*/- toHaveJSProperty(name: string, value: any, options?: {- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;+ not: LocatorAssertions;+}+/**+ * The {@link PageAssertions} class provides assertion methods that can be used to make assertions about the {@link+ * Page} state in the tests.+ *+ * ```js+ * import { test, expect } from '@playwright/test';+ *+ * test('navigates to login', async ({ page }) => {+ * // ...+ * await page.getByText('Sign in').click();+ * await expect(page).toHaveURL(/.*\/login/);+ * });+ * ```+ *+ */+interface PageAssertions {/**- * This function will wait until two consecutive locator screenshots yield the same result, and then compare the last+ * This function will wait until two consecutive page screenshots yield the same result, and then compare the last* screenshot with the expectation.** **Usage**** ```js- * const locator = page.getByRole('button');- * await expect(locator).toHaveScreenshot('image.png');+ * await expect(page).toHaveScreenshot('image.png');* ```** Note that screenshot assertions only work with Playwright test runner.@@ -7677,13 +6960,44 @@ interface LocatorAssertions {** Defaults to `"disabled"` that disables animations.*/- animations?: "disabled"|"allow";+ animations?: "disabled"|"allow";++ /**+ * When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be+ * changed. Defaults to `"hide"`.+ */+ caret?: "hide"|"initial";++ /**+ * An object which specifies clipping of the resulting image.+ */+ clip?: {+ /**+ * x-coordinate of top-left corner of clip area+ */+ x: number;++ /**+ * y-coordinate of top-left corner of clip area+ */+ y: number;++ /**+ * width of clipping area+ */+ width: number;++ /**+ * height of clipping area+ */+ height: number;+ };/**- * When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be- * changed. Defaults to `"hide"`.+ * When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to+ * `false`.*/- caret?: "hide"|"initial";+ fullPage?: boolean;/*** Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink@@ -7745,14 +7059,13 @@ interface LocatorAssertions {}): Promise<void>;/**- * This function will wait until two consecutive locator screenshots yield the same result, and then compare the last+ * This function will wait until two consecutive page screenshots yield the same result, and then compare the last* screenshot with the expectation.** **Usage**** ```js- * const locator = page.getByRole('button');- * await expect(locator).toHaveScreenshot();+ * await expect(page).toHaveScreenshot();* ```** Note that screenshot assertions only work with Playwright test runner.@@ -7775,6 +7088,37 @@ interface LocatorAssertions {*/caret?: "hide"|"initial";+ /**+ * An object which specifies clipping of the resulting image.+ */+ clip?: {+ /**+ * x-coordinate of top-left corner of clip area+ */+ x: number;++ /**+ * y-coordinate of top-left corner of clip area+ */+ y: number;++ /**+ * width of clipping area+ */+ width: number;++ /**+ * height of clipping area+ */+ height: number;+ };++ /**+ * When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to+ * `false`.+ */+ fullPage?: boolean;+/*** Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink* box `#FF00FF` (customized by `maskColor`) that completely covers its bounding box.@@ -7835,565 +7179,622 @@ interface LocatorAssertions {}): Promise<void>;/**- * Ensures the {@link Locator} points to an element with the given text. All nested elements will be considered when- * computing the text content of the element. You can use regular expressions for the value as well.- *- * **Details**- *- * When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual- * text and in the expected string before matching. When regular expression is used, the actual text is matched as is.+ * Ensures the page has the given title.+ *+ * **Usage**+ *+ * ```js+ * await expect(page).toHaveTitle(/.*checkout/);+ * ```+ *+ * @param titleOrRegExp Expected title or RegExp.+ * @param options+ */+ toHaveTitle(titleOrRegExp: string|RegExp, options?: {+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;++ /**+ * Ensures the page is navigated to the given URL.+ *+ * **Usage**+ *+ * ```js+ * await expect(page).toHaveURL(/.*checkout/);+ * ```+ *+ * @param urlOrRegExp Expected URL string or RegExp.+ * @param options+ */+ toHaveURL(urlOrRegExp: string|RegExp, options?: {+ /**+ * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ */+ timeout?: number;+ }): Promise<void>;++ /**+ * Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't+ * contain `"error"`:+ *+ * ```js+ * await expect(page).not.toHaveURL('error');+ * ```+ *+ */+ not: PageAssertions;+}++/**+ * Playwright provides methods for comparing page and element screenshots with expected values stored in files.+ *+ * ```js+ * expect(screenshot).toMatchSnapshot('landing-page.png');+ * ```+ *+ */+interface SnapshotAssertions {+ /**+ * **NOTE** To compare screenshots, use+ * [expect(page).toHaveScreenshot(name[, options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1)+ * instead.+ *+ * Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test+ * snapshots directory.+ *+ * **Usage**+ *+ * ```js+ * // Basic usage.+ * expect(await page.screenshot()).toMatchSnapshot('landing-page.png');+ *+ * // Pass options to customize the snapshot comparison and have a generated name.+ * expect(await page.screenshot()).toMatchSnapshot('landing-page.png', {+ * maxDiffPixels: 27, // allow no more than 27 different pixels.+ * });+ *+ * // Configure image matching threshold.+ * expect(await page.screenshot()).toMatchSnapshot('landing-page.png', { threshold: 0.3 });+ *+ * // Bring some structure to your snapshot files by passing file path segments.+ * expect(await page.screenshot()).toMatchSnapshot(['landing', 'step2.png']);+ * expect(await page.screenshot()).toMatchSnapshot(['landing', 'step3.png']);+ * ```+ *+ * Learn more about [visual comparisons](https://playwright.dev/docs/test-snapshots).+ *+ * Note that matching snapshots only work with Playwright test runner.+ * @param name Snapshot name.+ * @param options+ */+ toMatchSnapshot(name: string|ReadonlyArray<string>, options?: {+ /**+ * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is+ * configurable with `TestConfig.expect`. Unset by default.+ */+ maxDiffPixelRatio?: number;++ /**+ * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by+ * default.+ */+ maxDiffPixels?: number;++ /**+ * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the+ * same pixel in compared images, between zero (strict) and one (lax), default is configurable with+ * `TestConfig.expect`. Defaults to `0.2`.+ */+ threshold?: number;+ }): void;++ /**+ * **NOTE** To compare screenshots, use+ * [expect(page).toHaveScreenshot([options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-2)+ * instead.+ *+ * Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test+ * snapshots directory.+ *+ * **Usage**+ *+ * ```js+ * // Basic usage and the file name is derived from the test name.+ * expect(await page.screenshot()).toMatchSnapshot();+ *+ * // Pass options to customize the snapshot comparison and have a generated name.+ * expect(await page.screenshot()).toMatchSnapshot({+ * maxDiffPixels: 27, // allow no more than 27 different pixels.+ * });+ *+ * // Configure image matching threshold and snapshot name.+ * expect(await page.screenshot()).toMatchSnapshot({+ * name: 'landing-page.png',+ * threshold: 0.3,+ * });+ * ```+ *+ * Learn more about [visual comparisons](https://playwright.dev/docs/test-snapshots).+ *+ * Note that matching snapshots only work with Playwright test runner.+ * @param options+ */+ toMatchSnapshot(options?: {+ /**+ * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is+ * configurable with `TestConfig.expect`. Unset by default.+ */+ maxDiffPixelRatio?: number;++ /**+ * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by+ * default.+ */+ maxDiffPixels?: number;++ /**+ * Snapshot name. If not passed, the test name and ordinals are used when called multiple times.+ */+ name?: string|Array<string>;++ /**+ * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the+ * same pixel in compared images, between zero (strict) and one (lax), default is configurable with+ * `TestConfig.expect`. Defaults to `0.2`.+ */+ threshold?: number;+ }): void;+}++/**+ * `TestInfo` contains information about currently running test. It is available to test functions,+ * [test.beforeEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-before-each),+ * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each),+ * [test.beforeAll([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-before-all) and+ * [test.afterAll([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-all) hooks, and+ * test-scoped fixtures. `TestInfo` provides utilities to control test execution: attach files, update test timeout,+ * determine which test is currently running and whether it was retried, etc.+ *+ * ```js+ * import { test, expect } from '@playwright/test';+ *+ * test('basic test', async ({ page }, testInfo) => {+ * expect(testInfo.title).toBe('basic test');+ * await page.screenshot(testInfo.outputPath('screenshot.png'));+ * });+ * ```+ *+ */+export interface TestInfo {+ /**+ * Attach a value or a file from disk to the current test. Some reporters show test attachments. Either `path` or+ * `body` must be specified, but not both.*- * **Usage**+ * For example, you can attach a screenshot to the test:** ```js- * const locator = page.locator('.title');- * await expect(locator).toHaveText(/Welcome, Test User/);- * await expect(locator).toHaveText(/Welcome, .*\/);- * ```- *- * If you pass an array as an expected value, the expectations are:- * 1. Locator resolves to a list of elements.- * 1. The number of elements equals the number of expected values in the array.- * 1. Elements from the list have text matching expected array values, one by one, in order.- *- * For example, consider the following list:+ * import { test, expect } from '@playwright/test';*- * ```html- * <ul>- * <li>Text 1</li>- * <li>Text 2</li>- * <li>Text 3</li>- * </ul>+ * test('basic test', async ({ page }, testInfo) => {+ * await page.goto('https://playwright.dev');+ * const screenshot = await page.screenshot();+ * await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' });+ * });* ```*- * Let's see how we can use the assertion:+ * Or you can attach files returned by your APIs:** ```js- * // ✓ Has the right items in the right order- * await expect(page.locator('ul > li')).toHaveText(['Text 1', 'Text 2', 'Text 3']);- *- * // ✖ Wrong order- * await expect(page.locator('ul > li')).toHaveText(['Text 3', 'Text 2', 'Text 1']);- *- * // ✖ Last item does not match- * await expect(page.locator('ul > li')).toHaveText(['Text 1', 'Text 2', 'Text']);+ * import { test, expect } from '@playwright/test';+ * import { download } from './my-custom-helpers';*- * // ✖ Locator points to the outer list element, not to the list items- * await expect(page.locator('ul')).toHaveText(['Text 1', 'Text 2', 'Text 3']);+ * test('basic test', async ({}, testInfo) => {+ * const tmpPath = await download('a');+ * await testInfo.attach('downloaded', { path: tmpPath });+ * });* ```*- * @param expected Expected string or RegExp or a list of those.+ * **NOTE** [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach)+ * automatically takes care of copying attached files to a location that is accessible to reporters. You can safely+ * remove the attachment after awaiting the attach call.+ * @param name Attachment name. The name will also be sanitized and used as the prefix of file name when saving to disk.* @param options*/- toHaveText(expected: string|RegExp|ReadonlyArray<string|RegExp>, options?: {+ attach(name: string, options?: {/**- * Whether to perform case-insensitive match. `ignoreCase` option takes precedence over the corresponding regular- * expression flag if specified.+ * Attachment body. Mutually exclusive with `path`.*/- ignoreCase?: boolean;+ body?: string|Buffer;/**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.+ * Content type of this attachment to properly present in the report, for example `'application/json'` or+ * `'image/png'`. If omitted, content type is inferred based on the `path`, or defaults to `text/plain` for [string]+ * attachments and `application/octet-stream` for [Buffer] attachments.*/- timeout?: number;+ contentType?: string;/**- * Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.+ * Path on the filesystem to the attached file. Mutually exclusive with `body`.*/- useInnerText?: boolean;+ path?: string;}): Promise<void>;/**- * Ensures the {@link Locator} points to an element with the given input value. You can use regular expressions for- * the value as well.- *- * **Usage**- *- * ```js- * const locator = page.locator('input[type=number]');- * await expect(locator).toHaveValue(/[0-9]/);- * ```- *- * @param value Expected value.- * @param options+ * 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).*/- toHaveValue(value: string|RegExp, options?: {- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;+ fail(): void;/**- * Ensures the {@link Locator} points to multi-select/combobox (i.e. a `select` with the `multiple` attribute) and the- * specified values are selected.- *- * **Usage**- *- * For example, given the following element:- *- * ```html- * <select id="favorite-colors" multiple>- * <option value="R">Red</option>- * <option value="G">Green</option>- * <option value="B">Blue</option>- * </select>- * ```- *- * ```js- * const locator = page.locator('id=favorite-colors');- * await locator.selectOption(['R', 'G']);- * await expect(locator).toHaveValues([/R/, /G/]);- * ```- *- * @param values Expected options currently selected.- * @param options+ * 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.*/- toHaveValues(values: ReadonlyArray<string|RegExp>, options?: {- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;+ fail(condition: boolean, description?: string): void;/**- * Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain- * text `"error"`:+ * 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- * await expect(locator).not.toContainText('error');+ * 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.*/- not: LocatorAssertions;-}+ outputPath(...pathSegments: ReadonlyArray<string>): string;-/**- * The {@link PageAssertions} class provides assertion methods that can be used to make assertions about the {@link- * Page} state in the tests.- *- * ```js- * import { test, expect } from '@playwright/test';- *- * test('navigates to login', async ({ page }) => {- * // ...- * await page.getByText('Sign in').click();- * await expect(page).toHaveURL(/.*\/login/);- * });- * ```- *- */-interface PageAssertions {/**- * This function will wait until two consecutive page screenshots yield the same result, and then compare the last- * screenshot with the expectation.+ * Changes the timeout for the currently running test. Zero means no timeout. Learn more about+ * [various timeouts](https://playwright.dev/docs/test-timeouts).*- * **Usage**+ * 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- * await expect(page).toHaveScreenshot('image.png');+ * 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);+ * });* ```*- * Note that screenshot assertions only work with Playwright test runner.- * @param name Snapshot name.- * @param options+ * @param timeout Timeout in milliseconds.*/- toHaveScreenshot(name: string|ReadonlyArray<string>, options?: {- /**- * When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different- * treatment depending on their duration:- * - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event.- * - infinite animations are canceled to initial state, and then played over after the screenshot.- *- * Defaults to `"disabled"` that disables animations.- */- animations?: "disabled"|"allow";+ setTimeout(timeout: number): void;- /**- * When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be- * changed. Defaults to `"hide"`.- */- caret?: "hide"|"initial";+ /**+ * 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;- /**- * An object which specifies clipping of the resulting image.- */- clip?: {- /**- * x-coordinate of top-left corner of clip area- */- x: number;+ /**+ * 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;- /**- * y-coordinate of top-left corner of clip area- */- y: number;+ /**+ * 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;- /**- * width of clipping area- */- width: number;+ /**+ * 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;- /**- * height of clipping area- */- height: number;- };+ /**+ * 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<{/**- * When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to- * `false`.+ * Annotation type, for example `'skip'` or `'fail'`.*/- fullPage?: boolean;+ type: string;/**- * Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink- * box `#FF00FF` (customized by `maskColor`) that completely covers its bounding box.+ * Optional description.*/- mask?: Array<Locator>;+ 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<{/**- * Specify the color of the overlay box for masked elements, in- * [CSS color format](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). Default color is pink `#FF00FF`.+ * Attachment name.*/- maskColor?: string;+ name: string;/**- * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is- * configurable with `TestConfig.expect`. Unset by default.+ * Content type of this attachment to properly present in the report, for example `'application/json'` or+ * `'image/png'`.*/- maxDiffPixelRatio?: number;+ contentType: string;/**- * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by- * default.+ * Optional path on the filesystem to the attached file.*/- maxDiffPixels?: number;+ path?: string;/**- * Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.- * Defaults to `false`.+ * Optional attachment body used instead of a file.*/- omitBackground?: boolean;+ body?: Buffer;+ }>;- /**- * When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this- * will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so- * screenshots of high-dpi devices will be twice as large or even larger.- *- * Defaults to `"css"`.- */- scale?: "css"|"device";+ /**+ * Column number where the currently running test is declared.+ */+ column: number;- /**- * File name containing the stylesheet to apply while making the screenshot. This is where you can hide dynamic- * elements, make elements invisible or change their properties to help you creating repeatable screenshots. This- * stylesheet pierces the Shadow DOM and applies to the inner frames.- */- stylePath?: string|Array<string>;+ /**+ * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration).+ */+ config: ConfigInWorker;- /**- * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the- * same pixel in compared images, between zero (strict) and one (lax), default is configurable with- * `TestConfig.expect`. Defaults to `0.2`.- */- threshold?: number;+ /**+ * 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;- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;+ /**+ * 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;/**- * This function will wait until two consecutive page screenshots yield the same result, and then compare the last- * screenshot with the expectation.+ * 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).*- * **Usage**+ * Expected status is usually compared with the actual+ * [testInfo.status](https://playwright.dev/docs/api/class-testinfo#test-info-status):** ```js- * await expect(page).toHaveScreenshot();+ * import { test, expect } from '@playwright/test';+ *+ * test.afterEach(async ({}, testInfo) => {+ * if (testInfo.status !== testInfo.expectedStatus)+ * console.log(`${testInfo.title} did not run as expected!`);+ * });* ```*- * Note that screenshot assertions only work with Playwright test runner.- * @param options*/- toHaveScreenshot(options?: {- /**- * When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different- * treatment depending on their duration:- * - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event.- * - infinite animations are canceled to initial state, and then played over after the screenshot.- *- * Defaults to `"disabled"` that disables animations.- */- animations?: "disabled"|"allow";-- /**- * When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be- * changed. Defaults to `"hide"`.- */- caret?: "hide"|"initial";-- /**- * An object which specifies clipping of the resulting image.- */- clip?: {- /**- * x-coordinate of top-left corner of clip area- */- x: number;-- /**- * y-coordinate of top-left corner of clip area- */- y: number;-- /**- * width of clipping area- */- width: number;-- /**- * height of clipping area- */- height: number;- };-- /**- * When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to- * `false`.- */- fullPage?: boolean;-- /**- * Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink- * box `#FF00FF` (customized by `maskColor`) that completely covers its bounding box.- */- mask?: Array<Locator>;-- /**- * Specify the color of the overlay box for masked elements, in- * [CSS color format](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). Default color is pink `#FF00FF`.- */- maskColor?: string;-- /**- * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is- * configurable with `TestConfig.expect`. Unset by default.- */- maxDiffPixelRatio?: number;+ expectedStatus: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";- /**- * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by- * default.- */- maxDiffPixels?: number;+ /**+ * Absolute path to a file where the currently running test is declared.+ */+ file: string;- /**- * Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.- * Defaults to `false`.- */- omitBackground?: boolean;+ /**+ * Test function as passed to `test(title, testFunction)`.+ */+ fn: Function;- /**- * When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this- * will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so- * screenshots of high-dpi devices will be twice as large or even larger.- *- * Defaults to `"css"`.- */- scale?: "css"|"device";+ /**+ * Line number where the currently running test is declared.+ */+ line: number;- /**- * File name containing the stylesheet to apply while making the screenshot. This is where you can hide dynamic- * elements, make elements invisible or change their properties to help you creating repeatable screenshots. This- * stylesheet pierces the Shadow DOM and applies to the inner frames.- */- stylePath?: string|Array<string>;+ /**+ * Absolute path to the output directory for this specific test run. Each test run gets its own directory so they+ * cannot conflict.+ */+ outputDir: string;- /**- * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the- * same pixel in compared images, between zero (strict) and one (lax), default is configurable with- * `TestConfig.expect`. Defaults to `0.2`.- */- threshold?: number;+ /**+ * 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;- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;+ /**+ * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration).+ */+ project: ProjectInWorker;/**- * Ensures the page has the given title.- *- * **Usage**- *- * ```js- * await expect(page).toHaveTitle(/.*checkout/);- * ```- *- * @param titleOrRegExp Expected title or RegExp.- * @param options+ * 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).*/- toHaveTitle(titleOrRegExp: string|RegExp, options?: {- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;+ repeatEachIndex: number;/**- * Ensures the page is navigated to the given URL.- *- * **Usage**+ * 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- * await expect(page).toHaveURL(/.*checkout/);+ * 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();+ * // ...+ * });* ```*- * @param urlOrRegExp Expected URL string or RegExp.- * @param options*/- toHaveURL(urlOrRegExp: string|RegExp, options?: {- /**- * Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.- */- timeout?: number;- }): Promise<void>;+ retry: number;/**- * Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't- * contain `"error"`:- *- * ```js- * await expect(page).not.toHaveURL('error');- * ```+ * 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.*/- not: PageAssertions;-}+ snapshotDir: string;-/**- * Playwright provides methods for comparing page and element screenshots with expected values stored in files.- *- * ```js- * expect(screenshot).toMatchSnapshot('landing-page.png');- * ```- *- */-interface SnapshotAssertions {/**- * **NOTE** To compare screenshots, use- * [expect(page).toHaveScreenshot(name[, options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1)- * instead.+ * **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.*- * Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test- * snapshots directory.+ * 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.*- * **Usage**+ * Status is usually compared with the+ * [testInfo.expectedStatus](https://playwright.dev/docs/api/class-testinfo#test-info-expected-status):** ```js- * // Basic usage.- * expect(await page.screenshot()).toMatchSnapshot('landing-page.png');+ * import { test, expect } from '@playwright/test';*- * // Pass options to customize the snapshot comparison and have a generated name.- * expect(await page.screenshot()).toMatchSnapshot('landing-page.png', {- * maxDiffPixels: 27, // allow no more than 27 different pixels.+ * test.afterEach(async ({}, testInfo) => {+ * if (testInfo.status !== testInfo.expectedStatus)+ * console.log(`${testInfo.title} did not run as expected!`);* });- *- * // Configure image matching threshold.- * expect(await page.screenshot()).toMatchSnapshot('landing-page.png', { threshold: 0.3 });- *- * // Bring some structure to your snapshot files by passing file path segments.- * expect(await page.screenshot()).toMatchSnapshot(['landing', 'step2.png']);- * expect(await page.screenshot()).toMatchSnapshot(['landing', 'step3.png']);* ```*- * Learn more about [visual comparisons](https://playwright.dev/docs/test-snapshots).- *- * Note that matching snapshots only work with Playwright test runner.- * @param name Snapshot name.- * @param options*/- toMatchSnapshot(name: string|ReadonlyArray<string>, options?: {- /**- * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is- * configurable with `TestConfig.expect`. Unset by default.- */- maxDiffPixelRatio?: number;+ status?: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";- /**- * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by- * default.- */- maxDiffPixels?: number;+ /**+ * 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>;- /**- * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the- * same pixel in compared images, between zero (strict) and one (lax), default is configurable with- * `TestConfig.expect`. Defaults to `0.2`.- */- threshold?: number;- }): void;+ /**+ * Test id matching the test case id in the reporter API.+ */+ testId: string;/**- * **NOTE** To compare screenshots, use- * [expect(page).toHaveScreenshot([options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-2)- * instead.- *- * Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test- * snapshots directory.+ * Timeout in milliseconds for the currently running test. Zero means no timeout. Learn more about+ * [various timeouts](https://playwright.dev/docs/test-timeouts).*- * **Usage**+ * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration)** ```js- * // Basic usage and the file name is derived from the test name.- * expect(await page.screenshot()).toMatchSnapshot();- *- * // Pass options to customize the snapshot comparison and have a generated name.- * expect(await page.screenshot()).toMatchSnapshot({- * maxDiffPixels: 27, // allow no more than 27 different pixels.- * });+ * import { test, expect } from '@playwright/test';*- * // Configure image matching threshold and snapshot name.- * expect(await page.screenshot()).toMatchSnapshot({- * name: 'landing-page.png',- * threshold: 0.3,+ * test.beforeEach(async ({ page }, testInfo) => {+ * // Extend timeout for all tests running this hook by 30 seconds.+ * testInfo.setTimeout(testInfo.timeout + 30000);* });* ```*- * Learn more about [visual comparisons](https://playwright.dev/docs/test-snapshots).- *- * Note that matching snapshots only work with Playwright test runner.- * @param options*/- toMatchSnapshot(options?: {- /**- * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is- * configurable with `TestConfig.expect`. Unset by default.- */- maxDiffPixelRatio?: number;+ timeout: number;- /**- * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by- * default.- */- maxDiffPixels?: number;+ /**+ * The title of the currently running test as passed to `test(title, testFunction)`.+ */+ title: string;- /**- * Snapshot name. If not passed, the test name and ordinals are used when called multiple times.- */- name?: string|Array<string>;+ /**+ * The full title path starting with the project.+ */+ titlePath: Array<string>;- /**- * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the- * same pixel in compared images, between zero (strict) and one (lax), default is configurable with- * `TestConfig.expect`. Defaults to `0.2`.- */- threshold?: number;- }): 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.+ */+ workerIndex: number;}/**@@ -8945,6 +8346,41 @@ interface TestProject {timeout?: number;}+/**+ * `WorkerInfo` contains information about the worker that is running tests and is available to worker-scoped+ * fixtures. `WorkerInfo` is a subset of {@link TestInfo} that is available in many other places.+ */+export interface WorkerInfo {+ /**+ * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration).+ */+ config: ConfigInWorker;++ /**+ * 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;++ /**+ * 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.+ */+ workerIndex: number;+}+interface TestConfigWebServer {/*** Shell command to start. For example `npm run start`..diff --git a/packages/playwright/types/testReporter.d.ts b/packages/playwright/types/testReporter.d.tsindex 605012071c..5ed0d34eca 100644--- a/packages/playwright/types/testReporter.d.ts+++ b/packages/playwright/types/testReporter.d.ts@@ -15,12 +15,221 @@* limitations under the License.*/-import type { FullConfig, FullProject, TestStatus, Metadata } from './test';-export type { FullConfig, TestStatus, FullProject } from './test';+import type { TestStatus, Metadata, PlaywrightTestOptions, PlaywrightWorkerOptions, ReporterDescription, ConfigInWorker } from './test';+export type { TestStatus } from './test';++type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;++/**+ * Resolved configuration passed to+ * [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin).+ */+export interface FullConfig<TestArgs = {}, WorkerArgs = {}> {+ /**+ * List of resolved projects.+ */+ projects: FullProject<TestArgs, WorkerArgs>[];+ /**+ * See [testConfig.reporter](https://playwright.dev/docs/api/class-testconfig#test-config-reporter).+ */+ reporter: ReporterDescription[];+ /**+ * See [testConfig.webServer](https://playwright.dev/docs/api/class-testconfig#test-config-web-server).+ */+ webServer: ConfigInWorker['webServer'];+ /**+ * Path to the configuration file (if any) used to run the tests.+ */+ configFile?: string;++ /**+ * See [testConfig.forbidOnly](https://playwright.dev/docs/api/class-testconfig#test-config-forbid-only).+ */+ forbidOnly: boolean;++ /**+ * See [testConfig.fullyParallel](https://playwright.dev/docs/api/class-testconfig#test-config-fully-parallel).+ */+ fullyParallel: boolean;++ /**+ * See [testConfig.globalSetup](https://playwright.dev/docs/api/class-testconfig#test-config-global-setup).+ */+ globalSetup: null|string;++ /**+ * See [testConfig.globalTeardown](https://playwright.dev/docs/api/class-testconfig#test-config-global-teardown).+ */+ globalTeardown: null|string;++ /**+ * See [testConfig.globalTimeout](https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout).+ */+ globalTimeout: number;++ /**+ * See [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep).+ */+ grep: RegExp|Array<RegExp>;++ /**+ * See [testConfig.grepInvert](https://playwright.dev/docs/api/class-testconfig#test-config-grep-invert).+ */+ grepInvert: null|RegExp|Array<RegExp>;++ /**+ * See [testConfig.maxFailures](https://playwright.dev/docs/api/class-testconfig#test-config-max-failures).+ */+ maxFailures: number;++ /**+ * See [testConfig.metadata](https://playwright.dev/docs/api/class-testconfig#test-config-metadata).+ */+ metadata: Metadata;++ /**+ * See [testConfig.preserveOutput](https://playwright.dev/docs/api/class-testconfig#test-config-preserve-output).+ */+ preserveOutput: "always"|"never"|"failures-only";++ /**+ * See [testConfig.quiet](https://playwright.dev/docs/api/class-testconfig#test-config-quiet).+ */+ quiet: boolean;++ /**+ * See [testConfig.reportSlowTests](https://playwright.dev/docs/api/class-testconfig#test-config-report-slow-tests).+ */+ reportSlowTests: null|{+ /**+ * The maximum number of slow test files to report. Defaults to `5`.+ */+ max: number;++ /**+ * Test duration in milliseconds that is considered slow. Defaults to 15 seconds.+ */+ threshold: number;+ };++ rootDir: string;++ /**+ * See [testConfig.shard](https://playwright.dev/docs/api/class-testconfig#test-config-shard).+ */+ shard: null|{+ /**+ * The total number of shards.+ */+ total: number;++ /**+ * The index of the shard to execute, one-based.+ */+ current: number;+ };++ /**+ * See [testConfig.updateSnapshots](https://playwright.dev/docs/api/class-testconfig#test-config-update-snapshots).+ */+ updateSnapshots: "all"|"none"|"missing";++ /**+ * Playwright version.+ */+ version: string;++ /**+ * See [testConfig.workers](https://playwright.dev/docs/api/class-testconfig#test-config-workers).+ */+ workers: number;+}++/**+ * Runtime representation of the test project configuration that is passed to {@link Reporter}. It exposes some of the+ * resolved fields declared in {@link TestProject}. You can get {@link FullProject} instance from+ * [fullConfig.projects](https://playwright.dev/docs/api/class-fullconfig#full-config-projects) or+ * [suite.project()](https://playwright.dev/docs/api/class-suite#suite-project).+ */+export interface FullProject<TestArgs = {}, WorkerArgs = {}> {+ /**+ * See [testProject.use](https://playwright.dev/docs/api/class-testproject#test-project-use).+ */+ use: UseOptions<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;+ /**+ * See [testProject.dependencies](https://playwright.dev/docs/api/class-testproject#test-project-dependencies).+ */+ dependencies: Array<string>;++ /**+ * See [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep).+ */+ grep: RegExp|Array<RegExp>;++ /**+ * See [testProject.grepInvert](https://playwright.dev/docs/api/class-testproject#test-project-grep-invert).+ */+ grepInvert: null|RegExp|Array<RegExp>;++ /**+ * See [testProject.metadata](https://playwright.dev/docs/api/class-testproject#test-project-metadata).+ */+ metadata: Metadata;++ /**+ * See [testProject.name](https://playwright.dev/docs/api/class-testproject#test-project-name).+ */+ name: string;++ /**+ * See [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir).+ */+ outputDir: string;++ /**+ * See [testProject.repeatEach](https://playwright.dev/docs/api/class-testproject#test-project-repeat-each).+ */+ repeatEach: number;++ /**+ * See [testProject.retries](https://playwright.dev/docs/api/class-testproject#test-project-retries).+ */+ retries: number;++ /**+ * See [testProject.snapshotDir](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-dir).+ */+ snapshotDir: string;++ /**+ * See [testProject.teardown](https://playwright.dev/docs/api/class-testproject#test-project-teardown).+ */+ teardown?: string;++ /**+ * See [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir).+ */+ testDir: string;++ /**+ * See [testProject.testIgnore](https://playwright.dev/docs/api/class-testproject#test-project-test-ignore).+ */+ testIgnore: string|RegExp|Array<string|RegExp>;++ /**+ * See [testProject.testMatch](https://playwright.dev/docs/api/class-testproject#test-project-test-match).+ */+ testMatch: string|RegExp|Array<string|RegExp>;++ /**+ * See [testProject.timeout](https://playwright.dev/docs/api/class-testproject#test-project-timeout).+ */+ timeout: number;+}/*** `Suite` is a group of tests. All tests in Playwright Test form the following hierarchy:- * - Root suite has a child suite for each {@link TestProject}.+ * - Root suite has a child suite for each {@link FullProject}.* - Project suite #1. Has a child suite for each test file in the project.* - File suite #1* - {@link TestCase} #1@@ -45,10 +254,6 @@ export interface Suite {* -> ...`describe` -> `test`.*/type: 'root' | 'project' | 'file' | 'describe';- /**- * Configuration of the project this suite belongs to, or [void] for the root suite.- */- project(): FullProject | undefined;/*** Returns the list of all test cases in this suite and its descendants, as opposite to* [suite.tests](https://playwright.dev/docs/api/class-suite#suite-tests).@@ -63,6 +268,11 @@ export interface Suite {*/entries(): Array<TestCase|Suite>;+ /**+ * Configuration of the project this suite belongs to, or [void] for the root suite.+ */+ project(): FullProject|undefined;+/*** Returns a list of titles from the root down to this suite.*/@@ -454,13 +664,6 @@ export interface FullResult {* [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin).*/export interface Reporter {- /**- * Called once before running tests. All tests have been already discovered and put into a hierarchy of {@link- * Suite}s.- * @param config Resolved configuration.- * @param suite The root suite that contains all projects, files and test cases.- */- onBegin?(config: FullConfig, suite: Suite): void;/*** Called after all tests have been run, or testing has been interrupted. Note that this method may return a [Promise]* and Playwright Test will await it. Reporter is allowed to override the status and hence affect the exit code of the@@ -474,6 +677,14 @@ export interface Reporter {* - `'interrupted'` - Interrupted by the user.*/onEnd?(result: FullResult): Promise<{ status?: FullResult['status'] } | undefined | void> | void;+ /**+ * Called once before running tests. All tests have been already discovered and put into a hierarchy of {@link+ * Suite}s.+ * @param config Resolved configuration.+ * @param suite The root suite that contains all projects, files and test cases.+ */+ onBegin?(config: FullConfig, suite: Suite): void;+/*** Called on some global error, for example unhandled exception in the worker process.* @param error The error.diff --git a/tests/playwright-test/global-setup.spec.ts b/tests/playwright-test/global-setup.spec.tsindex 3d28be82cd..bcb9013387 100644--- a/tests/playwright-test/global-setup.spec.ts+++ b/tests/playwright-test/global-setup.spec.ts@@ -280,8 +280,8 @@ const authFiles = {export default config;`,'auth.ts': `- import { chromium, FullConfig } from '@playwright/test';- async function globalSetup(config: FullConfig) {+ import { chromium, ConfigInWorker } from '@playwright/test';+ async function globalSetup(config: ConfigInWorker) {const { baseURL, storageState } = config.projects[0].use;const browser = await chromium.launch();const page = await browser.newPage();diff --git a/utils/doclint/generateFullConfigDoc.js b/utils/doclint/generateFullConfigDoc.jsnew file mode 100644index 0000000000..8c00f7f8a2--- /dev/null+++ b/utils/doclint/generateFullConfigDoc.js@@ -0,0 +1,121 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// @ts-check++const path = require('path');+const fs = require('fs');+const PROJECT_DIR = path.join(__dirname, '..', '..');++function generateFullConfigClass(fromClassName, toClassName, allowList) {+ const allowedNames = new Set(allowList);++ const content = fs.readFileSync(path.join(PROJECT_DIR, `docs/src/test-api/class-${fromClassName.toLowerCase()}.md`)).toString();+ let sections = content.split('\n## ');+ sections = filterAllowedSections(sections, allowedNames);+ if (allowedNames.size)+ console.log(`Undocumented properties for ${fromClassName}:\n ${[...allowedNames].join('\n ')}`);+ sections = changeClassName(sections, fromClassName, toClassName);+ sections = replacePropertyDescriptions(sections, fromClassName);+ const fullconfig = sections.join('\n## ');+ fs.writeFileSync(path.join(PROJECT_DIR, `docs/src/test-api/class-${toClassName.toLowerCase()}.md`), fullconfig);+}++function propertyNameFromSection(section) {+ section = section.split('\n')[0];+ const match = /\.(\w+)/.exec(section);+ if (!match)+ return null;+ return match[1];+}++function filterAllowedSections(sections, allowedNames) {+ return sections.filter(section => {+ section = section.split('\n')[0];+ const name = propertyNameFromSection(section);+ if (!name)+ return true;+ return allowedNames.delete(name);+ });+}++function changeClassName(sections, from, to) {+ return sections.map(section => {+ const lines = section.split('\n');+ lines[0] = lines[0].replace(from, to);+ return lines.join('\n');+ });+}++function replacePropertyDescriptions(sections, configClassName) {+ return sections.map(section => {+ const parts = section.split('\n\n');+ section = parts[0];+ const name = propertyNameFromSection(section);+ if (!name)+ return `${section}\n`;+ return `${section}\n\nSee [\`property: ${configClassName}.${name}\`].\n`;+ });+}++function generateFullConfig() {+ generateFullConfigClass('TestConfig', 'FullConfig', [+ 'forbidOnly',+ 'fullyParallel',+ 'globalSetup',+ 'globalTeardown',+ 'globalTimeout',+ 'grep',+ 'grepInvert',+ 'maxFailures',+ 'metadata',+ 'version',+ 'preserveOutput',+ 'projects',+ 'reporter',+ 'reportSlowTests',+ 'rootDir',+ 'quiet',+ 'shard',+ 'updateSnapshots',+ 'workers',+ 'webServer',+ 'configFile',+ ]);+}++function generateFullProject() {+ generateFullConfigClass('TestProject', 'FullProject', [+ 'grep',+ 'grepInvert',+ 'metadata',+ 'name',+ 'dependencies',+ 'snapshotDir',+ 'outputDir',+ 'repeatEach',+ 'retries',+ 'teardown',+ 'testDir',+ 'testIgnore',+ 'testMatch',+ 'timeout',+ 'use',+ ]);+}++generateFullConfig();+generateFullProject();diff --git a/utils/generate_types/index.js b/utils/generate_types/index.jsindex e16f6df772..06863d9c9f 100644--- a/utils/generate_types/index.js+++ b/utils/generate_types/index.js@@ -553,9 +553,7 @@ class TypesGenerator {overridesToDocsClassMapping: new Map([['TestType', 'Test'],['Config', 'TestConfig'],- ['FullConfig', 'TestConfig'],['Project', 'TestProject'],- ['FullProject', 'TestProject'],['PlaywrightWorkerOptions', 'TestOptions'],['PlaywrightTestOptions', 'TestOptions'],['PlaywrightWorkerArgs', 'Fixtures'],@@ -563,9 +561,6 @@ class TypesGenerator {['AsymmetricMatchers', 'GenericAssertions'],]),ignoreMissing: new Set([- 'FullConfig.configFile',- 'FullConfig.version',- 'FullConfig.rootDir','SuiteFunction','TestFunction','PlaywrightWorkerOptions.defaultBrowserType',diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.tsindex 9ace4f70cc..a10938a49a 100644--- a/utils/generate_types/overrides-test.d.ts+++ b/utils/generate_types/overrides-test.d.ts@@ -29,33 +29,15 @@ export type ReporterDescription =['null'] |[string] | [string, any];-type UseOptions<TestArgs, WorkerArgs> = { [K in keyof WorkerArgs]?: WorkerArgs[K] } & { [K in keyof TestArgs]?: TestArgs[K] };+type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;export interface Project<TestArgs = {}, WorkerArgs = {}> extends TestProject {use?: UseOptions<TestArgs, WorkerArgs>;}-// [internal] !!! DO NOT ADD TO THIS !!!-// [internal] It is part of the public API and is computed from the user's config.-// [internal] If you need new fields internally, add them to FullProjectInternal instead.-export interface FullProject<TestArgs = {}, WorkerArgs = {}> {- grep: RegExp | RegExp[];- grepInvert: RegExp | RegExp[] | null;- metadata: Metadata;- name: string;- dependencies: string[];- snapshotDir: string;- outputDir: string;- repeatEach: number;- retries: number;- teardown?: string;- testDir: string;- testIgnore: string | RegExp | (string | RegExp)[];- testMatch: string | RegExp | (string | RegExp)[];- timeout: number;+export interface ProjectInWorker<TestArgs = {}, WorkerArgs = {}> {use: UseOptions<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;}-// [internal] !!! DO NOT ADD TO THIS !!! See prior note.type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });@@ -71,46 +53,14 @@ export interface Config<TestArgs = {}, WorkerArgs = {}> extends TestConfig {export type Metadata = { [key: string]: any };-// [internal] !!! DO NOT ADD TO THIS !!!-// [internal] It is part of the public API and is computed from the user's config.-// [internal] If you need new fields internally, add them to FullConfigInternal instead.-export interface FullConfig<TestArgs = {}, WorkerArgs = {}> {- forbidOnly: boolean;- fullyParallel: boolean;- globalSetup: string | null;- globalTeardown: string | null;- globalTimeout: number;- grep: RegExp | RegExp[];- grepInvert: RegExp | RegExp[] | null;- maxFailures: number;- metadata: Metadata;- version: string;- preserveOutput: 'always' | 'never' | 'failures-only';- projects: FullProject<TestArgs, WorkerArgs>[];+export interface ConfigInWorker<TestArgs = {}, WorkerArgs = {}> {+ projects: ProjectInWorker<TestArgs, WorkerArgs>[];reporter: ReporterDescription[];- reportSlowTests: { max: number, threshold: number } | null;- rootDir: string;- quiet: boolean;- shard: { total: number, current: number } | null;- updateSnapshots: 'all' | 'none' | 'missing';- workers: number;webServer: TestConfigWebServer | null;- configFile?: string;- // [internal] !!! DO NOT ADD TO THIS !!! See prior note.}export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped' | 'interrupted';-export interface WorkerInfo {- config: FullConfig;- project: FullProject;-}--export interface TestInfo {- config: FullConfig;- project: FullProject;-}-type TestDetailsAnnotation = {type: string;description?: string;diff --git a/utils/generate_types/overrides-testReporter.d.ts b/utils/generate_types/overrides-testReporter.d.tsindex 8faa956928..129faf30fc 100644--- a/utils/generate_types/overrides-testReporter.d.ts+++ b/utils/generate_types/overrides-testReporter.d.ts@@ -14,12 +14,23 @@* limitations under the License.*/-import type { FullConfig, FullProject, TestStatus, Metadata } from './test';-export type { FullConfig, TestStatus, FullProject } from './test';+import type { TestStatus, Metadata, PlaywrightTestOptions, PlaywrightWorkerOptions, ReporterDescription, ConfigInWorker } from './test';+export type { TestStatus } from './test';++type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;++export interface FullConfig<TestArgs = {}, WorkerArgs = {}> {+ projects: FullProject<TestArgs, WorkerArgs>[];+ reporter: ReporterDescription[];+ webServer: ConfigInWorker['webServer'];+}++export interface FullProject<TestArgs = {}, WorkerArgs = {}> {+ use: UseOptions<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;+}export interface Suite {type: 'root' | 'project' | 'file' | 'describe';- project(): FullProject | undefined;}export interface TestCase {@@ -56,7 +67,6 @@ export interface FullResult {}export interface Reporter {- onBegin?(config: FullConfig, suite: Suite): void;onEnd?(result: FullResult): Promise<{ status?: FullResult['status'] } | undefined | void> | void;}