Bird
0
0

You wrote this in cypress.config.js:

medium📝 Debug Q6 of 15
Cypress - Test Organization and Patterns
You wrote this in cypress.config.js:
export default defineConfig({
  env: {
    apiKey: process.env.API_KEY
  }
})

But Cypress.env('apiKey') is undefined during tests. What is the likely cause?
ACypress.env cannot access process.env variables
BYou must use double quotes around process.env.API_KEY
CThe environment variable API_KEY is not set in the OS before running Cypress
DapiKey must be defined inside the test file, not config
Step-by-Step Solution
Solution:
  1. Step 1: Check environment variable availability

    process.env.API_KEY reads OS environment variables; if not set, it returns undefined.
  2. Step 2: Confirm Cypress.env behavior

    Cypress.env('apiKey') reflects the value set in config.env.apiKey, so if process.env.API_KEY is undefined, Cypress.env('apiKey') is undefined.
  3. Final Answer:

    The environment variable API_KEY is not set in the OS before running Cypress -> Option C
  4. Quick Check:

    Unset OS env var = Cypress.env undefined [OK]
Quick Trick: Set OS env vars before running Cypress to use in config [OK]
Common Mistakes:
  • Thinking quotes affect process.env access
  • Believing Cypress.env can't read config env
  • Defining apiKey only inside tests instead of config

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes