DEV Community

Tejkumar Kempaiah
Tejkumar Kempaiah

Posted on

🔥 JavaScript Alerts in Cypress

Alerts are pop up's that appear on the browser window based on a specific user action which is "Click"

There are 3 types of alerts.

  1. Simple alerts with alert text, Ok button
  2. Confirm alerts with alert text, Ok & Cancel button
  3. Prompt alerts with alert text box, Ok & Cancel button

Note:

The way cypress are handled in cypress aren't the same way just like in case of Selenium.

In Selenium, Where there is a pop up alert on the screen.
The user should navigate to the alert pop to perform action.

But, In cypress simple alerts are handled by default as its one of the in-built capabilities of Cypress.

Cypress for now directly supports simple and confirm alerts.
Where as for prompt based alerts, One must use cy.window() with a then call back function along with a stub to handle it.

Example:

image

Top comments (0)