* Selects an Iframe and returns its body when it's done loading. * @param {string} selector - The selector for the iframe. * @returns {Function} A function that returns the wrapped body of the iframe.
(selector)
| 12 | * @returns {Function} A function that returns the wrapped body of the iframe. |
| 13 | */ |
| 14 | function enterIframe(selector) { |
| 15 | return cy.get(selector, {log: false}).then({timeout: 30000}, async (frame) => { |
| 16 | const contentWindow = frame.prop('contentWindow'); |
| 17 | |
| 18 | while ( |
| 19 | contentWindow.location.toString() === 'about:blank' || |
| 20 | contentWindow.document.readyState !== 'complete' |
| 21 | ) { |
| 22 | await new Promise((resolve) => setTimeout(resolve)); |
| 23 | } |
| 24 | |
| 25 | // return the body of the iframe wrapped in cypress |
| 26 | return () => cy.wrap(contentWindow.document.body); |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | Cypress.Commands.add('enterIframe', enterIframe); |