Recall & Review
beginner
What are environment variables in Cypress used for?
Environment variables in Cypress store configuration values that can change between test runs, like URLs, credentials, or API keys. They help keep tests flexible and secure.
Click to reveal answer
beginner
How do you set environment variables in Cypress using the command line?
You can set environment variables by running Cypress with the command:
cypress run --env key=value. Multiple variables can be set separated by commas.Click to reveal answer
intermediate
Where can you define environment variables in Cypress configuration files?
Environment variables can be defined inside
cypress.config.js under the env property as key-value pairs, making them available to all tests.Click to reveal answer
beginner
How do you access an environment variable inside a Cypress test?
Use
Cypress.env('key') to get the value of an environment variable named key inside your test code.Click to reveal answer
intermediate
Why is it better to use environment variables for sensitive data in tests?
Using environment variables keeps sensitive data like passwords out of the test code and version control, improving security and making it easier to change values without editing tests.
Click to reveal answer
How can you pass multiple environment variables when running Cypress from the command line?
✗ Incorrect
Multiple environment variables are passed as a comma-separated list with no spaces using --env.
Where in Cypress can you define environment variables to be used globally in tests?
✗ Incorrect
The
cypress.config.js file's env property is the standard place for global environment variables.How do you access an environment variable named 'apiUrl' inside a Cypress test?
✗ Incorrect
Cypress provides the Cypress.env() function to access environment variables.
Why should sensitive data be stored in environment variables rather than hard-coded in tests?
✗ Incorrect
Storing sensitive data in environment variables improves security by not exposing secrets in code.
Which of the following is a valid way to set an environment variable in
cypress.config.js?✗ Incorrect
The correct syntax is to use the env property with key-value pairs.
Explain how to set and use environment variables in Cypress tests.
Think about configuration files, command line options, and test code access.
You got /3 concepts.
Why is using environment variables important for managing sensitive data in test automation?
Consider security and maintainability benefits.
You got /4 concepts.