Test Overview
This test opens a simple web page, clicks a button, and verifies that the button click changes the text on the page. It demonstrates how Cypress runs tests inside the browser and interacts with page elements.
This test opens a simple web page, clicks a button, and verifies that the button click changes the text on the page. It demonstrates how Cypress runs tests inside the browser and interacts with page elements.
describe('Button click changes text', () => { it('should change text when button is clicked', () => { cy.visit('https://example.cypress.io/commands/actions') cy.get('.action-btn').first().click() cy.get('.action-btn').first().should('have.text', 'Clicked!') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner initializes | — | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io/commands/actions' | Browser shows the Cypress example actions page | — | PASS |
| 3 | Finds the first button with class '.action-btn' | Button element is located in the DOM | — | PASS |
| 4 | Clicks the found button | Button is clicked, triggering any click handlers | — | PASS |
| 5 | Checks that the button text changed to 'Clicked!' | Button text is updated in the DOM | Verify button text equals 'Clicked!' | PASS |
cy. followed by the command name, so cy.visit() is correct.describe('My Test', () => {
it('checks page title', () => {
cy.visit('https://example.cypress.io')
cy.title().should('include', 'Kitchen')
})
})cy.title() is a valid Cypress command that gets the page title. The assertion should('include', 'Kitchen') checks if the title contains 'Kitchen'.it('checks button click', () => {
cy.visit('https://example.com')
cy.get('#submit').click
})click command must be called as a function with parentheses: click().#submit is valid, cy.visit() can be inside the test, and chaining should() is optional.Pass the test and this pattern moves unknown