Bird
0
0

You want to verify that the URL contains either '/admin' or '/manager' after login. Which assertion is best?

hard📝 Application Q8 of 15
Cypress - Navigation and URL
You want to verify that the URL contains either '/admin' or '/manager' after login. Which assertion is best?
Acy.url().should('include', '/admin' || '/manager')
Bcy.url().should('eq', '/admin' || '/manager')
Ccy.url().should('contain', '/admin|/manager')
Dcy.url().should('match', /\/admin|\/manager/)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    We need to check if URL contains either '/admin' or '/manager'.
  2. Step 2: Evaluate options

    cy.url().should('match', /\/admin|\/manager/) uses regex with 'match' to check either substring correctly. cy.url().should('include', '/admin' || '/manager') uses JavaScript '||' inside string, which is invalid. cy.url().should('contain', '/admin|/manager') treats '|'' as literal substring. cy.url().should('eq', '/admin' || '/manager') uses 'eq' with '||' which is incorrect.
  3. Final Answer:

    cy.url().should('match', /\/admin|\/manager/) -> Option D
  4. Quick Check:

    Use regex with 'match' for multiple substring options [OK]
Quick Trick: Use regex with 'match' for OR conditions in URL [OK]
Common Mistakes:
  • Using '||' inside string for OR logic
  • Confusing 'include' with regex matching
  • Using 'eq' for multiple options

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes