0
0
Cypresstesting~10 mins

cy.url() assertions in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the URL includes the word 'dashboard'.

Cypress
cy.url().should([1], 'dashboard')
Drag options to blanks, or click blank then click option'
Aequal
Binclude
Chave.property
Dcontain
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'equal' instead of 'contain' will check for exact match, which is too strict.
Using 'have.property' is incorrect for URL string assertions.
2fill in blank
medium

Complete the code to assert that the URL exactly matches 'https://example.com/home'.

Cypress
cy.url().should([1], 'https://example.com/home')
Drag options to blanks, or click blank then click option'
Acontain
Binclude
Cequal
Dmatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contain' or 'include' will only check for partial match, not exact.
Using 'match' is for regex, not exact string match.
3fill in blank
hard

Fix the error in the code to assert the URL starts with 'https://'.

Cypress
cy.url().should('[1]', /^https:\/\//)
Drag options to blanks, or click blank then click option'
Amatch
Bequal
Ccontain
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contain' or 'include' does not support regex matching.
Using 'equal' expects exact string, not regex.
4fill in blank
hard

Fill both blanks to assert the URL does not include 'login' and is not equal to 'https://example.com/login'.

Cypress
cy.url().should([1], 'login').and('not.[2]', 'https://example.com/login')
Drag options to blanks, or click blank then click option'
Anot.include
Bequal
Ccontain
Dnot.equal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contain' in the first blank will fail because the instruction says 'does not include'.
Using 'equal' instead of 'not.equal' in the second blank will cause the assertion to fail.
5fill in blank
hard

Fill all three blanks to assert the URL matches regex /^https:\/\/app\./, contains 'dashboard', and is not equal to 'https://app.example.com/logout'.

Cypress
cy.url().should('[1]', /^https:\/\/app\./).and('[2]', 'dashboard').and('not.[3]', 'https://app.example.com/logout')
Drag options to blanks, or click blank then click option'
Amatch
Bcontain
Cequal
Dnot.equal
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'equal' and 'not.equal' will cause wrong assertion results.
Using 'include' instead of 'contain' is invalid in Cypress assertions.