javascript - Cypress - Running only specific test cases from the test suite - Stack Overflow

admin2025-04-22  1

I have 5 test cases in single suite file (TestCase1, TestCase2, TestCase3, TestCase4 and TestCase5) within integrations folder.

My Requirement: I need to run only TestCase2 and TestCase5.

Command to run a single test case from the mand line:

./node_modules/.bin/cypress run --spec 'cypress/integration/TestCase2.js

Query: How can I run TestCase2 and TestCase5 together using --spec mand?

I have 5 test cases in single suite file (TestCase1, TestCase2, TestCase3, TestCase4 and TestCase5) within integrations folder.

My Requirement: I need to run only TestCase2 and TestCase5.

Command to run a single test case from the mand line:

./node_modules/.bin/cypress run --spec 'cypress/integration/TestCase2.js

Query: How can I run TestCase2 and TestCase5 together using --spec mand?

Share Improve this question edited Mar 29, 2021 at 20:26 user14783414 asked Mar 29, 2021 at 11:13 Guru PrasadGuru Prasad 131 gold badge1 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

Your question is a bit confusing, you say 5 test cases in single suite file but your example cypress run --spec 'cypress/integration/TestCase2.js implies individual spec files.

I'll give you an answer both ways.


Individual spec files

Please see the third example docs - cypress run --spec which runs two tests, ma separated.

cypress run --spec "cypress/integration/TestCase2.spec.js,cypress/integration/TestCase5.spec.js"

Single suite file

Please see How to add test case grouping in Cypress which uses a beforeEach() to check test names passed in by ENV variable.

Add this at the top of your single test suite

beforeEach(function() {

  const testFilter = Cypress.env('TEST_FILTER');
  if (!testFilter) return;                       // exit if no filter defined

  const testName = Cypress.mocha.getRunner().test.fullTitle();
  if (!testFilter.includes(testName)) {
    this.skip();
  }
})

Run with

set CYPRESS_TEST_FILTER=Test2;Test5 & cypress open

or

cypress open --env TEST_FILTER=Test2;Test5  

Note when using the --env flag, the test names must not be separated by a ma since Cypress uses that internally to delimit multiple ENV variables.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745259497a292974.html

最新回复(0)