Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.location('hostname') check in this test?
cy.location('pathname') return in a Cypress test?cy.location() usagecy.location() command gets parts of the current URL in Cypress tests./home or /about.cy.location()?cy.location()cy.location('hostname') to get the hostname string.https://example.com/products?item=123#details, what will cy.location('search') return??, here it is ?item=123.cy.location('search') returns? symbol.cy.location('hash').should('eq', 'details') to check the URL hash #details. Why does this test fail?cy.location('hash') returns# symbol, e.g., #details.'details' without #, so it fails because the strings don't match exactly.https://shop.com/cart?item=5#checkout. Which chained Cypress commands correctly check the protocol, pathname, search, and hash parts?cy.location() returns a promise, so you call them separately for each part.cy.location() separately for each part with correct expected values including ':' in protocol and leading '/' in pathname.location() calls incorrectly (no chaining support). cy.location('protocol').should('eq', 'https')
cy.location('pathname').should('eq', 'cart')
cy.location('search').should('eq', 'item=5')
cy.location('hash').should('eq', 'checkout') misses ':' and leading characters. cy.location().should('eq', 'https://shop.com/cart?item=5#checkout') compares full URL string which is not supported by cy.location().Pass the test and this pattern moves unknown