Skip to content

Commit

Permalink
docs: explain how to reset storage state (#26422)
Browse files Browse the repository at this point in the history
References #26374.
  • Loading branch information
dgozman authored Aug 10, 2023
1 parent c37dfb3 commit 050f267
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/src/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
// ...
});
```
15 changes: 15 additions & 0 deletions docs/src/test-api/class-testoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions packages/playwright-test/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down

0 comments on commit 050f267

Please sign in to comment.