cypress-example-recipes icon indicating copy to clipboard operation
cypress-example-recipes copied to clipboard

iframe - how to expect document.ReadyState == complete and others waiting techniques

Open andreabisello opened this issue 3 years ago • 1 comments

i studied these examples

https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/blogs__iframes

to handle iframes.

i think no one of these examples handle the problem of the iframe loading state, so often i need to put a cy.wait() before trying the access of the elements in order to wait until the iframe is loaded.

to avoid the use of a cy.wait() i wait until the iframe should('have.text','something inside the iframe') before to proceed, and this help solving the problem. Similar to https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/blogs__iframes/cypress/integration/button-spec.js i do

Cypress.Commands.add('getIframeDocument', (stringToWait) => {
    return cy
        .get('iframe[name=radWindowLavorazioneContratto]', {timeout:10000 , includeShadowDom:true})
        .its('0.contentDocument.body').should('contain.text',stringToWait)
    })

Why this approach is never documented? maybe is not required and i'm making something wrong?

Anyway i think the right way is to wait until the property

document.readyState is equal to 'complete'.

how to access this property?

0.contentDocument doesn't contains this property, the property readyState is related to document , not contentDocument.

thanks for any suggestion

andreabisello avatar Nov 03 '21 11:11 andreabisello

https://dev.to/mkubdev/cypress-iframes-1ole?signin=true

janat08 avatar Jun 05 '22 13:06 janat08