docs: add more references to TestInfo.retry (#10472)
This commit is contained in:
parent
eaee864b2c
commit
e647f0420c
|
|
@ -229,6 +229,40 @@ Specifies a unique repeat index when running in "repeat each" mode. This mode is
|
||||||
|
|
||||||
Specifies the retry number when the test is retried after a failure. The first test run has [`property: TestInfo.retry`] equal to zero, the first retry has it equal to one, and so on. Learn more about [retries](./test-retries.md#retries).
|
Specifies the retry number when the test is retried after a failure. The first test run has [`property: TestInfo.retry`] equal to zero, the first retry has it equal to one, and so on. Learn more about [retries](./test-retries.md#retries).
|
||||||
|
|
||||||
|
```js js-flavor=js
|
||||||
|
const { test, expect } = require('@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();
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```js js-flavor=ts
|
||||||
|
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();
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## method: TestInfo.setTimeout
|
## method: TestInfo.setTimeout
|
||||||
|
|
||||||
Changes the timeout for the currently running test. Zero means no timeout. Learn more about [various timeouts](./test-timeouts.md).
|
Changes the timeout for the currently running test. Zero means no timeout. Learn more about [various timeouts](./test-timeouts.md).
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,28 @@ Running 3 tests using 1 worker
|
||||||
2 passed (4s)
|
2 passed (4s)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can detect retries at runtime with [`property: TestInfo.retry`], which is accessible to any test, hook or fixture. Here is an example that clears some server-side state before a retry.
|
||||||
|
|
||||||
|
```js js-flavor=js
|
||||||
|
const { test, expect } = require('@playwright/test');
|
||||||
|
|
||||||
|
test('my test', async ({ page }, testInfo) => {
|
||||||
|
if (testInfo.retry)
|
||||||
|
await cleanSomeCachesOnTheServer();
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```js js-flavor=ts
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
test('my test', async ({ page }, testInfo) => {
|
||||||
|
if (testInfo.retry)
|
||||||
|
await cleanSomeCachesOnTheServer();
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Serial mode
|
## Serial mode
|
||||||
|
|
||||||
Use [`method: Test.describe.serial`] to group dependent tests to ensure they will always run together and in order. If one of the tests fails, all subsequent tests are skipped. All tests in the group are retried together.
|
Use [`method: Test.describe.serial`] to group dependent tests to ensure they will always run together and in order. If one of the tests fails, all subsequent tests are skipped. All tests in the group are retried together.
|
||||||
|
|
|
||||||
18
packages/playwright-test/types/test.d.ts
vendored
18
packages/playwright-test/types/test.d.ts
vendored
|
|
@ -1328,6 +1328,24 @@ export interface TestInfo {
|
||||||
* Specifies the retry number when the test is retried after a failure. The first test run has
|
* 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
|
* [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).
|
* equal to one, and so on. Learn more about [retries](https://playwright.dev/docs/test-retries#retries).
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* 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;
|
retry: number;
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue