Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs: explain how to reset storage state (#26422)

Dmitry Gozman050f26764e2e
diff --git a/docs/src/auth.md b/docs/src/auth.md
index f57a64e955..fb3251ec72 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 1515e1656d..ff791113ba 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 843f337fd5..b737cf16fa 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;
/**