Bird
0
0

Which of the following is the correct syntax to get the protocol part of the URL using cy.location()?

easy📝 Syntax Q3 of 15
Cypress - Navigation and URL
Which of the following is the correct syntax to get the protocol part of the URL using cy.location()?
Acy.location('protocol').should('eq', 'https:')
Bcy.location.protocol().should('eq', 'https:')
Ccy.location('protocol') === 'https:'
Dcy.location.get('protocol').should('eq', 'https:')
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct cy.location() usage

    The correct way is to pass the property name as a string argument to cy.location(), then chain assertions.
  2. Step 2: Check syntax validity

    cy.location('protocol').should('eq', 'https:') uses cy.location('protocol').should('eq', 'https:'), which is valid Cypress syntax.
  3. Final Answer:

    cy.location('protocol').should('eq', 'https:') -> Option A
  4. Quick Check:

    Correct syntax = cy.location('protocol').should('eq', 'https:') [OK]
Quick Trick: Use cy.location('property') to get URL parts [OK]
Common Mistakes:
  • Calling protocol as a method
  • Using === outside Cypress chain
  • Using get() method which doesn't exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes