Challenge - 5 Problems
Environment Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of environment-specific baseUrl in Cypress
Given the following Cypress configuration files for two environments, what will be the baseUrl used when running tests with the command
cypress run --env configFile=staging?Cypress
/* cypress.config.js */ const { defineConfig } = require('cypress') module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { const envConfig = require(`./cypress.env.${config.env.configFile}.json`) return {...config, ...envConfig} }, baseUrl: 'http://localhost:3000' } }) /* cypress.env.staging.json */ { "baseUrl": "https://staging.example.com" } /* cypress.env.production.json */ { "baseUrl": "https://www.example.com" }
Attempts:
2 left
💡 Hint
Check how the configFile environment variable affects the loaded JSON file.
✗ Incorrect
When running with --env configFile=staging, the setupNodeEvents function loads cypress.env.staging.json which overrides baseUrl to https://staging.example.com.
❓ assertion
intermediate1:30remaining
Correct assertion for environment-specific API endpoint
You want to assert that the API endpoint URL used in your Cypress test matches the environment-specific value. Which assertion correctly verifies that the API URL is set to the production endpoint when running with
--env configFile=production?Cypress
const apiUrl = Cypress.env('apiUrl') // Production endpoint is https://api.example.com
Attempts:
2 left
💡 Hint
Use the correct assertion style and check the expected URL for production.
✗ Incorrect
Option B uses the correct Cypress assertion syntax and matches the expected production API URL.
🔧 Debug
advanced2:30remaining
Debug failing environment variable in Cypress test
A test fails because the environment variable
apiKey is undefined when running tests with --env configFile=qa. The cypress.env.qa.json file contains { "apiKey": "12345" }. What is the most likely cause?Cypress
/* cypress.config.js */ const { defineConfig } = require('cypress') module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { const envConfig = require(`./cypress.env.${config.env.configFile}.json`) return {...config, ...envConfig} } } })
Attempts:
2 left
💡 Hint
Check the test run command and environment variable usage.
✗ Incorrect
If the test command does not specify --env configFile=qa, the qa environment config file won't load, so apiKey remains undefined.
🧠 Conceptual
advanced2:00remaining
Best practice for managing sensitive environment variables in Cypress
Which approach is the safest and most recommended way to manage sensitive environment variables like API keys across different environments in Cypress?
Attempts:
2 left
💡 Hint
Think about security and version control best practices.
✗ Incorrect
Using OS environment variables and loading them in config files avoids committing sensitive data to version control, improving security.
❓ framework
expert3:00remaining
Configuring Cypress to run tests with multiple environment configurations sequentially
You want to run your Cypress tests sequentially for 'development', 'staging', and 'production' environments, each with its own config file (cypress.env.development.json, etc.). Which approach correctly sets this up in a Node.js script?
Cypress
const { exec } = require('child_process') // Fill in the missing code to run tests sequentially for each environment
Attempts:
2 left
💡 Hint
Consider how to wait for each exec command to finish before starting the next.
✗ Incorrect
Option D wraps exec in a Promise and uses async/await to run tests sequentially, ensuring one finishes before the next starts.