I have a 3 spec files for testing form filling and photo uploading using cypress.
Form is - https://demoqa.com/automation-practice-form
Problem is when fill a form test passes, browser is closed and 2 other test fail because I don't call open url in each test case.
If I run tests in GUI, everything is fine. Browser is not closed after first test, but when I run
npx cypress run --headed --browser chrome
from command line, problem occures.
I want to run tests from command line so browser doesn't close till all tests are finished.
I got exactly same problem and after hours of research I found a workaround that solves this. It is not a real fix but it solves your issue and mine. Here are the steps I did:
Create a 4th spec file, call it main.spec.ts, inside this file do an import for the 3 spec files you have:
import './fillform.spec.js'
import './uploadphoto.spec.js'
import './result.spec.js'
In cypress.json file, add the following entry to allow to run only the main spec file:
"testFiles": ["main.spec.js"],
Now cypress run will work exactly as cypress open and all specs will run without closing the browser in between:
npx cypress run --headed --browser chrome
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.