-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): support playwright persistent context #9229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ebb1288
5a71b60
f935feb
ed26cda
2b9c375
4f5a594
7d89e16
d4de468
88b03e2
a03baa7
d036a17
b81927b
e09644b
244f151
a68e687
bc61965
2ab69b7
b2d883d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,3 +104,35 @@ await userEvent.click(page.getByRole('button'), { | |||||||||||||||||||||||||||||||||||||||||||||
| timeout: 1_000, | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| ## `persistentContext` | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| - **Type:** `boolean | string` | ||||||||||||||||||||||||||||||||||||||||||||||
| - **Default:** `false` | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| When enabled, Vitest uses Playwright's [persistent context](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context) instead of a regular browser context. This allows browser state (cookies, localStorage, DevTools settings, etc.) to persist between test runs. | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| ::: warning | ||||||||||||||||||||||||||||||||||||||||||||||
| This option is ignored when [`headless`](/config/browser/headless) is enabled. In headless mode, Vitest runs tests in parallel sessions which is incompatible with persistent context. | ||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it should depend on
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds right, but maybe I saw persistent context with headless didn't work. I'll double check. If it works, we should aim for checking vitest/packages/vitest/src/node/pools/browser.ts Lines 135 to 150 in 7d89e16
vitest/packages/vitest/src/node/pools/browser.ts Lines 242 to 247 in 7d89e16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The note makes it sounds like it's about parallelism. If it's just about headless, we need to clarify that and remove the parallelisation mention I think
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirmed headless works fine. I updated to pass around initial |
||||||||||||||||||||||||||||||||||||||||||||||
| ::: | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| - When set to `true`, the user data is stored in `./node_modules/.cache/vitest-playwright-user-data` | ||||||||||||||||||||||||||||||||||||||||||||||
| - When set to a string, the value is used as the path to the user data directory | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| ```ts [vitest.config.js] | ||||||||||||||||||||||||||||||||||||||||||||||
| import { playwright } from '@vitest/browser-playwright' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { defineConfig } from 'vitest/config' | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export default defineConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||
| test: { | ||||||||||||||||||||||||||||||||||||||||||||||
| browser: { | ||||||||||||||||||||||||||||||||||||||||||||||
| provider: playwright({ | ||||||||||||||||||||||||||||||||||||||||||||||
| persistentContext: true, | ||||||||||||||||||||||||||||||||||||||||||||||
| // or specify a custom directory: | ||||||||||||||||||||||||||||||||||||||||||||||
| // persistentContext: './my-browser-data', | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| instances: [{ browser: 'chromium' }], | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.