1 import { browserSleep, isIOS, isMobileDevice, isSafari } from '../utils'
3 export class PlayerPage {
5 getWatchVideoPlayerCurrentTime () {
6 const elem = $('video')
9 ? elem.getAttribute('currentTime')
10 : elem.getProperty('currentTime')
12 return p.then(t => parseInt(t + '', 10))
13 .then(t => Math.ceil(t))
16 waitUntilPlaylistInfo (text: string, maxTime: number) {
17 return browser.waitUntil(async () => {
18 // Without this we have issues on iphone
19 await $('.video-js').click()
21 return (await $('.video-js .vjs-playlist-info').getText()).includes(text)
22 }, { timeout: maxTime })
25 waitUntilPlayerWrapper () {
26 return browser.waitUntil(async () => {
27 return !!(await $('#placeholder-preview'))
31 async playAndPauseVideo (isAutoplay: boolean, waitUntilSec: number) {
32 const videojsElem = () => $('div.video-js')
34 await videojsElem().waitForExist()
36 // Autoplay is disabled on iOS and Safari
37 if (isIOS() || isSafari() || isMobileDevice()) {
38 // We can't play the video if it is not muted
39 await browser.execute(`document.querySelector('video').muted = true`)
40 await this.clickOnPlayButton()
41 } else if (isAutoplay === false) {
42 await this.clickOnPlayButton()
45 await browserSleep(2000)
47 await browser.waitUntil(async () => {
48 return (await this.getWatchVideoPlayerCurrentTime()) >= waitUntilSec
51 await videojsElem().click()
55 return this.clickOnPlayButton()
58 private async clickOnPlayButton () {
59 const playButton = () => $('.vjs-big-play-button')
61 await playButton().waitForClickable()
62 await playButton().click()