0
0
Cypresstesting~10 mins

Multiple assertions chaining in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a webpage, finds a button, clicks it, and then checks multiple things about a message that appears. It verifies the message is visible, has the correct text, and has the right CSS color.

Test Code - Cypress
Cypress
describe('Multiple assertions chaining test', () => {
  it('checks message visibility, text, and color after button click', () => {
    cy.visit('https://example.cypress.io')
    cy.get('#show-message-btn').click()
    cy.get('#message')
      .should('be.visible')
      .and('have.text', 'Hello, Cypress!')
      .and('have.css', 'color', 'rgb(0, 128, 0)')
  })
})
Execution Trace - 9 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner is ready to execute the test-PASS
2Browser opens and navigates to 'https://example.cypress.io'The example Cypress page is loaded in the browser-PASS
3Find element with id 'show-message-btn' using cy.getButton with id 'show-message-btn' is found on the page-PASS
4Click the button '#show-message-btn'Button is clicked, triggering message display-PASS
5Find element with id 'message' using cy.getMessage element is present in the DOM-PASS
6Assert the message is visible using .should('be.visible')Message is visible on the pageMessage visibility is truePASS
7Assert the message text is 'Hello, Cypress!' using .and('have.text', ...)Message text content is 'Hello, Cypress!'Message text matches expectedPASS
8Assert the message CSS color is 'rgb(0, 128, 0)' using .and('have.css', ...)Message color style is green (rgb(0, 128, 0))Message color matches expectedPASS
9Test ends successfullyAll assertions passed, test completed-PASS
Failure Scenario
Failing Condition: The message element is not visible, or text/color does not match expected values
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check after clicking the button?
AThat the message is visible, has correct text, and correct color
BThat the button disappears
CThat the page URL changes
DThat an alert pops up
Key Result
Chaining multiple assertions on the same element in Cypress makes tests concise and readable while verifying several properties in one go.