Cypress.env present but saying it is undefined #25087
Answered
by
emilyrohrbough
diogormendes
asked this question in
Questions and Help
-
I'm saving an API tokes as a When I call this on the test, it says is undefined. What may I be doing wrong ? |
Beta Was this translation helpful? Give feedback.
Answered by
emilyrohrbough
Dec 9, 2022
Replies: 1 comment
-
@diogormendes This likely how your test is written given how this value is resolving at the time these commands are being queued. If you have: .then(() => {
Cypress.env('token', 'val')
})
cy.log(Cypress.env('token')) The If you were add the cy.log() in a then callback, it would be be queued after the env value has been set, it will be defined: .then(() => {
Cypress.env('token', 'val')
})
.then(() => {
cy.log(Cypress.env('token'))
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
diogormendes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@diogormendes This likely how your test is written given how this value is resolving at the time these commands are being queued.
If you have:
The
Cypress.env('token')
value at the timecy.log()
is added indeed undefined.If you were add the cy.log() in a then callback, it would be be queued after the env value has been set, it will be defined: