You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have my cypress.env.json file at the root directory. And the initial value of this env var is blank. let's say the name of the env var is TOKEN
cy.log('pre');cy.log(Cypress.env('TOKEN'));// "" loggedcy.request({method: 'GET',url: `/xsrf-token`,}).its('body').then((data)=>{Cypress.env('TOKEN',data.token);cy.log('mid');cy.log(Cypress.env('TOKEN'));// the correct token value is logged});cy.log('post');cy.log(Cypress.env('TOKEN'));// "" logged
Desired behavior
I was expecting the cypress env value to persist even outside of the "then" block.
Test code to reproduce
Run any cy.request function
In the then block, set the value of an env var
log the env var after the cy.request
Cypress Version
13.2.0
Node version
18
Operating System
MacOS
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered:
Hello! I would recommend using before if you want to set the environment variable before running your tests in your spec file like so
before(()=>{cy.request({method: 'GET',url: `/xsrf-token`,}).its('body').then((data)=>{Cypress.env('TOKEN',data.token);cy.log('mid');cy.log(Cypress.env('TOKEN'));// the correct token value is logged});})it('test',function(){cy.log(Cypress.env('TOKEN'))})
Do you have a special use case where this does not work? Please let me know
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.
Current behavior
I have my
cypress.env.json
file at the root directory. And the initial value of this env var is blank. let's say the name of the env var is TOKENDesired behavior
I was expecting the cypress env value to persist even outside of the "then" block.
Test code to reproduce
then
block, set the value of an env varCypress Version
13.2.0
Node version
18
Operating System
MacOS
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: