Skip to content

Instantly share code, notes, and snippets.

@vincentchalamon
Created December 9, 2019 14:28
Show Gist options
  • Save vincentchalamon/de9bbe4a5ee3faa78e8e448f74bf9320 to your computer and use it in GitHub Desktop.
Save vincentchalamon/de9bbe4a5ee3faa78e8e448f74bf9320 to your computer and use it in GitHub Desktop.
Cypress.io: parse iframe content
Cypress.Commands.add('iframe', {
prevSubject: 'element',
}, $iframe => {
const contentWindow = $iframe.prop('contentWindow');
return new Promise(resolve => {
if (contentWindow && contentWindow.document.readyState === 'complete') {
resolve(contentWindow);
} else {
$iframe.on('load', () => {
resolve(contentWindow);
});
}
});
});
Cypress.Commands.add('getInDocument', {
prevSubject: 'document',
}, (document, selector) => Cypress.$(selector, document));
@vincentchalamon
Copy link
Author

Usage:

cy.get('#foo > iframe').iframe().its('document').getInDocument('#bar');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment