segment-boneyard / nightmare

A high-level browser automation library.
https://open.segment.com
19.54k stars 1.08k forks source link

expect alert after click #1582

Open raquelhortab opened 4 years ago

raquelhortab commented 4 years ago

Hi! I would like to test whether a specific alert is triggered after clicking a button. I know I can catch alert events with .on('page',..) but this will catch it even if it is called before clicking the button, or if it is triggered because of another interaction... in other words, it will catch no matter when the alert appears.

I was wondering how I could achieve that with nightmare. I thought a workaroud could be using a boolean variable and set it to true once the button has been clicked, and then, when catching the event, check if such variable had been set to true. However I don't think this is a good solution, it would be great if I could integrate it in a flow, something like:

.click("#thebutton")
.wait(alertraised)
.click("#otherbutton")
.wait(otheralertraised)

I hope I explained myself good enough

Thanks in advance!