Reputation: 595
Usually Cypress should close popup window (confirmation or alert) automatically by confirming it. So we can use
cy.on('window:confirm', ($txt) => {
cy.log('This is confirmation text: ' + $txt)
})
for using this event for grabbing the popup text. But in my case the popup is not closed and the test is not able to continue after the confirmation popup comes up. The test stops and waits forever. Also the dialog can't be closed. Is there any solution for this? Is there any solution to close such dialog? The scenario is: click a button, the confirmation dialog (actually popup modal belonged to browser, but not Cypress) with two buttons comes up. Click the dialog OK button. Then the next alert popup with only one button appears. Close this popup and validate its text.
Upvotes: 0
Views: 1568
Reputation: 595
I had the same assumption as suggested by you. But finally I found out that it was a very specific case related to this certain application. The point is that it has a weird behavior in Cypress test. On a certain stage after some request is fired the page starts shrinking. The cypress runner window height starts reducing and stops in the middle when the first popup (confirm) comes up. And this was the reason why the popup was not closed by Cypress automatically. I tried to configure the test by disabling scrolling with scrollBehavior: false
and it stopped shrinkage but the elements outside the screen became inaccessible. So the only bypass I found was creation an additional test block it() right after the point where the shrinkage started. In this block I used the single command for navigation to another domain page. It stopped the shrinkage. After that I created new test block where I called the target page where the popups are used. After this everything started working properly. Cypress starts closing the popups automatically and it was possible to use events 'window:confirm'
and 'window:alert'
for validating the popups text. Very specific and weird case.
Upvotes: 0