docs: add more references to TestInfo.retry (#10472)

This commit is contained in:
Dmitry Gozman 2021-11-22 10:06:20 -08:00 committed by GitHub
parent eaee864b2c
commit e647f0420c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 0 deletions

View file

@ -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).

View file

@ -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.

View file

@ -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;
/** /**