Test Overview
This test uses the cypress-real-events plugin to simulate a native click event on a button. It verifies that the button's click handler is triggered and the expected text appears on the page.
This test uses the cypress-real-events plugin to simulate a native click event on a button. It verifies that the button's click handler is triggered and the expected text appears on the page.
import 'cypress-real-events/support'; describe('Native click event test with cypress-real-events', () => { it('should trigger native click and show confirmation text', () => { cy.visit('https://example.cypress.io/commands/actions'); cy.get('.action-btn').realClick(); cy.get('.action-btn').should('have.class', 'clicked'); cy.get('#action-callback').should('contain.text', 'Button clicked'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner is ready | — | PASS |
| 2 | Browser opens and navigates to https://example.cypress.io/commands/actions | Page with action buttons is loaded | Page URL is correct | PASS |
| 3 | Find element with class '.action-btn' | Button element is visible and enabled | Element exists and is visible | PASS |
| 4 | Perform native click on the button using realClick() | Button receives native click event | — | PASS |
| 5 | Check if button has class 'clicked' after click | Button class list updated to include 'clicked' | Button has class 'clicked' | PASS |
| 6 | Check if element with id '#action-callback' contains text 'Button clicked' | Confirmation text is displayed on page | Text 'Button clicked' is present | PASS |
cypress-real-events in Cypress tests?cypress-real-events providesrealClick from cypress-real-events in a test?realClick() on the element returned by cy.get().cy.get('#input').realType('Hello');
cy.get('#input').should('have.value', 'Hello');realType doesrealType sends native keyboard events to type text into input fields, updating their value.realType.cy.get('#submit').realClick();realClick requires the element to be visible and enabled to send native click events.realClick is valid and selector syntax is correct, so these are unlikely causes.cypress-real-events method should you use to trigger this tooltip reliably?cypress-real-events methodrealHover() sends native mouse hover events, triggering tooltips reliably.Pass the test and this pattern moves unknown