Bird
0
0

What is wrong with this code if the URL is https://example.com/login?

medium📝 Debug Q7 of 15
Cypress - Navigation and URL
What is wrong with this code if the URL is https://example.com/login?

cy.location('hostname').should('eq', 'www.example.com')
AThe code should use 'host' instead of 'hostname'
Bcy.location('hostname') returns full URL, not hostname
CThe assertion should use 'include' instead of 'eq'
DThe hostname does not include 'www.' prefix here
Step-by-Step Solution
Solution:
  1. Step 1: Check the hostname in the URL

    The URL hostname is 'example.com' without 'www.' prefix.
  2. Step 2: Understand assertion failure cause

    Comparing to 'www.example.com' will fail because it does not match exactly.
  3. Final Answer:

    The hostname does not include 'www.' prefix here -> Option D
  4. Quick Check:

    Hostname must match exactly [OK]
Quick Trick: Hostname excludes 'www.' if not in URL [OK]
Common Mistakes:
  • Assuming 'www.' is always present
  • Confusing 'host' and 'hostname'
  • Using 'include' when exact match needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes