0
0
Cypresstesting~5 mins

Environment variables for configuration in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Acypress run --env key1=value1&key2=value2
Bcypress run --env key1=value1 key2=value2
Ccypress run --env key1=value1;key2=value2
Dcypress run --env key1=value1,key2=value2
Where in Cypress can you define environment variables to be used globally in tests?
AOnly in the test files themselves
BIn the <code>package.json</code> file
CInside <code>cypress.config.js</code> under the <code>env</code> property
DIn the browser console
How do you access an environment variable named 'apiUrl' inside a Cypress test?
Aprocess.env.apiUrl
BCypress.env('apiUrl')
CgetEnv('apiUrl')
Denv.apiUrl
Why should sensitive data be stored in environment variables rather than hard-coded in tests?
ATo keep secrets out of code and version control
BTo make tests run faster
CTo avoid syntax errors
DTo reduce test file size
Which of the following is a valid way to set an environment variable in cypress.config.js?
Aenv: { baseUrl: 'https://example.com' }
Benvironment: { baseUrl: 'https://example.com' }
Cconfig.env.baseUrl = 'https://example.com'
DsetEnv('baseUrl', 'https://example.com')
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.