import { browserSleep , isIOS , isMobileDevice , isSafari } from '../utils' ; export class PlayerPage { getWatchVideoPlayerCurrentTime ( ) { const elem = $ ( 'video' ) ; const p = isIOS ( ) ? elem . getAttribute ( 'currentTime' ) : elem . getProperty ( 'currentTime' ) ; return p . then ( t => parseInt ( t + '' , 10 ) ) . then ( t => Math . ceil ( t ) ) ; } waitUntilPlaylistInfo ( text , maxTime ) { return browser . waitUntil ( async ( ) => { await $ ( '.video-js' ) . click ( ) ; return ( await $ ( '.video-js .vjs-playlist-info' ) . getText ( ) ) . includes ( text ) ; } , { timeout : maxTime } ) ; } waitUntilPlayerWrapper ( ) { return browser . waitUntil ( async ( ) => { return ! ! ( await $ ( '#placeholder-preview' ) ) ; } ) ; } async playAndPauseVideo ( isAutoplay , waitUntilSec ) { const videojsElem = ( ) => $ ( 'div.video-js' ) ; await videojsElem ( ) . waitForExist ( ) ; if ( isIOS ( ) || isSafari ( ) || isMobileDevice ( ) ) { await browser . execute ( `document.querySelector('video').muted = true` ) ; await this . clickOnPlayButton ( ) ; } else if ( isAutoplay === false ) { await this . clickOnPlayButton ( ) ; } await browserSleep ( 2000 ) ; await browser . waitUntil ( async ( ) => { return ( await this . getWatchVideoPlayerCurrentTime ( ) ) >= waitUntilSec ; } ) ; await videojsElem ( ) . click ( ) ; } async playVideo ( ) { return this . clickOnPlayButton ( ) ; } private async clickOnPlayButton ( ) { const playButton = ( ) => $ ( '.vjs-big-play-button' ) ; await playButton ( ) . waitForClickable ( ) ; await playButton ( ) . click ( ) ; } }