xk6-browser icon indicating copy to clipboard operation
xk6-browser copied to clipboard

Implement `BrowserContext.storageState([options])`

Open robingustafsson opened this issue 3 years ago • 9 comments

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

robingustafsson avatar Sep 30 '21 09:09 robingustafsson

I will really appreciate this feature.

pablotdv avatar Oct 06 '23 10:10 pablotdv

Hi @pablotdv, could you tell us how you would use it and what benefit you would get from it? Thanks!

inancgumus avatar Oct 06 '23 10:10 inancgumus

When this will come ore how I can not get item from session storage from browser?

mikoca avatar Jan 30 '24 10:01 mikoca

Hi @mikoca, can you tell us about your use case if it's OK?

inancgumus avatar Jan 30 '24 10:01 inancgumus

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'));

mikoca avatar Jan 30 '24 15:01 mikoca

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 avatar Jan 30 '24 15:01 mikoca

@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 avatar Jan 31 '24 09:01 inancgumus

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

jmalfait avatar Jul 15 '24 20:07 jmalfait

Hi @jmalfait, we don't currently support local storage. I'll bring this to the team's attention.

inancgumus avatar Jul 23 '24 08:07 inancgumus