Comments (4)
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 test.describe
and skip only it if you still want to run the rest.
from playwright.
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.
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 });
});
If I play all the tests, eg. using the Screenshot 2024-04-18 at 8 16 41 AM button, then the expected behavior occurs, eg. the setup only runs once before all the tests.
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.
from playwright.
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.
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.
from playwright.
setup.skip(fs.existsSync(storageFilePath) && !fileOlderThan(storageFilePath, "4h"));
@yury-s, that's... brilliant. This needs to be in the docs on the Authentication page.
from playwright.
Related Issues (20)
- [Bug]: Failed to install browsers on ubuntu 22.04 HOT 12
- [Bug]: Worker-scoped fixture execution terminates before timeout HOT 1
- [Feature]: Option to run only failed cases from the previous run
- [Feature]: maximizing the pop-up window in browser HOT 2
- [Bug]: Runnin playwright install in github actions fails: prod jammy InRelease' is no longer signed. HOT 1
- [Docs]: Discord link shows invalid invite error coming from discord HOT 1
- [Bug]: "--ui" mode hangs up on throw new Error in playwright config file HOT 3
- [Bug]: Installing browsers in GitHub Actions fails HOT 1
- [Bug]: junit report created by merge has incorrect testsuites time
- [Bug]: UI mode results disappear after running suite. Version 1.43 HOT 2
- [Feature]: `trace: retain-all-failures` HOT 1
- [Bug]: TypeError: The "paths[1]" argument must be of type string. Received undefined HOT 3
- [Feature]: Option to always send httpCredentials in APIRequestContext HOT 3
- [Bug]: Two differerent domain redirection cause target crash issue HOT 1
- [Bug]: Disabling the "Block insecure private network requests" experiment in Google Chrome is not effective. HOT 1
- gfdg
- [Bug]: Missing libraries for webkit browsers (libwoff2dec.so) HOT 3
- I have playwright cucumber typescript projects. we execute the Test Cases through npm commands using tags. Commands npm test --tags=@smoke. but the same commands are not working in mac
- is it possible to hide skipped tests altogether from HTML report?
- [Feature]: Skip remaining tests after failure of first test HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright.