Last active
February 5, 2024 12:26
-
-
Save ironboy/f5b6663ea4c9704efb5aeda248386343 to your computer and use it in GitHub Desktop.
Idea find iframe play button trailer
This file contains 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
const getIframeDocument = () => { | |
return cy | |
.get('iframe[title="YouTube video player"]]') | |
// Cypress yields jQuery element, which has the real | |
// DOM element under property "0". | |
// From the real DOM iframe element we can get | |
// the "document" element, it is stored in "contentDocument" property | |
// Cypress "its" command can access deep properties using dot notation | |
// https://on.cypress.io/its | |
.its('0.contentDocument').should('exist') | |
} | |
const getIframeBody = () => { | |
// get the document | |
return getIframeDocument() | |
// automatically retries until body is loaded | |
.its('body').should('not.be.undefined') | |
// wraps "body" DOM element to allow | |
// chaining more Cypress commands, like ".find(...)" | |
.then(cy.wrap) | |
} | |
When('I click the play button', () => { | |
getIframeBody().find('.ytp-large-play-button').click(); | |
}); | |
Then('the trailer should play', () => { | |
// How do we check that it plays? | |
// Could we check that the second counter is moving or something similar? | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment