Plugin cypress-iframe
https://www.npmjs.com/package/cypress-iframe
Install
import 'cypress-iframe' |
frameLoaded
// This will verify that the iframe is loaded to any page other than 'about:blank' |
iframe
// This will verify that the iframe is loaded to any page other than 'about:blank' |
Issue You may have
When you encounter an automation test case that requires you to open two browser tabs to execute it.
Then you will find that Cypress says they will never support for multiple browser tabs, after checking the official documentation.
https://docs.cypress.io/guides/references/trade-offs#Permanent-trade-offs-1
Here is My Solution
create an iframe by using Element.append() to complete it.
- create an iframe
https://stackoverflow.com/questions/8726455/creating-an-iframe-using-javascript- Element.append()
https://www.javascripttutorial.net/javascript-dom/javascript-append/- An Example For You
I can not show my code directly due to commercial reasons, so I wrote a demo using elements from ‘https://mochajs.org/‘.
it('test', () => {
cy.visit('https://mochajs.org/')
cy.get('main#content a').contains('Node.js').then(($el) => {
cy.get($el).click()
var iframe = document.createElement('iframe');
iframe.src = $el.href;
iframe.id = 'test'
iframe.width = 700
Cypress.$($el).append(iframe)
// cy.frameLoaded('#test')
// You can go on your automation
})
})