Bird
0
0

Given the code:

medium📝 Predict Output Q4 of 15
Cypress - Assertions
Given the code:
cy.get('input#username').should('have.attr', 'placeholder', 'Enter username')

What will happen if the input's placeholder is actually 'Enter user'?
AThe test will pass because the attribute exists
BThe test will ignore the placeholder attribute
CThe test will fail because the attribute value does not match
DThe test will throw a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand 'have.attr' with value check

    This assertion checks both presence and exact value of the attribute.
  2. Step 2: Compare expected vs actual attribute value

    The expected is 'Enter username' but actual is 'Enter user', so they differ.
  3. Final Answer:

    The test will fail because the attribute value does not match -> Option C
  4. Quick Check:

    have.attr with value = exact attribute value match [OK]
Quick Trick: Attribute value must match exactly for 'have.attr' with value [OK]
Common Mistakes:
  • Assuming attribute presence is enough to pass
  • Confusing attribute value with partial match
  • Expecting no error on mismatch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes