New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example of testing confirms and alerts triggered from within an iframe #410
Comments
Thanks! Do you know of a way to dismiss the confirm within the iframe, as if OK or Cancel was clicked? |
That is what the code above should do. This only works for iframe of the same origin of the main application under test though. |
Thank you very much. It looks like I'm able to stub the javascript function that calls confirm, but not the confirm itself. In my example, things are a little complicated, as I have an application with many nested iframes, and, I am using these instructions to open the application in a child window: https://glebbahmutov.com/blog/cypress-using-child-window/ Thanks! |
@jennifer-shehane I came across a situation where the code block you have mentioned above not working. I suspect the issue in my case is that the alert() was invoked inside a document ready again inside an internal same origin iframe which is not the top,
what my test has is,
Wonder if I missed anything but the only way I could pass this point in my test was to change the app side to fire the alert on the top iframe of the application using something like, parent.window.alert('Warning: some warning here'); which then automatically handle by cypress. And the above test block works smoothly when I stub a alert happen inside the same iframe but not inside document.ready, which is thee main reason I was inclined that this perhaps need a work out to correctly add the stub to the window instance. Any input on this would be highly appreciated. |
Are there any workarounds to handle these dialogs if the iframes are from different origins? |
How to handle alerts if it is triggered from nested iframe. Any example would be much appreciated. |
The iframes have to be of the same origin and the alert/confirm triggered by something other than
onload
of the iframe for the examples to work.Confirm
index.html
iframe.html
spec.js
Alert
index.html
iframe.html
The text was updated successfully, but these errors were encountered: