grafana / xk6-browser

k6 extension that adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol
https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/browser/
GNU Affero General Public License v3.0
337 stars 42 forks source link

Implement `BrowserContext.storageState([options])` #7

Open robingustafsson opened 2 years ago

robingustafsson commented 2 years ago

Add support for BrowserContext.storageState([optins]), to return storage state for browser context (cookies and origins with local storage).

Relevant links:

pablotdv commented 11 months ago

I will really appreciate this feature.

inancgumus commented 11 months ago

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

mikoca commented 7 months ago

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

inancgumus commented 7 months ago

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

mikoca commented 7 months ago

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 commented 7 months ago

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?

inancgumus commented 7 months ago

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

jmalfait commented 1 month ago

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

inancgumus commented 1 month ago

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