Bird
0
0

You want to create a plugin that reads environment variables and provides them as a task. Which approach correctly extends Cypress capabilities?

hard📝 Application Q8 of 15
Cypress - Plugins and Ecosystem
You want to create a plugin that reads environment variables and provides them as a task. Which approach correctly extends Cypress capabilities?
AAccess process.env directly inside test files without plugins
BDefine a task in plugins file that returns process.env variables when called
CUse Cypress.env() inside plugins to read environment variables
DModify cypress.json to include environment variables without plugins
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment variable access in Cypress

    Plugins run in Node.js and can access process.env; exposing them via tasks allows tests to retrieve them safely.
  2. Step 2: Evaluate options for correct plugin usage

    Define a task in plugins file that returns process.env variables when called correctly defines a task to return environment variables. Access process.env directly inside test files without plugins is unsafe and not recommended. Use Cypress.env() inside plugins to read environment variables is invalid because Cypress.env() is for test code, not plugins. Modify cypress.json to include environment variables without plugins does not extend capabilities via plugins.
  3. Final Answer:

    Define a task in plugins file that returns process.env variables when called -> Option B
  4. Quick Check:

    Use tasks to expose Node.js env vars to tests [OK]
Quick Trick: Use tasks to expose environment variables safely [OK]
Common Mistakes:
  • Accessing process.env directly in tests
  • Using Cypress.env() inside plugins
  • Modifying config without plugins

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes