0
0
Cypresstesting~10 mins

expect() for BDD assertions in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if a button with the ID submit-btn is visible and enabled on the page using Cypress expect() BDD assertions.

Test Code - Cypress
Cypress
describe('Button visibility and state test', () => {
  it('should verify the submit button is visible and enabled', () => {
    cy.visit('https://example.com')
    cy.get('#submit-btn').then(($btn) => {
      expect($btn).to.be.visible
      expect($btn).to.be.enabled
    })
  })
})
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to 'https://example.com'Browser shows the homepage of example.com-PASS
3Find element with selector '#submit-btn' using cy.getButton with ID 'submit-btn' is present in the DOMElement found successfullyPASS
4Use expect() to check if the button is visibleButton is visible on the pageexpect($btn).to.be.visiblePASS
5Use expect() to check if the button is enabledButton is enabled and clickableexpect($btn).to.be.enabledPASS
6Test ends successfullyAll assertions passed, test complete-PASS
Failure Scenario
Failing Condition: The button with ID 'submit-btn' is either not visible or disabled
Execution Trace Quiz - 3 Questions
Test your understanding
What does the step 'cy.get('#submit-btn')' do in the test?
AClicks the button with ID 'submit-btn'
BFinds the button element with ID 'submit-btn' on the page
CChecks if the button is visible
DNavigates to the submit page
Key Result
Using <code>expect()</code> with Cypress allows clear, readable checks of element states like visibility and enabled status, making tests easy to understand and maintain.