0
0
Cypresstesting~10 mins

Value and attribute assertions in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if an input field has the correct value and if a button has the expected attribute. It verifies that the input contains the text 'Hello' and the button has a 'type' attribute set to 'submit'.

Test Code - Cypress
Cypress
describe('Value and attribute assertions test', () => {
  it('checks input value and button attribute', () => {
    cy.visit('https://example.cypress.io/commands/actions')
    cy.get('.action-email')
      .type('Hello')
      .should('have.value', 'Hello')
    cy.get('.action-btn')
      .should('have.attr', 'type', 'submit')
  })
})
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to 'https://example.cypress.io/commands/actions'Browser displays the Cypress example actions page-PASS
3Finds input element with class '.action-email'Input field is visible and ready for typing-PASS
4Types 'Hello' into the input fieldInput field value is now 'Hello'Check input field has value 'Hello'PASS
5Finds button element with class '.action-btn'Button is visible on the page-PASS
6Checks button has attribute 'type' with value 'submit'Button attribute 'type' equals 'submit'Verify button's 'type' attribute is 'submit'PASS
Failure Scenario
Failing Condition: Input field does not contain the value 'Hello' or button does not have attribute 'type'='submit'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the input field?
AIt has the value 'Hello'
BIt is visible on the page
CIt is disabled
DIt has a placeholder text
Key Result
Always assert both the value and attributes of elements to ensure the UI behaves as expected and the elements have correct properties.