Cypress: How do I conditionally skip a test by checking the URL

Viewed 1817

How do I conditionally skip a test if the URL contains "xyz"? some tests that run in the QA environment "abc" should not be run in Production "xyz" environment.

I've not been able to find a good example of conditionally checking for environment to trigger a test. The baseURL needs to be checked dynamically and the test skipped preferably in the beforeEach.

running cypress 6.2.0

beforeEach(() => {
    login.loginByUser('TomJones');
    cy.visit(`${environment.getBaseUrl()}${route}`);
 });

it('test page', function () {
     if environment.getBaseUrl().contains("xyz")
       then *skip test* 
     else
       cy.intercept('GET', '**/some-api/v1/test*').as('Test'););     
       cy.get('#submitButton').click();
})

Potential Solution (tested and tried successfully): I used a combination of filtering (grouping) and folder structures via CLI I set folders /integrations/smokeTest/QA and /integrations/smokeTest/Prod/

1.QA Test Run: 
  npm run *cy:filter:qa* --spec "cypresss/integration/smokeTests/QA/*-spec.ts"

2.Run All (both QA and PROD tests)
  npm run cypress:open --spec "cypresss/integration/smokeTests/*/*-spec.ts"

3. Prod Test Run: 
npm run cy:filter:prod --spec "cypresss/integration/smokeTests/PROD*/*-spec.ts"



0 Answers
Related