question regarding globalSetup and globalTeardown
See original GitHub issueI am attempting to utilize globalSetup
and globalTeardown
to implement authentication once per suite rather than once per test.
In jest.config
I customize the browsers array via environment variables like so
let browsers = ['chromium'];
if (process.env.E2E_BROWSERS) {
browsers = process.env.E2E_BROWSERS.split(' ');
}
What 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!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Make "globalSetup" and "globalTeardown" work together with ...
Modules defined in globalSetup and globalTeardown are not being transformed as defined in transform configuration entry.
Read more >Getting Jest global setup and global teardown to work in a ...
The typescript environment is not yet defined when globalSetup and globalTeardown are run, which is why jest is failing.
Read more >Configuring Jest
Any global variables that are defined through globalSetup can only be read in globalTeardown . You cannot retrieve globals defined here in ...
Read more >Internals API | Detox
Theoretically, Detox CLI could be totally agnostic about the test runner under the hood, ... Hence, neither globalSetup nor globalTeardown will be called, ......
Read more >Mocha - the fun, simple, flexible JavaScript test framework
Do not share a context with tests, suites, or other hooks. There are two types of global fixtures: global setup fixtures and global...
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
The
globalSetup
example looks like thisSo, in the example you have to specify the browser being used, rather than the one utilized from the
browsers
array in thejest-playwright.config.js
. So the question becomes, how would you use the currentbrowser
for your login process.Seems to me that the
globalSetup
runs prior to all of the tests being run, soglobalSetup
probably doesn’t know which browser your tests are going to run against, and probably wouldn’t run again if you’ve defined multiple browsers, but I don’t know enough aboutjest
internals, so I’m just assuming. If that’s the case, I guess the developer just has to pick one (browser) to write the login against (to get the state data). If someone could verify that, that would be great.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.
Playwright and Jest-Playwright