0
0
Cypresstesting~20 mins

cy.url() assertions in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
URL Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
assertion
intermediate
2:00remaining
Check if URL contains a specific path segment
You want to verify that the current page URL contains the segment /dashboard. Which assertion correctly checks this using cy.url()?
Acy.url().should('include', '/dashboard')
Bcy.url().should('have', '/dashboard')
Ccy.url().should('contain', '/dashboard')
Dcy.url().should('equal', '/dashboard')
Attempts:
2 left
💡 Hint
Think about the correct assertion keyword to check if a string is part of the URL.
assertion
intermediate
2:00remaining
Verify URL equals expected full URL
You want to assert that the current URL exactly matches https://example.com/login. Which option is correct?
Acy.url().should('match', 'https://example.com/login')
Bcy.url().should('eq', 'https://example.com/login')
Ccy.url().should('equals', 'https://example.com/login')
Dcy.url().should('equal', 'https://example.com/login')
Attempts:
2 left
💡 Hint
Look for the exact assertion keyword Cypress supports for equality.
Predict Output
advanced
2:00remaining
What is the test result of this URL assertion?
Given the current URL is https://example.com/profile/settings, what will be the result of this test code?
Cypress
cy.url().should('include', '/profile').and('include', '/settings')
ATest fails because 'and' cannot chain assertions
BTest passes because both substrings are in the URL
CTest fails because 'include' only works once per assertion
DTest passes but only checks the first substring
Attempts:
2 left
💡 Hint
Think about how chaining assertions with 'and' works in Cypress.
🔧 Debug
advanced
2:00remaining
Identify the error in this URL assertion code
This test code is intended to check if the URL starts with https://example.com/shop. What is wrong with it?
Cypress
cy.url().should('startWith', 'https://example.com/shop')
AThe assertion keyword 'startWith' is invalid in Cypress
BThe URL must be wrapped in a regex for this to work
CThe method 'should' cannot be used with 'startWith'
DThe URL must be converted to lowercase first
Attempts:
2 left
💡 Hint
Check Cypress documentation for valid assertion keywords.
🧠 Conceptual
expert
3:00remaining
Best practice for asserting dynamic URL parameters
You want to assert that the current URL contains the path /product and a query parameter id with any value. Which approach is best to write a reliable test?
AUse <code>cy.url().should('equal', '/product?id=123')</code> with a fixed id value
BUse <code>cy.url().should('include', '/product?id=')</code> to check the substring
CUse <code>cy.url().should('match', /\/product\?id=\w+/)</code> to match the pattern with regex
DUse <code>cy.url().should('contain', '/product').and('contain', 'id=')</code> to check both parts separately
Attempts:
2 left
💡 Hint
Think about how to handle dynamic values in URLs during assertions.