Skip to main content

Cypress Skip Test Plugin

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

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.
Tags
Submitted by arilio666 on June 14, 2022

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.