docs: remove overloads from test.* APIs (#29376)

This commit is contained in:
Dmitry Gozman 2024-02-05 19:03:04 -08:00 committed by GitHub
parent 286adf3af3
commit fb29d90052
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 1675 additions and 805 deletions

View file

@ -135,7 +135,7 @@ test.describe('Playwright homepage', () => {
1. Each Playwright Test file has explicit import of the `test` and `expect` functions
1. Test function is marked with `async`
1. Playwright Test is given a `page` as one of its parameters. This is one of the many [useful fixtures](./api/class-fixtures) in Playwright Test.
Playwright Test creates an isolated [Page] object for each test. However, if you'd like to reuse a single [Page] object between multiple tests, you can create your own in [`method: Test.beforeAll#1`] and close it in [`method: Test.afterAll#1`].
Playwright Test creates an isolated [Page] object for each test. However, if you'd like to reuse a single [Page] object between multiple tests, you can create your own in [`method: Test.beforeAll`] and close it in [`method: Test.afterAll`].
1. Locator creation with [`method: Page.locator`] is one of the few methods that is sync.
1. Use [assertions](./test-assertions) to verify the state instead of `page.$eval()`.

View file

@ -1110,7 +1110,7 @@ Linux support looks like this:
### 🕵️ Anonymous Describe
It is now possible to call [`method: Test.describe#2`] to create suites without a title. This is useful for giving a group of tests a common option with [`method: Test.use`].
It is now possible to call [`method: Test.describe`] to create suites without a title. This is useful for giving a group of tests a common option with [`method: Test.use`].
```ts
test.describe(() => {

View file

@ -6,10 +6,10 @@ title: "Annotations"
## Introduction
Playwright Test supports test annotations to deal with failures, flakiness, skip, focus and tag tests:
- [`method: Test.skip#1`] marks the test as irrelevant. Playwright Test does not run such a test. Use this annotation when the test is not applicable in some configuration.
- [`method: Test.fail#1`] marks the test as failing. Playwright Test will run this test and ensure it does indeed fail. If the test does not fail, Playwright Test will complain.
- [`method: Test.fixme#1`] marks the test as failing. Playwright Test will not run this test, as opposed to the `fail` annotation. Use `fixme` when running the test is slow or crashes.
- [`method: Test.slow#1`] marks the test as slow and triples the test timeout.
- [`method: Test.skip`] marks the test as irrelevant. Playwright Test does not run such a test. Use this annotation when the test is not applicable in some configuration.
- [`method: Test.fail`] marks the test as failing. Playwright Test will run this test and ensure it does indeed fail. If the test does not fail, Playwright Test will complain.
- [`method: Test.fixme`] marks the test as failing. Playwright Test will not run this test, as opposed to the `fail` annotation. Use `fixme` when running the test is slow or crashes.
- [`method: Test.slow`] marks the test as slow and triples the test timeout.
Annotations can be used on a single test or a group of tests. Annotations can be conditional, in which case they apply when the condition is truthy. Annotations may depend on test fixtures. There could be multiple annotations on the same test, possibly in different configurations.

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
* since: v1.10
* langs: js
`TestInfo` contains information about currently running test. It is available to test functions, [`method: Test.beforeEach#1`], [`method: Test.afterEach#1`], [`method: Test.beforeAll#1`] and [`method: Test.afterAll#1`] 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.
`TestInfo` contains information about currently running test. It is available to test functions, [`method: Test.beforeEach`], [`method: Test.afterEach`], [`method: Test.beforeAll`] and [`method: Test.afterAll`] 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';
@ -20,7 +20,7 @@ test('basic test', async ({ page }, testInfo) => {
- `type` <[string]> Annotation type, for example `'skip'` or `'fail'`.
- `description` ?<[string]> Optional description.
The list of annotations applicable to the current test. Includes annotations from the test, annotations from all [`method: Test.describe#1`] groups the test belongs to and file-level annotations for the test file.
The list of annotations applicable to the current test. Includes annotations from the test, annotations from all [`method: Test.describe`] groups the test belongs to and file-level annotations for the test file.
Learn more about [test annotations](../test-annotations.md).
@ -115,7 +115,7 @@ Processed configuration from the [configuration file](../test-configuration.md).
* since: v1.10
- type: <[int]>
The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or not. Can be used in [`method: Test.afterEach#1`] hook.
The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or not. Can be used in [`method: Test.afterEach`] hook.
## property: TestInfo.error
@ -137,8 +137,8 @@ Errors thrown during test execution, if any.
- type: <[TestStatus]<"passed"|"failed"|"timedOut"|"skipped"|"interrupted">>
Expected status for the currently running test. This is usually `'passed'`, except for a few cases:
* `'skipped'` for skipped tests, e.g. with [`method: Test.skip#2`];
* `'failed'` for tests marked as failed with [`method: Test.fail#1`].
* `'skipped'` for skipped tests, e.g. with [`method: Test.skip`];
* `'failed'` for tests marked as failed with [`method: Test.fail`].
Expected status is usually compared with the actual [`property: TestInfo.status`]:
@ -154,12 +154,12 @@ test.afterEach(async ({}, testInfo) => {
## method: TestInfo.fail#1
* since: v1.10
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 [`method: Test.fail#1`].
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 [`method: Test.fail`].
## method: TestInfo.fail#2
* since: v1.10
Conditionally mark the currently running test as "should fail" with an optional description. This is similar to [`method: Test.fail#2`].
Conditionally mark the currently running test as "should fail" with an optional description. This is similar to [`method: Test.fail`].
### param: TestInfo.fail#2.condition
* since: v1.10
@ -184,12 +184,12 @@ Absolute path to a file where the currently running test is declared.
## method: TestInfo.fixme#1
* since: v1.10
Mark a test as "fixme", with the intention to fix it. Test is immediately aborted. This is similar to [`method: Test.fixme#2`].
Mark a test as "fixme", with the intention to fix it. Test is immediately aborted. This is similar to [`method: Test.fixme`].
## method: TestInfo.fixme#2
* since: v1.10
Conditionally mark the currently running test as "fixme" with an optional description. This is similar to [`method: Test.fixme#3`].
Conditionally mark the currently running test as "fixme" with an optional description. This is similar to [`method: Test.fixme`].
### param: TestInfo.fixme#2.condition
* since: v1.10
@ -330,12 +330,12 @@ Timeout in milliseconds.
## method: TestInfo.skip#1
* since: v1.10
Unconditionally skip the currently running test. Test is immediately aborted. This is similar to [`method: Test.skip#2`].
Unconditionally skip the currently running test. Test is immediately aborted. This is similar to [`method: Test.skip`].
## method: TestInfo.skip#2
* since: v1.10
Conditionally skips the currently running test with an optional description. This is similar to [`method: Test.skip#3`].
Conditionally skips the currently running test with an optional description. This is similar to [`method: Test.skip`].
### param: TestInfo.skip#2.condition
* since: v1.10
@ -353,12 +353,12 @@ Optional description that will be reflected in a test report.
## method: TestInfo.slow#1
* since: v1.10
Marks the currently running test as "slow", giving it triple the default timeout. This is similar to [`method: Test.slow#1`].
Marks the currently running test as "slow", giving it triple the default timeout. This is similar to [`method: Test.slow`].
## method: TestInfo.slow#2
* since: v1.10
Conditionally mark the currently running test as "slow" with an optional description, giving it triple the default timeout. This is similar to [`method: Test.slow#2`].
Conditionally mark the currently running test as "slow" with an optional description, giving it triple the default timeout. This is similar to [`method: Test.slow`].
### param: TestInfo.slow#2.condition
* since: v1.10
@ -403,7 +403,7 @@ Suffix used to differentiate snapshots between multiple test configurations. For
* since: v1.10
- type: ?<[TestStatus]<"passed"|"failed"|"timedOut"|"skipped"|"interrupted">>
Actual status for the currently running test. Available after the test has finished in [`method: Test.afterEach#1`] hook and fixtures.
Actual status for the currently running test. Available after the test has finished in [`method: Test.afterEach`] hook and fixtures.
Status is usually compared with the [`property: TestInfo.expectedStatus`]:

View file

@ -9,7 +9,7 @@
* File suite #1
* [TestCase] #1
* [TestCase] #2
* Suite corresponding to a [`method: Test.describe#1`] group
* Suite corresponding to a [`method: Test.describe`] group
* [TestCase] #1 in a group
* [TestCase] #2 in a group
* < more test cases ... >
@ -54,7 +54,7 @@ Child suites. See [Suite] for the hierarchy of suites.
* since: v1.10
- type: <[Array]<[TestCase]>>
Test cases in the suite. Note that only test cases defined directly in this suite are in the list. Any test cases defined in nested [`method: Test.describe#1`] groups are listed
Test cases in the suite. Note that only test cases defined directly in this suite are in the list. Any test cases defined in nested [`method: Test.describe`] groups are listed
in the child [`property: Suite.suites`].
## property: Suite.title
@ -65,7 +65,7 @@ Suite title.
* Empty for root suite.
* Project name for project suite.
* File path for file suite.
* Title passed to [`method: Test.describe#1`] for a group suite.
* Title passed to [`method: Test.describe`] for a group suite.
## method: Suite.titlePath
* since: v1.10

View file

@ -10,7 +10,7 @@
- `type` <[string]> Annotation type, for example `'skip'` or `'fail'`.
- `description` ?<[string]> Optional description.
The list of annotations applicable to the current test. Includes annotations from the test, annotations from all [`method: Test.describe#1`] groups the test belongs to and file-level annotations for the test file.
The list of annotations applicable to the current test. Includes annotations from the test, annotations from all [`method: Test.describe`] groups the test belongs to and file-level annotations for the test file.
Annotations are available during test execution through [`property: TestInfo.annotations`].
@ -21,8 +21,8 @@ Learn more about [test annotations](../test-annotations.md).
- type: <[TestStatus]<"passed"|"failed"|"timedOut"|"skipped"|"interrupted">>
Expected test status.
* Tests marked as [`method: Test.skip#1`] or [`method: Test.fixme#1`] are expected to be `'skipped'`.
* Tests marked as [`method: Test.fail#1`] are expected to be `'failed'`.
* Tests marked as [`method: Test.skip`] or [`method: Test.fixme`] are expected to be `'skipped'`.
* Tests marked as [`method: Test.fail`] are expected to be `'failed'`.
* Other tests are expected to be `'passed'`.
See also [`property: TestResult.status`] for the actual status.
@ -83,7 +83,7 @@ Learn more about [test retries](../test-retries.md#retries).
* since: v1.10
- type: <[float]>
The timeout given to the test. Affected by [`property: TestConfig.timeout`], [`property: TestProject.timeout`], [`method: Test.setTimeout`], [`method: Test.slow#1`] and [`method: TestInfo.setTimeout`].
The timeout given to the test. Affected by [`property: TestConfig.timeout`], [`property: TestProject.timeout`], [`method: Test.setTimeout`], [`method: Test.slow`] and [`method: TestInfo.setTimeout`].
## property: TestCase.title
* since: v1.10

View file

@ -169,7 +169,7 @@ It is usually better to make your tests isolated, so they can be efficiently run
## Reuse single page between tests
Playwright Test creates an isolated [Page] object for each test. However, if you'd like to reuse a single [Page] object between multiple tests, you can create your own in [`method: Test.beforeAll#1`] and close it in [`method: Test.afterAll#1`].
Playwright Test creates an isolated [Page] object for each test. However, if you'd like to reuse a single [Page] object between multiple tests, you can create your own in [`method: Test.beforeAll`] and close it in [`method: Test.afterAll`].
```js tab=js-js title="example.spec.js"
// @ts-check

View file

@ -54,7 +54,7 @@ test('very slow test', async ({ page }) => {
});
```
API reference: [`method: Test.setTimeout`] and [`method: Test.slow#1`].
API reference: [`method: Test.setTimeout`] and [`method: Test.slow`].
### Change timeout from a `beforeEach` hook

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,7 @@ export type { FullConfig, TestStatus } from './test';
* - {@link TestCase} #1
* - {@link TestCase} #2
* - Suite corresponding to a
* [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1) group
* [test.describe([title, callback])](https://playwright.dev/docs/api/class-test#test-describe) group
* - {@link TestCase} #1 in a group
* - {@link TestCase} #2 in a group
* - < more test cases ... >
@ -71,7 +71,7 @@ export interface Suite {
/**
* Test cases in the suite. Note that only test cases defined directly in this suite are in the list. Any test cases
* defined in nested [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1)
* defined in nested [test.describe([title, callback])](https://playwright.dev/docs/api/class-test#test-describe)
* groups are listed in the child [suite.suites](https://playwright.dev/docs/api/class-suite#suite-suites).
*/
tests: Array<TestCase>;
@ -81,27 +81,29 @@ export interface Suite {
* - Empty for root suite.
* - Project name for project suite.
* - File path for file suite.
* - Title passed to [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe-1)
* - Title passed to [test.describe([title, callback])](https://playwright.dev/docs/api/class-test#test-describe)
* for a group suite.
*/
title: string;
}
/**
* `TestCase` corresponds to every
* [test.(call)(title, testFunction)](https://playwright.dev/docs/api/class-test#test-call) call in a test file. When
* a single [test.(call)(title, testFunction)](https://playwright.dev/docs/api/class-test#test-call) is running in
* multiple projects or repeated multiple times, it will have multiple `TestCase` objects in corresponding projects'
* suites.
* `TestCase` corresponds to every [test.(call)(title, body)](https://playwright.dev/docs/api/class-test#test-call)
* call in a test file. When a single [test.(call)(title, body)](https://playwright.dev/docs/api/class-test#test-call)
* is running in multiple projects or repeated multiple times, it will have multiple `TestCase` objects in
* corresponding projects' suites.
*/
export interface TestCase {
/**
* Expected test status.
* - Tests marked as [test.skip(title, testFunction)](https://playwright.dev/docs/api/class-test#test-skip-1) or
* [test.fixme(title, testFunction)](https://playwright.dev/docs/api/class-test#test-fixme-1) are expected to be
* `'skipped'`.
* - Tests marked as [test.fail()](https://playwright.dev/docs/api/class-test#test-fail-1) are expected to be
* `'failed'`.
* - Tests marked as
* [test.skip([title, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip)
* or
* [test.fixme([title, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme)
* are expected to be `'skipped'`.
* - Tests marked as
* [test.fail([title, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail)
* are expected to be `'failed'`.
* - Other tests are expected to be `'passed'`.
*
* See also [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status) for the actual
@ -128,7 +130,7 @@ export interface TestCase {
/**
* 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
* [test.describe([title, callback])](https://playwright.dev/docs/api/class-test#test-describe) groups the test
* belongs to and file-level annotations for the test file.
*
* Annotations are available during test execution through
@ -187,14 +189,13 @@ export interface TestCase {
* [testConfig.timeout](https://playwright.dev/docs/api/class-testconfig#test-config-timeout),
* [testProject.timeout](https://playwright.dev/docs/api/class-testproject#test-project-timeout),
* [test.setTimeout(timeout)](https://playwright.dev/docs/api/class-test#test-set-timeout),
* [test.slow()](https://playwright.dev/docs/api/class-test#test-slow-1) and
* [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow) and
* [testInfo.setTimeout(timeout)](https://playwright.dev/docs/api/class-testinfo#test-info-set-timeout).
*/
timeout: number;
/**
* Test title as passed to the
* [test.(call)(title, testFunction)](https://playwright.dev/docs/api/class-test#test-call) call.
* Test title as passed to the [test.(call)(title, body)](https://playwright.dev/docs/api/class-test#test-call) call.
*/
title: string;
}

View file

@ -98,7 +98,7 @@ class TypesGenerator {
}, (className, methodName, overloadIndex) => {
if (className === 'SuiteFunction' && methodName === '__call') {
const cls = this.documentation.classes.get('Test');
const method = cls.membersArray.find(m => m.alias === 'describe' && m.overloadIndex === overloadIndex);
const method = cls.membersArray.find(m => m.alias === 'describe');
return this.memberJSDOC(method, ' ').trimLeft();
}

View file

@ -142,10 +142,10 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue
fixme(): void;
fixme(condition: boolean, description?: string): void;
fixme(callback: (args: TestArgs & WorkerArgs) => boolean, description?: string): void;
fail(): void;
fail(title: string, testFunction: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<void> | void): void;
fail(condition: boolean, description?: string): void;
fail(callback: (args: TestArgs & WorkerArgs) => boolean, description?: string): void;
fail(title: string, testFunction: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<void> | void): void;
fail(): void;
slow(): void;
slow(condition: boolean, description?: string): void;
slow(callback: (args: TestArgs & WorkerArgs) => boolean, description?: string): void;