I have a 3 spec files for testing form filling and photo uploading using cypress.
- spec file: Fill a form
- spec file: Upload a photo
- spec file: Check the results
Form is -
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 mand line, problem occures.
I want to run tests from mand line so browser doesn't close till all tests are finished.
I have a 3 spec files for testing form filling and photo uploading using cypress.
- spec file: Fill a form
- spec file: Upload a photo
- spec file: Check the results
Form is - https://demoqa./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 mand line, problem occures.
I want to run tests from mand line so browser doesn't close till all tests are finished.
Share Improve this question asked Sep 15, 2021 at 11:37 user3850734user3850734 571 silver badge6 bronze badges 6- 1 Please add the code from your spec files in the question. – Alapan Das Commented Sep 15, 2021 at 12:42
- 3 Code is irrelevant. When I run tests with cypress gui tests are performed one by one and browser is not closing. – user3850734 Commented Sep 15, 2021 at 19:36
-
I put test cases order in cypress.json
"testFiles": [ "Form.spec.js", "UploadFile.spec.js", "Check.spec.js" ]
Form spec fill the form with user data, uploadfile spec upload a file on the same form and click submit, and check spec checks is file uploaded after test case step before submited filled form. Problem is when I start all from mand line. After first test case is over, browser is closed and second test case starts without browser and test case fails. – user3850734 Commented Sep 15, 2021 at 19:45 - Did you tried the option --no-exit – Frank Commented Sep 16, 2021 at 13:31
- 2 Yes and after first test browser stays open but second test case doesn't start. – user3850734 Commented Sep 17, 2021 at 7:35
1 Answer
Reset to default 5I 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745513188a4630863.html
评论列表(0条)