Estoy tratando de acceder a los elementos dentro de mi iframe siguiendo los consejos enumerados en este artículo aquí , pero por alguna razón, Cypress no puede encontrar nada en el iframe.
Aquí está mi código de prueba
describe('example to-do app', () => { const getIframeDocument = () => { return cy .get('iframe[data-cy="iframe"]') .its('0.contentDocument').should('exist') } const getIframeBody = () => { return getIframeDocument() .its('body').should('not.be.undefined') .then(cy.wrap) } it('finds the root', () => { cy.visit('http://localhost:3000/view') getIframeBody().get('#root'); }) });Y este es mi iframe
<iframe data-cy="iframe" title="iframe" style={{ height: '100%', width: '100%' }} src={url} />
Finalmente esto es lo que tengo en mi cypress.json
{ "chromeWebSecurity": false }Esto se basa en el artículo anterior. No estoy seguro de dónde me estoy equivocando.
Puede usar un complemento llamado cypress-iframe . Después de la instalación, vaya a cypress/support/commands.js y agregue lo siguiente:
import 'cypress-iframe';En su prueba puede usar directamente:
cy.iframe('[data-cy="iframe"]').find('.some-button').should('be.visible').click() cy.iframe('[data-cy="iframe"]').contains('Some element').should('not.be.visible')