Cypress Skip Test Plugin

Profile picture for user arilio666

The skip test plugin, unlike the skip and only functionality already available in the cypress, is primarily for skipping tests based on platform, browser, or URL.

Let us start by installing the plugin in cypress.

npm install -D @cypress/skip-test to install the plugin package in cypress.

Next, to use the copy.skipOn and cy.onlyOn or any other custom cypress commands, we need to import it on cypress/support/index.js

Noteif you are using version Cypress 10 or above add it to e2e.js. For typescript it will be e2e.ts.

require('@cypress/skip-test/support')
 

Let's check out the commands.

cy.onlyOn

it('runs on Windows only', () => {
  cy.onlyOn('windows')
  // the rest
})
  • Runs test only when running on windows and skips running on any other platform.
it('localhost only', () => {
  cy.onlyOn('localhost')
  // the rest
})
  • Only runs tests against localhost and neglects others.

cy.skipOn

it('Skip Firefox', () => {
  cy.skipOn('firefox')
  // the rest
})
  • It skips this test if running on firefox.
it('skip windows', () => {
  cy.skipOn('windows')
  // the rest
})
  • It skips on the windows platform.

isOn

import { isOn } from '@cypress/skip-test'
it('loads users', () => {

  if (isOn('windows') && isOn('localhost')) {
    cy.server()
    cy.route('/users', 'fixture:users')
  }
  cy.visit('/')
  cy.get('.user').should('have.length', 10)
})
  • Can check the condition against browser name or environment.
  • This can be done after importing the isOn from @cypress/skip-test.

Chaining:

it('combination of skip and only', () => {
  cy.skipOn('windows')
  cy.onlyOn('firefox').onlyOn('chrome')
  cy.log('running')
})
  • We can chain conditions together too.