Answered
In my Cypress tests, I want to add an if ()
conditionally where a test will be ran or skipped based on a true
or false
value.
For instance, if I have this test:
it('should focus on the todo input field', function () {
cy.focused().should('have.class', 'new-todo')
})
How could I skip it? Is there a cy.skip()
or this.skip()
method in Cypress?
You can simply wrap your test in an if
statement like you would in any JavaScript code:
if (condition) {
it('should focus on the todo input field', function () {
cy.focused().should('have.class', 'new-todo')
})
}
Cypress has @cypress/skip-test NPM package you could use for this.
It provides skipOn()
and onlyOn()
methods you could use.
For example, you could skip a test if Cypress is using the Firefox browser:
it('skips on Firefox', () => {
skipOn('firefox')
})