最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to run multiple tests in Cypress without closing browser? - Stack Overflow

programmeradmin0浏览0评论

I have a 3 spec files for testing form filling and photo uploading using cypress.

  1. spec file: Fill a form
  2. spec file: Upload a photo
  3. 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.

  1. spec file: Fill a form
  2. spec file: Upload a photo
  3. 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
 |  Show 1 more ment

1 Answer 1

Reset to default 5

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
发布评论

评论列表(0)

  1. 暂无评论