0
0
Cypresstesting~10 mins

CSS assertions in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the element has the correct background color.

Cypress
cy.get('.button').should('have.css', 'background-color', [1]);
Drag options to blanks, or click blank then click option'
A'rgba(255, 0, 0, 1)'
B'red'
C'rgb(255, 0, 0)'
D'#ff0000'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color names like 'red' instead of rgba format.
Using hex codes which Cypress does not return in computed styles.
2fill in blank
medium

Complete the code to assert that the element is visible and has the correct font size.

Cypress
cy.get('#title').should('be.visible').and('have.css', 'font-size', [1]);
Drag options to blanks, or click blank then click option'
A'16em'
B'1.6rem'
C'16pt'
D'16px'
Attempts:
3 left
💡 Hint
Common Mistakes
Using rem, pt, or em units which Cypress does not return in computed styles.
3fill in blank
hard

Fix the error in the code to correctly assert the element's border style.

Cypress
cy.get('.card').should('have.css', 'border-style', [1]);
Drag options to blanks, or click blank then click option'
A'border: 1px solid black'
B'1px solid black'
C'solid'
D'solid 1px black'
Attempts:
3 left
💡 Hint
Common Mistakes
Using full border shorthand values instead of just the style.
Including width or color in the assertion value.
4fill in blank
hard

Fill both blanks to assert the element's text color and font weight.

Cypress
cy.get('.header').should('have.css', 'color', [1]).and('have.css', 'font-weight', [2]);
Drag options to blanks, or click blank then click option'
A'rgb(0, 0, 0)'
B'bold'
C'700'
D'black'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color names instead of rgb values.
Using 'bold' instead of '700' for font-weight.
5fill in blank
hard

Fill all three blanks to assert the element's margin, padding, and display properties.

Cypress
cy.get('.container').should('have.css', 'margin', [1]).and('have.css', 'padding', [2]).and('have.css', 'display', [3]);
Drag options to blanks, or click blank then click option'
A'16px'
B'0px'
C'flex'
D'block'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up margin and padding values.
Using incorrect display values like 'inline-block' if not set.