Bird
0
0

Given baseUrl is set to http://localhost:3000, what happens if you run cy.visit('http://example.com')?

medium📝 Predict Output Q5 of 15
Cypress - Navigation and URL
Given baseUrl is set to http://localhost:3000, what happens if you run cy.visit('http://example.com')?
ATest fails with URL error
BCypress visits http://example.com ignoring baseUrl
CCypress visits http://localhost:3000/example.com
DCypress appends example.com to baseUrl
Step-by-Step Solution
Solution:
  1. Step 1: Understand absolute vs relative URLs in cy.visit()

    If cy.visit() receives a full URL, it uses it directly, ignoring baseUrl.
  2. Step 2: Apply this to the given URL

    Since 'http://example.com' is absolute, Cypress visits it as is, not combining with baseUrl.
  3. Final Answer:

    Cypress visits http://example.com ignoring baseUrl -> Option B
  4. Quick Check:

    Absolute URL in cy.visit() ignores baseUrl [OK]
Quick Trick: Absolute URLs in cy.visit() override baseUrl [OK]
Common Mistakes:
  • Thinking baseUrl always prefixes
  • Expecting error on absolute URL
  • Appending absolute URL to baseUrl

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes