Bird
0
0

You want to verify that a button with class .submit-btn has a border radius of 5 pixels and a background color that is not transparent. Which Cypress code correctly asserts both styles?

hard📝 framework Q15 of 15
Cypress - Assertions
You want to verify that a button with class .submit-btn has a border radius of 5 pixels and a background color that is not transparent. Which Cypress code correctly asserts both styles?
Acy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color').not('transparent')
Bcy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color', 'rgba(0, 0, 0, 0)')
Ccy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color').should(value => expect(value).not.to.equal('rgba(0, 0, 0, 0)'))
Dcy.get('.submit-btn').should('have.css', 'border-radius', 5).and('have.css', 'background-color', 'transparent')"
Step-by-Step Solution
Solution:
  1. Step 1: Assert border-radius with correct value and type

    Use should('have.css', 'border-radius', '5px') to check border radius as a string with units.
  2. Step 2: Assert background-color is not transparent

    Since 'transparent' can be represented as 'rgba(0, 0, 0, 0)', use a callback assertion to check the value is not equal to that.
  3. Step 3: Review options for correctness

    cy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color').should(value => expect(value).not.to.equal('rgba(0, 0, 0, 0)')) uses a callback with should and expect to verify background-color is not transparent, which is correct.
  4. Final Answer:

    cy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color').should(value => expect(value).not.to.equal('rgba(0, 0, 0, 0)')) -> Option C
  5. Quick Check:

    Use callback assertions for negative CSS checks [OK]
Quick Trick: Use callback assertions to check CSS values are not equal [OK]
Common Mistakes:
  • Passing numeric values without units for CSS properties
  • Trying to chain 'not' directly after 'have.css' without callback
  • Checking for exact transparent string instead of rgba value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes