0
0
Cypresstesting~20 mins

CSS assertions in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
assertion
intermediate
2: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)')
Acy.get('#submitBtn').should('have.style', 'background-color', 'rgb(0, 128, 0)')
Bcy.get('#submitBtn').should('have.css', 'background-color', 'rgb(0, 128, 0)')
Ccy.get('#submitBtn').should('have.attr', 'background-color', 'rgb(0, 128, 0)')
D)')0 ,821 ,0(bgr' ,'roloc-dnuorgkcab' ,'ssc.evah'(dluohs.)'ntBtimbus#'(teg.yc
Attempts:
2 left
💡 Hint
Use the correct assertion method to check CSS properties.
assertion
intermediate
2: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')
Acy.get('.intro').should('have.css', 'font-size', '16px')
Bcy.get('.intro').should('have.attr', 'font-size', '16px')
Ccy.get('.intro').should('contain.css', 'font-size', '16px')
Dcy.get('.intro').should('have.style', 'font-size', '16px')
Attempts:
2 left
💡 Hint
Remember CSS properties are checked with 'have.css' in Cypress.
Predict Output
advanced
2: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)')
ATest fails with a syntax error in the test code
BTest passes because color values are case-insensitive
CTest fails with an assertion error showing expected 'rgb(0, 0, 255)' but found 'rgb(255, 0, 0)'
DTest passes but logs a warning about color mismatch
Attempts:
2 left
💡 Hint
Think about what happens when expected and actual CSS values differ.
locator
advanced
2: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?
Acy.get('button:disabled')
Bcy.get('button[disabled="true"]')
Ccy.get('button.disabled')
Dcy.get('button[disabled]')
Attempts:
2 left
💡 Hint
Consider how HTML disabled attribute works and how to select it in CSS.
framework
expert
3: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?
Acy.get('#colorBtn').should('have.css', 'background-color', 'rgb(255, 0, 0)').click().should('have.css', 'background-color', 'rgb(0, 255, 0)')
Bcy.get('#colorBtn').click().should('have.css', 'background-color', 'rgb(0, 255, 0)')
Ccy.get('#colorBtn').click(); cy.get('#colorBtn').should('have.css', 'background-color', 'rgb(0, 255, 0)')
Dcy.get('#colorBtn').click().then(() => { cy.get('#colorBtn').should('have.css', 'background-color', 'rgb(0, 255, 0)') })
Attempts:
2 left
💡 Hint
Check the initial state before click and then the changed state after click.