Bird
0
0

You want to run tests on two environments: https://dev.site and https://prod.site. How can you configure Cypress to switch baseUrl easily?

hard📝 framework Q15 of 15
Cypress - Navigation and URL
You want to run tests on two environments: https://dev.site and https://prod.site. How can you configure Cypress to switch baseUrl easily?
AUse environment variables and set <code>baseUrl</code> dynamically in <code>cypress.config.js</code>.
BManually edit <code>baseUrl</code> in config before each test run.
CWrite full URLs in every <code>cy.visit()</code> call instead of using <code>baseUrl</code>.
DSet <code>baseUrl</code> only once and ignore environment differences.
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment switching need

    Tests must run on different URLs without changing code manually.
  2. Step 2: Use environment variables in config

    Set baseUrl in cypress.config.js using environment variables to switch easily.
  3. Final Answer:

    Use environment variables and set baseUrl dynamically in cypress.config.js. -> Option A
  4. Quick Check:

    Dynamic baseUrl via env vars = flexible testing [OK]
Quick Trick: Use env vars to switch baseUrl without code changes [OK]
Common Mistakes:
  • Editing config manually each time
  • Avoiding baseUrl and writing full URLs everywhere
  • Ignoring environment differences in tests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes