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: add more references to TestInfo.retry (#10472)
Dmitry Gozmane647f0420cda
diff --git a/docs/src/test-api/class-testinfo.md b/docs/src/test-api/class-testinfo.mdindex 2d0a3a2e13..551778e1a5 100644--- a/docs/src/test-api/class-testinfo.md+++ b/docs/src/test-api/class-testinfo.md@@ -229,6 +229,40 @@ Specifies a unique repeat index when running in "repeat each" mode. This mode isSpecifies 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.setTimeoutChanges the timeout for the currently running test. Zero means no timeout. Learn more about [various timeouts](./test-timeouts.md).diff --git a/docs/src/test-retries-js.md b/docs/src/test-retries-js.mdindex a8bbbc42f3..7c150306e5 100644--- a/docs/src/test-retries-js.md+++ b/docs/src/test-retries-js.md@@ -112,6 +112,28 @@ Running 3 tests using 1 worker2 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 modeUse [`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.diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.tsindex 60655dbda1..ccbaa9febb 100644--- a/packages/playwright-test/types/test.d.ts+++ b/packages/playwright-test/types/test.d.ts@@ -1328,6 +1328,24 @@ export interface TestInfo {* 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).+ *+ * ```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;/**