[Question] Persist Auth from Session Storage?
See original GitHub issueI have seen the docs on this: https://playwright.dev/docs/auth#session-storage.
However, I am a bit lost at the location I should add the hook for addInitScript
.
I have tried adding it in: beforeAll
, the test itself, overriding the context fixture. However, none seem to work.
Where would be the proper place to place this hook?
const test = base.extend({
// override `context` fixture to add init script
context: async ({ context }, use) => {
await context.addInitScript(() => {
const entries = JSON.parse(process.env.SESSION_STORAGE);
for (const [key, value] of Object.entries(entries)) {
window.sessionStorage.setItem(key, value);
}
});
await use(context);
},
});
This is the attempt with overriding. If I add a console.log
inside the initScript fn
it doesn’t show anything, if I add it outside, it works.
Also, the session storage seems to have values, it’s just that they are all set on null
. The value from the environmental variable is correct.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to persist to both localStorage and sessionStorage at the ...
My first question is if my client side view and approach is correct or not. If it is, how can I update my...
Read more >Local Storage vs. Session Storage vs. Cookies
In this post, I'll talk about how cookies compare to browser storage. You'll understand why cookies came out, the problem they solve, and...
Read more >ASP.NET Core Blazor state management - Microsoft Learn
sessionStorage is scoped to the browser tab. If the user reloads the tab, the state persists. If the user closes the tab or...
Read more >Storing authentication sessions in external DB
I have a 4 server PF cluster with 1 admin node and 3 engine nodes. Even after modifying the org.sourceid.saml20.service.session.data.impl.
Read more >Web Storage API - MDN Web Docs - Mozilla
sessionStorage maintains a separate storage area for each given origin that's available for the duration of the page session (as long as the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Citronex Not sure if this is best practices, it works. In every test suite I have, on a
beforeAll
I do a login and save the session in an environmental variable as per the docs:Then, to properly load the session on every test, I override the fixture:
The tests then look exactly like the normal tests, but just use the extended test function instead of the one from playwright.
Thanks @taigi100 ! Yeah I’m doing something very similar, the only difference is that my login is inside global-setup.ts. I save the session inside process.env and then override the fixture.