cypress-example-recipes
cypress-example-recipes copied to clipboard
iframe - how to expect document.ReadyState == complete and others waiting techniques
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
https://dev.to/mkubdev/cypress-iframes-1ole?signin=true