Bird
0
0

You want to verify that after login, the URL contains '/dashboard' but may have query parameters like '?user=123'. Which assertion is best to use?

hard📝 Application Q15 of 15
Cypress - Navigation and URL
You want to verify that after login, the URL contains '/dashboard' but may have query parameters like '?user=123'. Which assertion is best to use?
Acy.url().should('eq', 'https://example.com/dashboard')
Bcy.url().should('contain', '/dashboard?user=123')
Ccy.url().should('include', '/dashboard')
Dcy.url().should('match', /^https:\/\/example\.com\/dashboard\?user=\d+$/)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the URL with query parameters

    The URL may have extra parts after '/dashboard', so exact match ('eq') won't work.
  2. Step 2: Choose assertion allowing partial match

    'include' checks if '/dashboard' is anywhere in the URL, ignoring query parameters.
  3. Final Answer:

    cy.url().should('include', '/dashboard') -> Option C
  4. Quick Check:

    Use 'include' to ignore query parameters [OK]
Quick Trick: Use 'include' to ignore query parameters in URL check [OK]
Common Mistakes:
  • Using 'eq' which fails with query parameters
  • Trying complex regex without need
  • Using invalid 'contain' assertion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes