-
Notifications
You must be signed in to change notification settings - Fork 75
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
question regarding globalSetup and globalTeardown #686
Comments
I have the same question. Comment to follow this thread. |
I'm not sure that i understood this issue correctly. Why can't you use it like this? |
The // global-setup.js
import { globalSetup as playwrightGlobalSetup } from 'jest-playwright-preset';
module.exports = async function globalSetup(globalConfig) {
await playwrightGlobalSetup(globalConfig);
const browserServer = await chromium.launchServer();
const wsEndpoint = browserServer.wsEndpoint();
const browser = await chromium.connect({ wsEndpoint: wsEndpoint });
const page = await browser.newPage();
// your login function
await doLogin(page);
// store authentication data
const storage = await page.context().storageState();
process.env.STORAGE = JSON.stringify(storage);
}; So, in the example you have to specify the browser being used, rather than the one utilized from the Seems to me that the |
@mmarkelov does that provide some clarification? |
I have the same question. |
I understood the problem. It was kind of trick from There is discussion about this here: #611 I can try to find out solution, but it can be complicated. So if you have any thoughts about this, please let me know |
I think that in your module.exports = () => ({
contextOptions: {
storageState: JSON.parse(process.env.STORAGE)
}
}) |
I wrote a blog post about how I approached persistent login using globalSetup. Spent a lot of time going over the documentation in my work to figure this out. Maybe it'll help someone else stumbling on this thread. If there are ways to improve it, I am always open to suggestions. |
I am attempting to utilize
globalSetup
andglobalTeardown
to implement authentication once per suite rather than once per test.In
jest.config
I customize the browsers array via environment variables like soWhat is the proper way to inject the storage state into the currently available browser? The examples in the documentation assume the use of just one browser, chromium.
I saw an example from @mmarkelov that might be relevant but it appears to have been written a few months before PlaywrightEnvironment was introduced to jest-playwright
Any guidance is greatly appreciated!
The text was updated successfully, but these errors were encountered: