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 return (await $('.video-js .vjs-playlist-info').getText()).includes(text)
19 }, { timeout: maxTime })
22 waitUntilPlayerWrapper () {
23 return browser.waitUntil(async () => {
24 return !!(await $('#placeholder-preview'))
28 async playAndPauseVideo (isAutoplay: boolean, waitUntilSec: number) {
29 const videojsElem = () => $('div.video-js')
31 await videojsElem().waitForExist()
33 // Autoplay is disabled on iOS and Safari
34 if (isIOS() || isSafari() || isMobileDevice()) {
35 // We can't play the video using protractor if it is not muted
36 await browser.execute(`document.querySelector('video').muted = true`)
37 await this.clickOnPlayButton()
38 } else if (isAutoplay === false) {
39 await this.clickOnPlayButton()
42 await browserSleep(2000)
44 await browser.waitUntil(async () => {
45 return (await this.getWatchVideoPlayerCurrentTime()) >= 2
48 await videojsElem().click()
52 return this.clickOnPlayButton()
55 private async clickOnPlayButton () {
56 const playButton = () => $('.vjs-big-play-button')
58 await playButton().waitForClickable()
59 await playButton().click()