describe('CSS Assertions for Submit Button', () => {
beforeEach(() => {
cy.visit('https://example.com'); // Replace with actual homepage URL
});
it('should have correct CSS properties on submit button', () => {
// Locate the button by id
cy.get('#submit-btn')
// Assert background color
.should('have.css', 'background-color', 'rgb(0, 123, 255)')
// Assert font size
.and('have.css', 'font-size', '16px')
// Assert border radius
.and('have.css', 'border-radius', '4px');
});
});This Cypress test suite named CSS Assertions for Submit Button runs on the homepage URL.
The beforeEach hook opens the homepage before each test.
The test locates the button with id submit-btn using cy.get('#submit-btn').
It then asserts the CSS properties using should('have.css', property, value):
- background-color is checked as
rgb(0, 123, 255) because browsers return colors in rgb format. - font-size is checked as
16px. - border-radius is checked as
4px.
Using chaining with .and() keeps the assertions clean and readable.
This approach follows Cypress best practices for CSS assertions and element selection.