From 050f26764e2e175615414c8a237d396b6ce6e146 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 10 Aug 2023 16:32:45 -0700 Subject: [PATCH] docs: explain how to reset storage state (#26422) References #26374. --- docs/src/auth.md | 16 ++++++++++++++++ docs/src/test-api/class-testoptions.md | 15 +++++++++++++++ packages/playwright-test/types/test.d.ts | 16 ++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/docs/src/auth.md b/docs/src/auth.md index f57a64e955dda..fb3251ec72d23 100644 --- a/docs/src/auth.md +++ b/docs/src/auth.md @@ -654,3 +654,19 @@ await context.AddInitScriptAsync(@"(storage => { } })('" + loadedSessionStorage + "')"); ``` + +### Avoid authentication in some tests +* langs: js + +You can reset storage state in a test file to avoid authentication that was set up for the whole project. + +```js title="not-signed-in.spec.ts" +import { test } from '@playwright/test'; + +// Reset storage state for this file to avoid being authenticated +test.use({ storageState: { cookies: [], origins: [] } }); + +test('not signed in test', async ({ page }) => { + // ... +}); +``` diff --git a/docs/src/test-api/class-testoptions.md b/docs/src/test-api/class-testoptions.md index 1515e1656d86e..ff791113bafc8 100644 --- a/docs/src/test-api/class-testoptions.md +++ b/docs/src/test-api/class-testoptions.md @@ -492,6 +492,21 @@ export default defineConfig({ }); ``` +**Details** + +When storage state is set up in the config, it is possible to reset storage state for a file: + +```js title="not-signed-in.spec.ts" +import { test } from '@playwright/test'; + +// Reset storage state for this file to avoid being authenticated +test.use({ storageState: { cookies: [], origins: [] } }); + +test('not signed in test', async ({ page }) => { + // ... +}); +``` + ## property: TestOptions.testIdAttribute * since: v1.27 diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index 843f337fd5b6c..b737cf16fa443 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -4012,6 +4012,22 @@ export interface PlaywrightTestOptions { * }); * ``` * + * **Details** + * + * When storage state is set up in the config, it is possible to reset storage state for a file: + * + * ```js + * // not-signed-in.spec.ts + * import { test } from '@playwright/test'; + * + * // Reset storage state for this file to avoid being authenticated + * test.use({ storageState: { cookies: [], origins: [] } }); + * + * test('not signed in test', async ({ page }) => { + * // ... + * }); + * ``` + * */ storageState: StorageState | undefined; /**