Bird
0
0

Which Cypress command correctly asserts that an element has a margin of 10 pixels?

easy📝 Conceptual Q2 of 15
Cypress - Assertions
Which Cypress command correctly asserts that an element has a margin of 10 pixels?
Acy.get('div').should('have.attr', 'margin', '10px')
Bcy.get('div').should('have.css', 'margin', '10px')
Ccy.get('div').should('contain', 'margin: 10px')
Dcy.get('div').should('have.text', 'margin: 10px')
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct assertion for CSS property

    The have.css assertion checks CSS properties. Margin is a CSS property, so use have.css.
  2. Step 2: Verify correct syntax

    The syntax cy.get('div').should('have.css', 'margin', '10px') correctly asserts the margin value.
  3. Final Answer:

    cy.get('div').should('have.css', 'margin', '10px') -> Option B
  4. Quick Check:

    CSS property check = B [OK]
Quick Trick: Use 'have.css' for CSS properties, not 'have.attr' [OK]
Common Mistakes:
  • Using 'have.attr' for CSS properties
  • Checking text content instead of CSS
  • Using 'contain' for CSS assertions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes