1 import { browserSleep, isIOS, isMobileDevice, isSafari } from '../utils'
3 export class PlayerPage {
5 getWatchVideoPlayerCurrentTime () {
6 const elem = $('video')
9 return elem.getAttribute('currentTime')
10 .then(t => parseInt(t, 10))
11 .then(t => Math.round(t))
14 return elem.getProperty('currentTime')
17 waitUntilPlaylistInfo (text: string, maxTime: number) {
18 return browser.waitUntil(async () => {
19 return (await $('.video-js .vjs-playlist-info').getText()).includes(text)
20 }, { timeout: maxTime })
23 waitUntilPlayerWrapper () {
24 return browser.waitUntil(async () => {
25 return !!(await $('#placeholder-preview'))
29 async playAndPauseVideo (isAutoplay: boolean) {
30 const videojsElem = () => $('div.video-js')
32 await videojsElem().waitForExist()
34 // Autoplay is disabled on iOS and Safari
35 if (isIOS() || isSafari() || isMobileDevice()) {
36 // We can't play the video using protractor if it is not muted
37 await browser.execute(`document.querySelector('video').muted = true`)
38 await this.clickOnPlayButton()
39 } else if (isAutoplay === false) {
40 await this.clickOnPlayButton()
43 await browserSleep(2000)
45 await browser.waitUntil(async () => {
46 return !await $('.vjs-loading-spinner').isDisplayedInViewport()
47 }, { timeout: 20 * 1000 })
49 await browserSleep(4000)
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()