Challenge - 5 Problems
Environment Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Understanding Cypress environment variable usage
What will be the output of the following Cypress test code snippet when run with the environment variable USERNAME set to 'tester'?
Cypress
describe('Env Var Test', () => { it('prints username', () => { const user = Cypress.env('USERNAME') cy.log(`User is: ${user}`) }) })
Attempts:
2 left
💡 Hint
Remember Cypress.env() reads environment variables set before running tests.
✗ Incorrect
Cypress.env('USERNAME') fetches the environment variable USERNAME. If set to 'tester', cy.log prints 'User is: tester'.
❓ assertion
intermediate2:00remaining
Correct assertion for environment variable in Cypress
Which assertion correctly verifies that the environment variable API_KEY equals '12345' in a Cypress test?
Cypress
const apiKey = Cypress.env('API_KEY')
Attempts:
2 left
💡 Hint
Use Cypress's recommended assertion style with expect().
✗ Incorrect
expect(apiKey).to.equal('12345') correctly checks string equality. Option C uses less common syntax in Cypress, C checks boolean, D compares string to number.
🔧 Debug
advanced2:00remaining
Debugging missing environment variable in Cypress
A Cypress test fails because Cypress.env('PASSWORD') returns undefined, even though you set PASSWORD in cypress.config.js. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check how environment variables are structured in the config file.
✗ Incorrect
Environment variables must be set under the 'env' key in cypress.config.js. If set elsewhere, Cypress.env() returns undefined.
🧠 Conceptual
advanced2:00remaining
Best practice for sensitive environment variables in Cypress
Which is the best practice to handle sensitive environment variables like API keys in Cypress tests?
Attempts:
2 left
💡 Hint
Think about security and version control best practices.
✗ Incorrect
Setting sensitive variables in CI/CD environment variables and accessing them via Cypress.env() keeps secrets out of code and version control.
❓ framework
expert2:00remaining
Configuring Cypress environment variables for multiple environments
You want to run Cypress tests with different environment variables for 'staging' and 'production'. Which configuration approach allows this?
Attempts:
2 left
💡 Hint
Consider how Cypress supports multiple config files.
✗ Incorrect
Cypress supports multiple config files. Using --config-file option lets you run tests with different environment variables per environment.