top of page

Cypress: Popups & ToolTips

Updated: Jul 30

As a Quality Engineer, one common challenge in automated UI testing is handling popups — especially window.alert, window.confirm, and window.prompt. Cypress makes this easier by allowing you to intercept and stub these native browser dialogs.


This guide walks you through practical methods to handle and assert browser dialogs using Cypress, with multiple approaches to validating window.confirm.


Handling window.confirm in Cypress


Cypress gives us full control over how to respond to a window.confirm dialog. You can:

  • Automatically accept it (true)

  • Automatically cancel it (false)

  • Validate the message

  • Stub the function and check how it was called


Method 1: Return false to cancel the confirmation

This simulates a user clicking Cancel on the confirmation dialog.


Method 2: Return true to confirm the action

This simulates a user clicking OK.


Method 3: Validate the message inside the confirmation

This lets you confirm that the message shown is exactly what you expect.


Method 4: Use a stub and assert how it was called

This is useful when you want to verify the dialog call without necessarily reacting to it.


Handling window.alert

Cypress automatically handles alerts (clicks OK), but you can assert the message like this:

Full Real-World Examples

All three methods work — it's just a matter of what you're testing: behavior, message correctness, or response simulation.


Resources


 
 
bottom of page