0
0
Cypresstesting~5 mins

cy.url() assertions in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does cy.url() do in Cypress?

cy.url() gets the current URL of the page being tested. It allows you to check or assert the URL during your test.

Click to reveal answer
beginner
How do you assert that the URL contains a specific string using cy.url()?

Use cy.url().should('include', 'string') to check if the current URL contains the given string.

Click to reveal answer
beginner
Which assertion checks if the URL exactly matches a string?

Use cy.url().should('eq', 'https://example.com') to assert the URL equals the exact string.

Click to reveal answer
intermediate
How can you assert that the URL matches a pattern using cy.url()?

Use cy.url().should('match', /pattern/) where /pattern/ is a regular expression to test the URL.

Click to reveal answer
beginner
Why is it useful to assert the URL in end-to-end tests?

Asserting the URL confirms the app navigated to the correct page, just like checking the address on a letter to make sure it reached the right place.

Click to reveal answer
Which command checks if the current URL contains 'dashboard'?
Acy.url().should('eq', 'dashboard')
Bcy.url().should('include', 'dashboard')
Ccy.url().should('contain', 'dashboard')
Dcy.url().should('match', 'dashboard')
How do you assert the URL exactly equals 'https://example.com/home'?
Acy.url().should('contain', 'https://example.com/home')
Bcy.url().should('include', 'https://example.com/home')
Ccy.url().should('eq', 'https://example.com/home')
Dcy.url().should('match', 'https://example.com/home')
Which assertion uses a regular expression to check the URL?
Acy.url().should('match', /login/)
Bcy.url().should('include', 'login')
Ccy.url().should('eq', 'login')
Dcy.url().should('contain', 'login')
What does cy.url() return?
AThe current page URL as a string
BThe page title
CThe page HTML content
DThe browser console logs
Why should you assert URLs in tests?
ATo test CSS styles
BTo check page load speed
CTo validate database entries
DTo verify navigation happened correctly
Explain how to use cy.url() to check if the current URL contains a specific word.
Think about how to check if a string is part of another string.
You got /4 concepts.
    Describe the difference between asserting URL equality and URL inclusion in Cypress tests.
    Consider when you want the full URL vs just part of it.
    You got /4 concepts.