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

References #26374.
This commit is contained in:
Dmitry Gozman 2023-08-10 16:32:45 -07:00 committed by GitHub
parent c37dfb379b
commit 050f26764e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions

View File

@ -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 }) => {
// ...
});
```

View File

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

View File

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