Skip a Cypress Test in Commandline

Viewed 1831

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?

3 Answers

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.

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

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
        })
    }
}
Related