2020-08-26 07:38:34 -05:00
|
|
|
import { browserSleep, isIOS, isMobileDevice, isSafari } from '../utils'
|
2020-08-07 03:25:07 -05:00
|
|
|
|
|
|
|
export class PlayerPage {
|
|
|
|
|
2021-08-30 09:24:25 -05:00
|
|
|
getWatchVideoPlayerCurrentTime () {
|
|
|
|
const elem = $('video')
|
2021-03-05 03:26:10 -06:00
|
|
|
|
2021-09-02 01:57:59 -05:00
|
|
|
const p = isIOS()
|
|
|
|
? elem.getAttribute('currentTime')
|
|
|
|
: elem.getProperty('currentTime')
|
2020-08-07 03:25:07 -05:00
|
|
|
|
2021-09-02 01:57:59 -05:00
|
|
|
return p.then(t => parseInt(t + '', 10))
|
|
|
|
.then(t => Math.ceil(t))
|
2021-08-30 09:24:25 -05:00
|
|
|
}
|
2020-08-07 03:25:07 -05:00
|
|
|
|
2021-08-30 09:24:25 -05:00
|
|
|
waitUntilPlaylistInfo (text: string, maxTime: number) {
|
|
|
|
return browser.waitUntil(async () => {
|
|
|
|
return (await $('.video-js .vjs-playlist-info').getText()).includes(text)
|
|
|
|
}, { timeout: maxTime })
|
2020-08-07 03:25:07 -05:00
|
|
|
}
|
|
|
|
|
2020-11-30 02:11:12 -06:00
|
|
|
waitUntilPlayerWrapper () {
|
2021-08-30 09:24:25 -05:00
|
|
|
return browser.waitUntil(async () => {
|
|
|
|
return !!(await $('#placeholder-preview'))
|
|
|
|
})
|
2020-11-30 02:11:12 -06:00
|
|
|
}
|
|
|
|
|
2021-09-02 01:57:59 -05:00
|
|
|
async playAndPauseVideo (isAutoplay: boolean, waitUntilSec: number) {
|
2021-08-30 09:24:25 -05:00
|
|
|
const videojsElem = () => $('div.video-js')
|
|
|
|
|
|
|
|
await videojsElem().waitForExist()
|
2020-08-26 07:38:34 -05:00
|
|
|
|
|
|
|
// Autoplay is disabled on iOS and Safari
|
2021-08-30 09:24:25 -05:00
|
|
|
if (isIOS() || isSafari() || isMobileDevice()) {
|
2020-08-26 07:38:34 -05:00
|
|
|
// We can't play the video using protractor if it is not muted
|
2021-08-30 09:24:25 -05:00
|
|
|
await browser.execute(`document.querySelector('video').muted = true`)
|
2020-08-26 07:38:34 -05:00
|
|
|
await this.clickOnPlayButton()
|
|
|
|
} else if (isAutoplay === false) {
|
2020-08-07 03:25:07 -05:00
|
|
|
await this.clickOnPlayButton()
|
|
|
|
}
|
|
|
|
|
|
|
|
await browserSleep(2000)
|
|
|
|
|
2021-08-30 09:24:25 -05:00
|
|
|
await browser.waitUntil(async () => {
|
2021-09-02 01:57:59 -05:00
|
|
|
return (await this.getWatchVideoPlayerCurrentTime()) >= 2
|
|
|
|
})
|
2021-08-30 09:24:25 -05:00
|
|
|
|
|
|
|
await videojsElem().click()
|
2020-08-07 03:25:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async playVideo () {
|
|
|
|
return this.clickOnPlayButton()
|
|
|
|
}
|
|
|
|
|
|
|
|
private async clickOnPlayButton () {
|
2021-08-30 09:24:25 -05:00
|
|
|
const playButton = () => $('.vjs-big-play-button')
|
|
|
|
|
|
|
|
await playButton().waitForClickable()
|
|
|
|
await playButton().click()
|
2020-08-07 03:25:07 -05:00
|
|
|
}
|
|
|
|
}
|