0
0
Cypresstesting~10 mins

cy.location() for URL parts 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 the current URL's pathname using cy.location().

Cypress
cy.location('[1]').should('eq', '/dashboard')
Drag options to blanks, or click blank then click option'
Apathname
Bhost
Chref
Dprotocol
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'href' instead of 'pathname' returns the full URL, not just the path.
Using 'host' or 'protocol' returns other parts of the URL, not the path.
2fill in blank
medium

Complete the code to assert the URL's protocol is HTTPS using cy.location().

Cypress
cy.location('[1]').should('eq', 'https:')
Drag options to blanks, or click blank then click option'
Aprotocol
Bhost
Corigin
Dpathname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'host' returns the domain, not the protocol.
Using 'pathname' returns the path, not the protocol.
3fill in blank
hard

Fix the error in the code to correctly check the URL's hash using cy.location().

Cypress
cy.location().[1].should('eq', '#section1')
Drag options to blanks, or click blank then click option'
Ahost
Bhref
Chash
Dpathname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'href' returns the full URL, not just the hash.
Using 'pathname' or 'host' returns other parts of the URL.
4fill in blank
hard

Fill in the blank to assert the URL's host (including port if present) using cy.location().

Cypress
cy.location().[1].should('eq', 'example.com:3000')
Drag options to blanks, or click blank then click option'
Ahostname
Bhost
Cport
Dorigin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hostname' returns only the domain without the port.
Using 'origin' returns protocol + host, not just host and port.
5fill in blank
hard

Fill all three blanks to create a test that checks the URL's origin, pathname, and search query using cy.location().

Cypress
cy.location().[1].should('eq', 'https://example.com')
cy.location().[2].should('eq', '/products')
cy.location().[3].should('eq', '?category=books')
Drag options to blanks, or click blank then click option'
Aorigin
Bpathname
Csearch
Dhash
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'hash' with 'search' for query parameters.
Using 'host' instead of 'origin' for full protocol and domain.