Challenge - 5 Problems
CSS Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ assertion
intermediate2:00remaining
Check background color of a button
You want to verify that a button with id
#submitBtn has a background color of rgb(0, 128, 0). Which Cypress assertion is correct?Cypress
cy.get('#submitBtn').should('have.css', 'background-color', 'rgb(0, 128, 0)')
Attempts:
2 left
💡 Hint
Use the correct assertion method to check CSS properties.
✗ Incorrect
The correct Cypress assertion to check CSS properties is 'have.css'. Option B uses it correctly. Option B uses 'css' which is not a valid assertion. Option B tries to check an attribute which is incorrect for CSS properties. Option B uses 'have.style' which is not a valid Cypress assertion.
❓ assertion
intermediate2:00remaining
Verify font size of a paragraph
Which Cypress command correctly asserts that a paragraph with class
.intro has a font size of 16px?Cypress
cy.get('.intro').should('have.css', 'font-size', '16px')
Attempts:
2 left
💡 Hint
Remember CSS properties are checked with 'have.css' in Cypress.
✗ Incorrect
Option A correctly uses 'have.css' to check the font size. Option A incorrectly uses 'have.attr' which checks HTML attributes, not CSS. Option A uses 'contain.css' which is not a valid assertion. Option A uses 'have.style' which is invalid in Cypress.
❓ Predict Output
advanced2:00remaining
Output of CSS color assertion failure
What will be the test result when running this Cypress code if the element's color is
rgb(255, 0, 0) but the assertion expects rgb(0, 0, 255)?Cypress
cy.get('.title').should('have.css', 'color', 'rgb(0, 0, 255)')
Attempts:
2 left
💡 Hint
Think about what happens when expected and actual CSS values differ.
✗ Incorrect
Cypress assertions compare exact CSS values. Since the actual color is red (rgb(255, 0, 0)) but the test expects blue (rgb(0, 0, 255)), the test fails with an assertion error showing the mismatch. There is no syntax error or warning in this case.
❓ locator
advanced2:00remaining
Best locator for CSS assertion on a disabled button
You want to assert the opacity of a disabled button. Which locator is best to select the disabled button for CSS assertion?
Attempts:
2 left
💡 Hint
Consider how HTML disabled attribute works and how to select it in CSS.
✗ Incorrect
Option D correctly selects buttons with the disabled attribute regardless of its value. Option D uses the :disabled pseudo-class which works but is less explicit in Cypress selectors. Option D looks for disabled="true" which is incorrect because disabled attribute is boolean and usually has no value or empty. Option D selects buttons with class 'disabled' which is different from the disabled attribute.
❓ framework
expert3:00remaining
Handling dynamic CSS changes in Cypress tests
You have a button that changes its background color from
rgb(255, 0, 0) to rgb(0, 255, 0) after a click. Which Cypress code correctly asserts this dynamic CSS change?Attempts:
2 left
💡 Hint
Check the initial state before click and then the changed state after click.
✗ Incorrect
Option A first asserts the initial background color, then clicks, then asserts the changed color. This ensures the test checks both states clearly. Option A only checks after click, missing initial state. Option A separates commands but may cause timing issues. Option A uses then callback unnecessarily and may cause flaky tests.