0
0
Cypresstesting~5 mins

cy.location() for URL parts in Cypress - Cheat Sheet & Quick Revision

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

cy.location() gets information about the current URL of the page under test. It helps you check parts like the hostname, pathname, or protocol.

Click to reveal answer
beginner
How do you check the current page's pathname using cy.location()?

You use cy.location('pathname') to get just the path part of the URL, like /about or /products/123.

Click to reveal answer
beginner
Which property would you use with cy.location() to verify the domain name?

Use cy.location('hostname') to get the domain name, like example.com.

Click to reveal answer
intermediate
How can you assert that the current URL uses HTTPS with cy.location()?

Check the protocol by using cy.location('protocol').should('eq', 'https:'). This confirms the page is loaded over HTTPS.

Click to reveal answer
intermediate
What is the difference between cy.url() and cy.location()?

cy.url() returns the full URL as a string. cy.location() returns an object with URL parts like pathname, hostname, and protocol. Use cy.location() to check specific parts easily.

Click to reveal answer
Which cy.location() property gives you the path after the domain?
Ahostname
Bpathname
Cprotocol
Dport
How do you check if the current page uses HTTPS with Cypress?
Acy.location('protocol').should('eq', 'https:')
Bcy.location('hostname').should('contain', 'https')
Ccy.url().should('include', 'https')
Dcy.location('pathname').should('eq', 'https')
What does cy.location('hostname') return?
AThe domain name like example.com
BThe URL query string
CThe path after the domain
DThe full URL
Which command returns the full URL as a string in Cypress?
Acy.location()
Bcy.location('pathname')
Ccy.url()
Dcy.location('protocol')
If you want to check the port number of the current URL, which cy.location() property do you use?
Aprotocol
Bhostname
Cpathname
Dport
Explain how to use cy.location() to verify different parts of a URL in a Cypress test.
Think about how you check the URL in pieces, not the whole string.
You got /4 concepts.
    Describe the difference between cy.url() and cy.location() and when to use each.
    Consider if you want the whole URL or just a piece.
    You got /4 concepts.