Consider the following Cypress test code that checks the URL parts using cy.location(). What will be the value of pathname logged?
cy.visit('https://example.com/products/item1?ref=123') .location('pathname') .then(pathname => { cy.log(pathname) })
Remember that pathname returns only the path part of the URL, excluding domain and query parameters.
The pathname property of cy.location() returns the path after the domain, without query strings or protocol. So it is /products/item1.
You want to check that the current URL contains the query string ?user=admin. Which Cypress assertion is correct?
Which part of the URL contains the query string?
The search property of cy.location() returns the query string including the leading question mark. So cy.location('search').should('eq', '?user=admin') is correct.
Examine the test code below. It fails even though the URL is correct. What is the reason?
cy.visit('https://myapp.test/dashboard') cy.location('hostname').should('eq', 'myapp.test')
Check the exact string returned by cy.location('hostname') and compare with the expected value.
The hostname property returns the domain without any trailing slash. The expected value incorrectly includes a slash, so the assertion fails.
You want to capture the entire URL string of the current page in Cypress. Which property of cy.location() gives you this?
Think about which property includes protocol, domain, path, and query.
The href property returns the full URL string including protocol, domain, path, and query parameters.
You want to assert that the URL's protocol is https: and the pathname is /home. Which code snippet correctly performs both assertions?
Consider how to access multiple properties from cy.location() in one callback.
Option A uses cy.location() without arguments to get the full location object, then asserts multiple properties inside a single should callback. This is the correct and efficient way.