← Back to library
Cypressassertionsbeginnerv10+

Assert text, visibility, and value

Core assertion patterns you'll use in almost every test.

1it('covers core assertions', () => {
2  cy.visit('/profile');
3
4  // Text content
5  cy.get('h1').should('contain.text', 'Welcome');
6
7  // Visibility
8  cy.get('.error-banner').should('not.exist');
9  cy.get('.success-msg').should('be.visible');
10
11  // Input value
12  cy.get('[name="email"]').should('have.value', 'user@test.com');
13
14  // Attribute
15  cy.get('img.avatar').should('have.attr', 'alt', 'User avatar');
16
17  // CSS class
18  cy.get('.btn-primary').should('have.class', 'active');
19});
#should#contain#visible#value#assert