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'.
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'.
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') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io/commands/actions' | Browser displays the Cypress example actions page | — | PASS |
| 3 | Finds input element with class '.action-email' | Input field is visible and ready for typing | — | PASS |
| 4 | Types 'Hello' into the input field | Input field value is now 'Hello' | Check input field has value 'Hello' | PASS |
| 5 | Finds button element with class '.action-btn' | Button is visible on the page | — | PASS |
| 6 | Checks button has attribute 'type' with value 'submit' | Button attribute 'type' equals 'submit' | Verify button's 'type' attribute is 'submit' | PASS |
cy.get('input').should('have.value', 'hello') check?should('have.value', 'hello') which asserts the value property of the input.disabled?should('have.attr', 'attributeName').should('have.attr', 'disabled').cy.get('input#email')
.should('have.attr', 'placeholder', 'Enter your email')
.and('have.value', '')should('have.attr', 'placeholder', 'Enter your email') checks the placeholder attribute equals 'Enter your email'.and('have.value', '') asserts the input's current value is empty (no text typed).cy.get('input[name="username"]').should('have.value', 'admin')have.value fails, likely 'admin' is placeholder text, not actual value.data-test with value agree. Which Cypress assertion chain is correct?should('be.checked').should('have.attr', 'data-test', 'agree').and() to check both conditions on the same element.Pass the test and this pattern moves unknown