Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(docs): sort members instead of validating (#20755)

Dmitry Gozman98e2fe184e91
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index a78848f5af..21550c26c0 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -1748,13 +1748,6 @@ export interface Page {
*/
prependListener(event: 'worker', listener: (worker: Worker) => void): this;
- /**
- * @deprecated This property is discouraged. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to
- * test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration
- * with Axe.
- */
- accessibility: Accessibility;
-
/**
* Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
* fires or when the script content was injected into frame.
@@ -1990,13 +1983,6 @@ export interface Page {
*/
context(): BrowserContext;
- /**
- * **NOTE** Only available for Chromium atm.
- *
- * Browser-specific Coverage implementation. See [Coverage] for more details.
- */
- coverage: Coverage;
-
/**
* **NOTE** Use locator-based [locator.dblclick([options])](https://playwright.dev/docs/api/class-locator#locator-dblclick)
* instead. Read more about [locators](https://playwright.dev/docs/locators).
@@ -3194,8 +3180,6 @@ export interface Page {
timeout?: number;
}): Promise<boolean>;
- keyboard: Keyboard;
-
/**
* The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved
* to the element immediately before performing an action, so a series of actions on the same locator can in fact be
@@ -3227,8 +3211,6 @@ export interface Page {
*/
mainFrame(): Frame;
- mouse: Mouse;
-
/**
* Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`.
*/
@@ -3496,15 +3478,6 @@ export interface Page {
waitUntil?: "load"|"domcontentloaded"|"networkidle"|"commit";
}): Promise<null|Response>;
- /**
- * API testing helper associated with this page. This method returns the same instance as
- * [browserContext.request](https://playwright.dev/docs/api/class-browsercontext#browser-context-request) on the
- * page's context. See
- * [browserContext.request](https://playwright.dev/docs/api/class-browsercontext#browser-context-request) for more
- * details.
- */
- request: APIRequestContext;
-
/**
* Routing provides the capability to modify network requests that are made by a page.
*
@@ -4055,8 +4028,6 @@ export interface Page {
*/
title(): Promise<string>;
- touchscreen: Touchscreen;
-
/**
* **NOTE** Use locator-based [locator.type(text[, options])](https://playwright.dev/docs/api/class-locator#locator-type)
* instead. Read more about [locators](https://playwright.dev/docs/locators).
@@ -4620,7 +4591,36 @@ export interface Page {
*
* **NOTE** This does not contain ServiceWorkers
*/
- workers(): Array<Worker>;}
+ workers(): Array<Worker>;
+
+ /**
+ * @deprecated This property is discouraged. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to
+ * test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration
+ * with Axe.
+ */
+ accessibility: Accessibility;
+
+ /**
+ * **NOTE** Only available for Chromium atm.
+ *
+ * Browser-specific Coverage implementation. See [Coverage] for more details.
+ */
+ coverage: Coverage;
+
+ keyboard: Keyboard;
+
+ mouse: Mouse;
+
+ /**
+ * API testing helper associated with this page. This method returns the same instance as
+ * [browserContext.request](https://playwright.dev/docs/api/class-browsercontext#browser-context-request) on the
+ * page's context. See
+ * [browserContext.request](https://playwright.dev/docs/api/class-browsercontext#browser-context-request) for more
+ * details.
+ */
+ request: APIRequestContext;
+
+ touchscreen: Touchscreen;}
/**
* At every point of time, page exposes its current frame tree via the
@@ -7978,11 +7978,6 @@ export interface BrowserContext {
*/
pages(): Array<Page>;
- /**
- * API testing helper associated with this context. Requests made with this API will use context cookies.
- */
- request: APIRequestContext;
-
/**
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once
* route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
@@ -8223,8 +8218,6 @@ export interface BrowserContext {
}>;
}>;
- tracing: Tracing;
-
/**
* Removes a route created with
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route).
@@ -8323,7 +8316,14 @@ export interface BrowserContext {
* Emitted when new service worker is created in the context.
*/
waitForEvent(event: 'serviceworker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise<boolean>, timeout?: number } | ((worker: Worker) => boolean | Promise<boolean>)): Promise<Worker>;
-}
+
+
+ /**
+ * API testing helper associated with this context. Requests made with this API will use context cookies.
+ */
+ request: APIRequestContext;
+
+ tracing: Tracing;}
/**
* The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
@@ -13560,8 +13560,6 @@ export interface AndroidDevice {
*/
info(selector: AndroidSelector): Promise<AndroidElementInfo>;
- input: AndroidInput;
-
/**
* Installs an apk on the device.
* @param file Either a path to the apk file, or apk file content.
@@ -14153,6 +14151,8 @@ export interface AndroidDevice {
* Currently open WebViews.
*/
webViews(): Array<AndroidWebView>;
+
+ input: AndroidInput;
}
export interface AndroidInput {
diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts
index 45528e5491..c621a8ccaf 100644
--- a/packages/playwright-test/types/test.d.ts
+++ b/packages/playwright-test/types/test.d.ts
@@ -879,135 +879,6 @@ interface TestConfig {
*/
outputDir?: string;
- /**
- * **NOTE** Use
- * [testConfig.snapshotPathTemplate](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-path-template)
- * to configure snapshot paths.
- *
- * The base directory, relative to the config file, for snapshot files created with `toMatchSnapshot`. Defaults to
- * [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir).
- *
- * **Usage**
- *
- * ```js
- * // playwright.config.ts
- * import { defineConfig } from '@playwright/test';
- *
- * export default defineConfig({
- * snapshotDir: './snapshots',
- * });
- * ```
- *
- * **Details**
- *
- * The directory for each test can be accessed by
- * [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir) and
- * [testInfo.snapshotPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-path).
- *
- * This path will serve as the base directory for each test file snapshot directory. Setting `snapshotDir` to
- * `'snapshots'`, the [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir)
- * would resolve to `snapshots/a.spec.js-snapshots`.
- */
- snapshotDir?: string;
-
- /**
- * This option configures a template controlling location of snapshots generated by
- * [pageAssertions.toHaveScreenshot(name[, options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1)
- * and
- * [snapshotAssertions.toMatchSnapshot(name[, options])](https://playwright.dev/docs/api/class-snapshotassertions#snapshot-assertions-to-match-snapshot-1).
- *
- * **Usage**
- *
- * ```js
- * // playwright.config.ts
- * import { defineConfig } from '@playwright/test';
- *
- * export default defineConfig({
- * testDir: './tests',
- * snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
- * });
- * ```
- *
- * **Details**
- *
- * The value might include some "tokens" that will be replaced with actual values during test execution.
- *
- * Consider the following file structure:
- *
- * ```
- * playwright.config.ts
- * tests/
- * └── page/
- * └── page-click.spec.ts
- * ```
- *
- * And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call:
- *
- * ```js
- * // page-click.spec.ts
- * import { test, expect } from '@playwright/test';
- *
- * test.describe('suite', () => {
- * test('test should work', async ({ page }) => {
- * await expect(page).toHaveScreenshot(['foo', 'bar', 'baz.png']);
- * });
- * });
- * ```
- *
- * The list of supported tokens:
- * - `{testDir}` - Project's
- * [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir).
- * - Value: `/home/playwright/tests` (absolute path is since `testDir` is resolved relative to directory with
- * config)
- * - `{snapshotDir}` - Project's
- * [testConfig.snapshotDir](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-dir).
- * - Value: `/home/playwright/tests` (since `snapshotDir` is not provided in config, it defaults to `testDir`)
- * - `{platform}` - The value of `process.platform`.
- * - `{projectName}` - Project's file-system-sanitized name, if any.
- * - Value: `''` (empty string).
- * - `{testFileDir}` - Directories in relative path from `testDir` to **test file**.
- * - Value: `page`
- * - `{testFileName}` - Test file name with extension.
- * - Value: `page-click.spec.ts`
- * - `{testFilePath}` - Relative path from `testDir` to **test file**
- * - Value: `page/page-click.spec.ts`
- * - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.
- * - Value: `suite-test-should-work`
- * - `{arg}` - Relative snapshot path **without extension**. These come from the arguments passed to the
- * `toHaveScreenshot()` and `toMatchSnapshot()` calls; if called without arguments, this will be an auto-generated
- * snapshot name.
- * - Value: `foo/bar/baz`
- * - `{ext}` - snapshot extension (with dots)
- * - Value: `.png`
- *
- * Each token can be preceded with a single character that will be used **only if** this token has non-empty value.
- *
- * Consider the following config:
- *
- * ```js
- * // playwright.config.ts
- * import { defineConfig } from '@playwright/test';
- *
- * export default defineConfig({
- * snapshotPathTemplate: '__screenshots__{/projectName}/{testFilePath}/{arg}{ext}',
- * testMatch: 'example.spec.ts',
- * projects: [
- * { use: { browserName: 'firefox' } },
- * { name: 'chromium', use: { browserName: 'chromium' } },
- * ],
- * });
- * ```
- *
- * In this config:
- * 1. First project **does not** have a name, so its snapshots will be stored in
- * `<configDir>/__screenshots__/example.spec.ts/...`.
- * 1. Second project **does** have a name, so its snapshots will be stored in
- * `<configDir>/__screenshots__/chromium/example.spec.ts/..`.
- * 1. Since `snapshotPathTemplate` resolves to relative path, it will be resolved relative to `configDir`.
- * 1. Forward slashes `"/"` can be used as path separators on any platform.
- */
- snapshotPathTemplate?: string;
-
/**
* Whether to preserve test output in the
* [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir). Defaults to
@@ -1161,6 +1032,135 @@ interface TestConfig {
current: number;
};
+ /**
+ * **NOTE** Use
+ * [testConfig.snapshotPathTemplate](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-path-template)
+ * to configure snapshot paths.
+ *
+ * The base directory, relative to the config file, for snapshot files created with `toMatchSnapshot`. Defaults to
+ * [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir).
+ *
+ * **Usage**
+ *
+ * ```js
+ * // playwright.config.ts
+ * import { defineConfig } from '@playwright/test';
+ *
+ * export default defineConfig({
+ * snapshotDir: './snapshots',
+ * });
+ * ```
+ *
+ * **Details**
+ *
+ * The directory for each test can be accessed by
+ * [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir) and
+ * [testInfo.snapshotPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-path).
+ *
+ * This path will serve as the base directory for each test file snapshot directory. Setting `snapshotDir` to
+ * `'snapshots'`, the [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir)
+ * would resolve to `snapshots/a.spec.js-snapshots`.
+ */
+ snapshotDir?: string;
+
+ /**
+ * This option configures a template controlling location of snapshots generated by
+ * [pageAssertions.toHaveScreenshot(name[, options])](https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1)
+ * and
+ * [snapshotAssertions.toMatchSnapshot(name[, options])](https://playwright.dev/docs/api/class-snapshotassertions#snapshot-assertions-to-match-snapshot-1).
+ *
+ * **Usage**
+ *
+ * ```js
+ * // playwright.config.ts
+ * import { defineConfig } from '@playwright/test';
+ *
+ * export default defineConfig({
+ * testDir: './tests',
+ * snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
+ * });
+ * ```
+ *
+ * **Details**
+ *
+ * The value might include some "tokens" that will be replaced with actual values during test execution.
+ *
+ * Consider the following file structure:
+ *
+ * ```
+ * playwright.config.ts
+ * tests/
+ * └── page/
+ * └── page-click.spec.ts
+ * ```
+ *
+ * And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call:
+ *
+ * ```js
+ * // page-click.spec.ts
+ * import { test, expect } from '@playwright/test';
+ *
+ * test.describe('suite', () => {
+ * test('test should work', async ({ page }) => {
+ * await expect(page).toHaveScreenshot(['foo', 'bar', 'baz.png']);
+ * });
+ * });
+ * ```
+ *
+ * The list of supported tokens:
+ * - `{testDir}` - Project's
+ * [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir).
+ * - Value: `/home/playwright/tests` (absolute path is since `testDir` is resolved relative to directory with
+ * config)
+ * - `{snapshotDir}` - Project's
+ * [testConfig.snapshotDir](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-dir).
+ * - Value: `/home/playwright/tests` (since `snapshotDir` is not provided in config, it defaults to `testDir`)
+ * - `{platform}` - The value of `process.platform`.
+ * - `{projectName}` - Project's file-system-sanitized name, if any.
+ * - Value: `''` (empty string).
+ * - `{testFileDir}` - Directories in relative path from `testDir` to **test file**.
+ * - Value: `page`
+ * - `{testFileName}` - Test file name with extension.
+ * - Value: `page-click.spec.ts`
+ * - `{testFilePath}` - Relative path from `testDir` to **test file**
+ * - Value: `page/page-click.spec.ts`
+ * - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.
+ * - Value: `suite-test-should-work`
+ * - `{arg}` - Relative snapshot path **without extension**. These come from the arguments passed to the
+ * `toHaveScreenshot()` and `toMatchSnapshot()` calls; if called without arguments, this will be an auto-generated
+ * snapshot name.
+ * - Value: `foo/bar/baz`
+ * - `{ext}` - snapshot extension (with dots)
+ * - Value: `.png`
+ *
+ * Each token can be preceded with a single character that will be used **only if** this token has non-empty value.
+ *
+ * Consider the following config:
+ *
+ * ```js
+ * // playwright.config.ts
+ * import { defineConfig } from '@playwright/test';
+ *
+ * export default defineConfig({
+ * snapshotPathTemplate: '__screenshots__{/projectName}/{testFilePath}/{arg}{ext}',
+ * testMatch: 'example.spec.ts',
+ * projects: [
+ * { use: { browserName: 'firefox' } },
+ * { name: 'chromium', use: { browserName: 'chromium' } },
+ * ],
+ * });
+ * ```
+ *
+ * In this config:
+ * 1. First project **does not** have a name, so its snapshots will be stored in
+ * `<configDir>/__screenshots__/example.spec.ts/...`.
+ * 1. Second project **does** have a name, so its snapshots will be stored in
+ * `<configDir>/__screenshots__/chromium/example.spec.ts/..`.
+ * 1. Since `snapshotPathTemplate` resolves to relative path, it will be resolved relative to `configDir`.
+ * 1. Forward slashes `"/"` can be used as path separators on any platform.
+ */
+ snapshotPathTemplate?: string;
+
/**
* Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file.
*
@@ -1861,55 +1861,6 @@ export interface TestInfo {
* Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration).
*/
project: FullProject;
- /**
- * The list of annotations applicable to the current test. Includes annotations from the test, annotations from all
- * [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1) 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;
- }>;
-
/**
* 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.
@@ -1963,6 +1914,170 @@ export interface TestInfo {
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()](https://playwright.dev/docs/api/class-test#test-fail-1).
+ */
+ fail(): void;
+
+ /**
+ * Conditionally mark the currently running test as "should fail" with an optional description. This is similar to
+ * [test.fail(condition[, description])](https://playwright.dev/docs/api/class-test#test-fail-2).
+ * @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()](https://playwright.dev/docs/api/class-test#test-fixme-2).
+ */
+ fixme(): void;
+
+ /**
+ * Conditionally mark the currently running test as "fixme" with an optional description. This is similar to
+ * [test.fixme(condition[, description])](https://playwright.dev/docs/api/class-test#test-fixme-3).
+ * @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: Array<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()](https://playwright.dev/docs/api/class-test#test-skip-2).
+ */
+ skip(): void;
+
+ /**
+ * Conditionally skips the currently running test with an optional description. This is similar to
+ * [test.skip(condition[, description])](https://playwright.dev/docs/api/class-test#test-skip-3).
+ * @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()](https://playwright.dev/docs/api/class-test#test-slow-1).
+ */
+ 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[, description])](https://playwright.dev/docs/api/class-test#test-slow-2).
+ * @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: Array<string>): string;
+
+ /**
+ * The list of annotations applicable to the current test. Includes annotations from the test, annotations from all
+ * [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1) 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.
*/
@@ -2007,40 +2122,11 @@ export interface TestInfo {
*/
expectedStatus: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";
- /**
- * 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()](https://playwright.dev/docs/api/class-test#test-fail-1).
- */
- fail(): void;
-
- /**
- * Conditionally mark the currently running test as "should fail" with an optional description. This is similar to
- * [test.fail(condition[, description])](https://playwright.dev/docs/api/class-test#test-fail-2).
- * @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;
-
/**
* Absolute path to a file where the currently running test is declared.
*/
file: string;
- /**
- * Mark a test as "fixme", with the intention to fix it. Test is immediately aborted. This is similar to
- * [test.fixme()](https://playwright.dev/docs/api/class-test#test-fixme-2).
- */
- fixme(): void;
-
- /**
- * Conditionally mark the currently running test as "fixme" with an optional description. This is similar to
- * [test.fixme(condition[, description])](https://playwright.dev/docs/api/class-test#test-fixme-3).
- * @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;
-
/**
* Test function as passed to `test(title, testFunction)`.
*/
@@ -2051,46 +2137,12 @@ export interface TestInfo {
*/
line: 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;
-
/**
* Absolute path to the output directory for this specific test run. Each test run gets its own directory so they
* cannot conflict.
*/
outputDir: string;
- /**
- * 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: Array<string>): 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
@@ -2133,66 +2185,14 @@ export interface TestInfo {
retry: number;
/**
- * 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()](https://playwright.dev/docs/api/class-test#test-skip-2).
- */
- skip(): void;
-
- /**
- * Conditionally skips the currently running test with an optional description. This is similar to
- * [test.skip(condition[, description])](https://playwright.dev/docs/api/class-test#test-skip-3).
- * @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()](https://playwright.dev/docs/api/class-test#test-slow-1).
- */
- 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[, description])](https://playwright.dev/docs/api/class-test#test-slow-2).
- * @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).
+ * Absolute path to the snapshot output directory for this specific test. Each test suite gets its own directory so
+ * they cannot conflict.
*
- * > 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.
+ * This property does not account for the
+ * [testProject.snapshotPathTemplate](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-path-template)
+ * configuration.
*/
- snapshotPath(...pathSegments: Array<string>): string;
+ snapshotDir: string;
/**
* **NOTE** Use of [testInfo.snapshotSuffix](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-suffix)
@@ -4292,27 +4292,27 @@ export {};
*/
interface APIResponseAssertions {
/**
- * Makes the assertion check for the opposite condition. For example, this code tests that the response status is not
- * successful:
+ * Ensures the response status code is within `200..299` range.
+ *
+ * **Usage**
*
* ```js
- * await expect(response).not.toBeOK();
+ * await expect(response).toBeOK();
* ```
*
*/
- not: APIResponseAssertions;
+ toBeOK(): Promise<void>;
/**
- * Ensures the response status code is within `200..299` range.
- *
- * **Usage**
+ * Makes the assertion check for the opposite condition. For example, this code tests that the response status is not
+ * successful:
*
* ```js
- * await expect(response).toBeOK();
+ * await expect(response).not.toBeOK();
* ```
*
*/
- toBeOK(): Promise<void>;
+ not: APIResponseAssertions;
}
/**
@@ -4332,17 +4332,6 @@ interface APIResponseAssertions {
*
*/
interface LocatorAssertions {
- /**
- * Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain
- * text `"error"`:
- *
- * ```js
- * await expect(locator).not.toContainText('error');
- * ```
- *
- */
- not: LocatorAssertions;
-
/**
* Ensures the [Locator] points to a checked input.
*
@@ -4992,6 +4981,17 @@ interface LocatorAssertions {
*/
timeout?: number;
}): Promise<void>;
+
+ /**
+ * Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain
+ * text `"error"`:
+ *
+ * ```js
+ * await expect(locator).not.toContainText('error');
+ * ```
+ *
+ */
+ not: LocatorAssertions;
}
/**
@@ -5011,17 +5011,6 @@ interface LocatorAssertions {
*
*/
interface PageAssertions {
- /**
- * 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;
-
/**
* This function will wait until two consecutive page screenshots yield the same result, and then compare the last
* screenshot with the expectation.
@@ -5284,6 +5273,17 @@ interface PageAssertions {
*/
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;
}
/**
@@ -5653,6 +5653,54 @@ interface TestProject {
*/
name?: string;
+ /**
+ * The output directory for files created during test execution. Defaults to `<package.json-directory>/test-results`.
+ *
+ * This directory is cleaned at the start. When running a test, a unique subdirectory inside the
+ * [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir) is created,
+ * guaranteeing that test running in parallel do not conflict. This directory can be accessed by
+ * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) and
+ * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path).
+ *
+ * Here is an example that uses
+ * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path) to
+ * create a temporary file.
+ *
+ * ```js
+ * import { test, expect } from '@playwright/test';
+ * import fs from 'fs';
+ *
+ * test('example test', async ({}, testInfo) => {
+ * const file = testInfo.outputPath('temporary-file.txt');
+ * await fs.promises.writeFile(file, 'Put some data to the file', 'utf8');
+ * });
+ * ```
+ *
+ * Use [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir) to change this
+ * option for all projects.
+ */
+ outputDir?: string;
+
+ /**
+ * The number of times to repeat each test, useful for debugging flaky tests.
+ *
+ * Use [testConfig.repeatEach](https://playwright.dev/docs/api/class-testconfig#test-config-repeat-each) to change
+ * this option for all projects.
+ */
+ repeatEach?: number;
+
+ /**
+ * The maximum number of retry attempts given to failed tests. Learn more about
+ * [test retries](https://playwright.dev/docs/test-retries#retries).
+ *
+ * Use [test.describe.configure([options])](https://playwright.dev/docs/api/class-test#test-describe-configure) to
+ * change the number of retries for a specific file or a group of tests.
+ *
+ * Use [testConfig.retries](https://playwright.dev/docs/api/class-testconfig#test-config-retries) to change this
+ * option for all projects.
+ */
+ retries?: number;
+
/**
* The base directory, relative to the config file, for snapshot files created with `toMatchSnapshot`. Defaults to
* [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir).
@@ -5765,54 +5813,6 @@ interface TestProject {
*/
snapshotPathTemplate?: string;
- /**
- * The output directory for files created during test execution. Defaults to `<package.json-directory>/test-results`.
- *
- * This directory is cleaned at the start. When running a test, a unique subdirectory inside the
- * [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir) is created,
- * guaranteeing that test running in parallel do not conflict. This directory can be accessed by
- * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) and
- * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path).
- *
- * Here is an example that uses
- * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path) to
- * create a temporary file.
- *
- * ```js
- * import { test, expect } from '@playwright/test';
- * import fs from 'fs';
- *
- * test('example test', async ({}, testInfo) => {
- * const file = testInfo.outputPath('temporary-file.txt');
- * await fs.promises.writeFile(file, 'Put some data to the file', 'utf8');
- * });
- * ```
- *
- * Use [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir) to change this
- * option for all projects.
- */
- outputDir?: string;
-
- /**
- * The number of times to repeat each test, useful for debugging flaky tests.
- *
- * Use [testConfig.repeatEach](https://playwright.dev/docs/api/class-testconfig#test-config-repeat-each) to change
- * this option for all projects.
- */
- repeatEach?: number;
-
- /**
- * The maximum number of retry attempts given to failed tests. Learn more about
- * [test retries](https://playwright.dev/docs/test-retries#retries).
- *
- * Use [test.describe.configure([options])](https://playwright.dev/docs/api/class-test#test-describe-configure) to
- * change the number of retries for a specific file or a group of tests.
- *
- * Use [testConfig.retries](https://playwright.dev/docs/api/class-testconfig#test-config-retries) to change this
- * option for all projects.
- */
- retries?: number;
-
/**
* Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file.
*
diff --git a/packages/playwright-test/types/testReporter.d.ts b/packages/playwright-test/types/testReporter.d.ts
index bc3e732fce..bb39ee50e0 100644
--- a/packages/playwright-test/types/testReporter.d.ts
+++ b/packages/playwright-test/types/testReporter.d.ts
@@ -49,6 +49,11 @@ export interface Suite {
*/
allTests(): Array<TestCase>;
+ /**
+ * Returns a list of titles from the root down to this suite.
+ */
+ titlePath(): Array<string>;
+
/**
* Location in the source where the suite is defined. Missing for root and project suites.
*/
@@ -79,12 +84,7 @@ export interface Suite {
* - Title passed to [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1)
* for a group suite.
*/
- title: string;
-
- /**
- * Returns a list of titles from the root down to this suite.
- */
- titlePath(): Array<string>;}
+ title: string;}
/**
* `TestCase` corresponds to every
@@ -107,6 +107,24 @@ export interface TestCase {
* status.
*/
expectedStatus: TestStatus;
+ /**
+ * Whether the test is considered running fine. Non-ok tests fail the test run with non-zero exit code.
+ */
+ ok(): boolean;
+
+ /**
+ * Testing outcome for this test. Note that outcome is not the same as
+ * [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status):
+ * - Test that is expected to fail and actually fails is `'expected'`.
+ * - Test that passes on a second retry is `'flaky'`.
+ */
+ outcome(): "skipped"|"expected"|"unexpected"|"flaky";
+
+ /**
+ * Returns a list of titles from the root down to this test.
+ */
+ titlePath(): Array<string>;
+
/**
* The list of annotations applicable to the current test. Includes annotations from the test, annotations from all
* [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1) groups the test
@@ -140,19 +158,6 @@ export interface TestCase {
*/
location: Location;
- /**
- * Whether the test is considered running fine. Non-ok tests fail the test run with non-zero exit code.
- */
- ok(): boolean;
-
- /**
- * Testing outcome for this test. Note that outcome is not the same as
- * [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status):
- * - Test that is expected to fail and actually fails is `'expected'`.
- * - Test that passes on a second retry is `'flaky'`.
- */
- outcome(): "skipped"|"expected"|"unexpected"|"flaky";
-
/**
* Suite this test case belongs to.
*/
@@ -190,12 +195,7 @@ export interface TestCase {
* Test title as passed to the
* [test.(call)(title, testFunction)](https://playwright.dev/docs/api/class-test#test-call) call.
*/
- title: string;
-
- /**
- * Returns a list of titles from the root down to this test.
- */
- titlePath(): Array<string>;}
+ title: string;}
/**
* A result of a single [TestCase] run.
@@ -249,6 +249,12 @@ export interface TestResult {
*/
errors: Array<TestError>;
+ /**
+ * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have
+ * a different `parallelIndex`.
+ */
+ parallelIndex: number;
+
/**
* When test is retries multiple times, each retry attempt is given a sequential number.
*
@@ -282,13 +288,7 @@ export interface TestResult {
*
* Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test.
*/
- workerIndex: 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`.
- */
- parallelIndex: number;}
+ workerIndex: number;}
/**
* Result of the full test run.
@@ -546,6 +546,11 @@ export {};
* Represents a location in the source code where [TestCase] or [Suite] is defined.
*/
export interface Location {
+ /**
+ * Column number in the source file.
+ */
+ column: number;
+
/**
* Path to the source file.
*/
@@ -555,17 +560,17 @@ export interface Location {
* Line number in the source file.
*/
line: number;
-
- /**
- * Column number in the source file.
- */
- column: number;
}
/**
* Information about an error thrown during test execution.
*/
export interface TestError {
+ /**
+ * Error location in the source code.
+ */
+ location?: Location;
+
/**
* Error message. Set when [Error] (or its subclass) has been thrown.
*/
@@ -580,17 +585,17 @@ export interface TestError {
* The value that was thrown. Set when anything except the [Error] (or its subclass) has been thrown.
*/
value?: string;
-
- /**
- * Error location in the source code.
- */
- location?: Location;
}
/**
* Represents a step in the [TestRun].
*/
export interface TestStep {
+ /**
+ * Returns a list of step titles from the root step down to this step.
+ */
+ titlePath(): Array<string>;
+
/**
* Step category to differentiate steps with different origin and verbosity. Built-in categories are:
* - `hook` for fixtures and hooks initialization and teardown
@@ -606,14 +611,14 @@ export interface TestStep {
duration: number;
/**
- * Optional location in the source where the step is defined.
+ * Error thrown during the step execution, if any.
*/
- location?: Location;
+ error?: TestError;
/**
- * Error thrown during the step execution, if any.
+ * Optional location in the source where the step is defined.
*/
- error?: TestError;
+ location?: Location;
/**
* Parent step, if any.
@@ -634,11 +639,6 @@ export interface TestStep {
* User-friendly test step title.
*/
title: string;
-
- /**
- * Returns a list of step titles from the root step down to this step.
- */
- titlePath(): Array<string>;
}
diff --git a/utils/doclint/documentation.js b/utils/doclint/documentation.js
index b17546b39e..6f5cd707c2 100644
--- a/utils/doclint/documentation.js
+++ b/utils/doclint/documentation.js
@@ -97,7 +97,7 @@ class Documentation {
*/
copyDocsFromSuperclasses(errors) {
for (const [name, clazz] of this.classes.entries()) {
- clazz.validateOrder(errors, clazz);
+ clazz.sortMembers();
if (!clazz.extends || ['EventEmitter', 'Error', 'Exception', 'RuntimeException'].includes(clazz.extends))
continue;
@@ -317,48 +317,17 @@ class Documentation {
this.membersArray = membersArray;
}
- validateOrder(errors, cls) {
- const members = this.membersArray;
- // Events should go first.
- let eventIndex = 0;
- for (; eventIndex < members.length && members[eventIndex].kind === 'event'; ++eventIndex);
- for (; eventIndex < members.length && members[eventIndex].kind !== 'event'; ++eventIndex);
- if (eventIndex < members.length)
- errors.push(`Events should go first. Event '${members[eventIndex].name}' in class ${cls.name} breaks order`);
-
- // Constructor should be right after events and before all other members.
- const constructorIndex = members.findIndex(member => member.kind === 'method' && member.name === 'constructor');
- if (constructorIndex > 0 && members[constructorIndex - 1].kind !== 'event')
- errors.push(`Constructor of ${cls.name} should go before other methods`);
-
- // Events should be sorted alphabetically.
- for (let i = 0; i < members.length - 1; ++i) {
- const member1 = this.membersArray[i];
- const member2 = this.membersArray[i + 1];
- if (member1.kind !== 'event' || member2.kind !== 'event')
- continue;
- if (member1.name.localeCompare(member2.name, 'en', { sensitivity: 'base' }) > 0)
- errors.push(`Event '${member1.name}' in class ${this.name} breaks alphabetic ordering of events`);
+ sortMembers() {
+ /**
+ * @param {Member} member
+ */
+ function sortKey(member) {
+ return { 'event': 'a', 'method': 'b', 'property': 'c' }[member.kind] + member.alias;
}
- // All other members should be sorted alphabetically.
- for (let i = 0; i < members.length - 1; ++i) {
- const member1 = this.membersArray[i];
- const member2 = this.membersArray[i + 1];
- if (member1.kind === 'event' || member2.kind === 'event')
- continue;
- if (member1.kind === 'method' && member1.name === 'constructor')
- continue;
- if (member1.name.replace(/^\$+/, '$').localeCompare(member2.name.replace(/^\$+/, '$'), 'en', { sensitivity: 'base' }) > 0) {
- let memberName1 = `${this.name}.${member1.name}`;
- if (member1.kind === 'method')
- memberName1 += '()';
- let memberName2 = `${this.name}.${member2.name}`;
- if (member2.kind === 'method')
- memberName2 += '()';
- errors.push(`Bad alphabetic ordering of ${this.name} members: ${memberName1} should go after ${memberName2}`);
- }
- }
+ this.membersArray.sort((m1, m2) => {
+ return sortKey(m1).localeCompare(sortKey(m2), 'en', { sensitivity: 'base' });
+ });
}
/**