'Azure DevOps pipelines for cypress tests not running in the test environments(Dev, QA, Stage and prod) that I selected before clicking on run
I have different environments added in my cypress.env.json file like below
{
"environment":"staging",
"prod":"http://production.com",
"staging":"http://qual.com/dashboard",
"sandbox":"http://sandbox.com/dashboard",
"test": "http://test.com/dashboard",
"versionProd": "vAlpha6",
"versionStage":"vAlpha7"
}
And in .YML file, I have stack data like below
parameters:
- name: TestType
displayName: Test
type: string
default: sanity
values:
- sanity
- smoke
- parameterization
- name: environment
displayName: environment
type: string
default: staging
values:
- test
- sandbox
- staging
When I try to select test type(Sanity/smoke, etc) it is taking correctly. But when I try to select test stack, it is considering what I provided in env.json file. I need it to run in the environment that I selected in pipeline but not the one that I have passed in env.json. Can I get some help here please. Thanks in Advance enter image description here
Solution 1:[1]
Without seeing your actual pipeline .yml file and the use of the environment variables in your tests, it is of course difficult to give an answer.
As far as I understand your question, you want to select an environment on which to run the tests before executing your pipeline. So I guess your pipeline parameters look something like this:
parameters:
- name: TestType
displayName: Test
type: string
default: sanity
values:
- sanity
- smoke
- parameterization
- name: environment
displayName: environment
type: string
default: staging
values:
- test
- sandbox
- staging
Then you have several options to use this information for your Cypress test execution. See also the Environment Variables section of the official docs.
One option for you would be to use the CYPRESS_ namepspace like described here. With this you could make the information from your pipeline parameters available in your tests as follows:
- script: |
npm run cy:int
workingDirectory: $(Build.SourcesDirectory)
displayName: Run Cypress Tests
env:
CYPRESS_TestType: '$(TestType)'
CYPRESS_environment: '$(environment)'
You can then access the information in your Cypress tests as follows, e.g. for visiting a certain url:
if(Cypress.env('environment') === 'sandbox') {
cy.visit('http://sandbox.com/dashboard');
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sebastiano Vierk |
