Created
          September 2, 2019 17:17 
        
      - 
      
- 
        Save bahrmichael/401b6c37ed3191879a6292977ba09470 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Cypress.Commands.add( | |
| 'iframeLoaded', | |
| {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) | |
| ); | |
| Cypress.Commands.add( | |
| 'getWithinIframe', | |
| (targetElement) => cy.get('iframe').iframeLoaded().its('document').getInDocument(targetElement) | |
| ); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment