-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[Bug]: Project dependency and storageState
not working as expected
#30416
Comments
You can easily achieve that by having you setup code check if the storage state file already exists and skip expensive setup steps in that case. Playwright does not do this automatically. const authFile = 'playwright/.auth/user.json';
setup('authenticate', async ({ request }) => {
if (fs.existsSync(authFile))
return;
// Send authentication request. Replace with your own.
await request.post('https://github.com/login', { ... });
await request.storageState({ path: authFile });
});
Playwright will run setup dependencies on every run. It will run each dependency exactly once, regardless of how many tests are in the dependent project. |
Yeah, that's what I'm doing currently. setup("Authenticate into CMS", async ({ page }) => {
if (fs.existsSync(storageFilePath) && !fileOlderThan(storageFilePath, "4h")) {
return;
}
...
}); It would be nice if it did this automatically somehow, but I get it. The biggest downside with this is when running single tests with 'Show browser' enabled, it'll flash a white page in a new window before opening the actual test. |
You can call test.skip based on a condition outside the tests: setup.skip(fs.existsSync(storageFilePath) && !fileOlderThan(storageFilePath, "4h"));
setup("Authenticate into CMS", async ({ page }) => {
...
}); Or wrap relevant tests into |
setup.skip(fs.existsSync(storageFilePath) && !fileOlderThan(storageFilePath, "4h")); @yury-s, that's... brilliant. This needs to be in the docs on the Authentication page. |
Version
1.43.1
Steps to reproduce
setup
project with atestMatch
of/.*\.setup\.ts/
Desktop Chrome
project with a defineduse.storageState
and a["setup"]
asdependencies
Desktop Chrome
, observe the setup dependency run, the storage state file is generated and the single test is ranExpected behavior
I'd expect the dependency to run once and generate the storage state file. And then in subsequent runs, the dependency should not be run since the storage state file already exists. If I play all the tests, eg. using the button, then the expected behavior occurs, eg. the setup only runs once before all the tests.
Actual behavior
The dependency test runs before every single test when running a single test.
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: