Leo2304
Leo2304

Reputation: 117

Skip a Cypress Test in Commandline

I have a cypress integration test that I do not want to run in my CI/CD pipeline. I know I can use .skip() function to skip the test but what I am looking for is a way to exclude the test by passing some command line argument itself(like we have in case of Xunit test cases). Is there any way to do that?

Upvotes: 3

Views: 3174

Answers (3)

Rosen Mihaylov
Rosen Mihaylov

Reputation: 1427

I would put an Environment variable in cypres.env.json file and put the questionable It case in an if statement like:

context('conditional test', () => {
    if (Cypress.env('myVariable')) {
        it('conditional test', function () {
            //code to be run only if the variable is true
        })
    }
}

Upvotes: 2

Alapan Das
Alapan Das

Reputation: 18639

One option can be to use the Node package cypress-select-tests. Once installed, you can add some keywords to your describe().

eg. describe('test name (ignore)', () => {

And then run your tests based on the keyword ignore. Below command will run all tests except the ones which has ignore written in the describe().

## runs tests NOT with "ignore" in the title 
$ npx cypress run --env grep='ignore',invert=true

Upvotes: 4

ShortM
ShortM

Reputation: 499

You can specify the tests you want to be run by using the cypress run --spec option. So you can move the tests you want to run into their own folder, 'cypress/integration/testsToRun/**/*' for example, and Cypress will run only the specified tests and skip the rest.

Upvotes: 4

Related Questions