Running Cypress Tests on Multiple Environments

In our Slack Ask Me Anything all about Cypress with @marie.drake and Filip Hric, Ritesh asked

We are running cypress on CircleCI using mock data is there a way to run the same test on using live data on UAT or similar. Something like if environment is UAT, expect this, else expect that

Filip suggested

I have a similar although slightly different use case, where I need to run my tests in one environment, but skip them on other. I use this neat plugin for this which allows me to determine whether I want to run that test or not, based on a certain condition. check out boolean flag on this plugin, it’s really cool

Marie suggested

Hey Ritesh great question! Yes you can achieved this What you can do is you can declare an environment variable for your test environment. Something like

if (Cypress.env('environment') === 'uat') {
/// some code store live data on a json file cy.fixture('real-data').as('testData')
} else {
cy.fixture('mock-data').as('testData');
}

Then using Cypress aliases you can access the testData in your test

This is just one way that I can think of, I’m sure others might have a better way but you can try this

Is this something that you have tried? What way did you approach it?