xk6-browser
xk6-browser copied to clipboard
Implement `BrowserContext.storageState([options])`
Add support for BrowserContext.storageState([optins])
, to return storage state for browser context (cookies and origins with local storage).
Relevant links:
- Playwright docs: https://playwright.dev/docs/api/class-browsercontext#browser-context-storage-state
- xk6-browser code starting point: https://github.com/grafana/xk6-browser/blob/main/common/browser_context.go#L286
- Playwright code: https://github.com/microsoft/playwright/blob/master/src/server/browserContext.ts#L328
- Playwright tests: https://github.com/microsoft/playwright/blob/master/tests/browsercontext-storage-state.spec.ts
I will really appreciate this feature.
Hi @pablotdv, could you tell us how you would use it and what benefit you would get from it? Thanks!
When this will come ore how I can not get item from session storage from browser?
Hi @mikoca, can you tell us about your use case if it's OK?
Hi @mikoca, can you tell us about your use case if it's OK?
I did like this: page.evaluate(() => window.sessionStorage.getItem('access_token'));
Hi @mikoca, can you tell us about your use case if it's OK?
And I need pass token to another scenario. I will get token from first test, and then I need pas token to second scenario or second test. How I can pass this token from first browser test?
@mikoca Thanks for the example. You save the access token in the browser process to preserve the token between test runs. Assuming you have the same token between all test runs, you could pass the token to each test. I believe you're receiving a different token on a prior test run dynamically.
@inancgumus I have an application that relies heavily on the local storage to set/get certain values.
I wanted to setup k6 with a hybrid approach. My protocol tests are working great. But when running the browser tests i keep bumping into the issue that i can't set my local storage. The application is expecting certain key's to be present to work correctly.
Could you point me in the right direction? Or is there a best practise when writing such tests?
Hi @jmalfait, we don't currently support local storage. I'll bring this to the team's attention.