-import { browser, by, element, ExpectedConditions } from 'protractor'
-import { browserSleep, isIOS, isMobileDevice } from '../utils'
+import { browserSleep, isIOS, isMobileDevice, isSafari } from '../utils'
export class PlayerPage {
getWatchVideoPlayerCurrentTime () {
- return element(by.css('.video-js .vjs-current-time-display'))
- .getText()
- .then((t: string) => t.split(':')[1])
- .then(seconds => parseInt(seconds, 10))
- }
+ const elem = $('video')
- waitUntilPlaylistInfo (text: string) {
- const elem = element(by.css('.video-js .vjs-playlist-info'))
+ const p = isIOS()
+ ? elem.getAttribute('currentTime')
+ : elem.getProperty('currentTime')
- return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, text))
+ return p.then(t => parseInt(t + '', 10))
+ .then(t => Math.ceil(t))
}
- async playAndPauseVideo (isAutoplay: boolean) {
- // Autoplay is disabled on iOS
- if (isAutoplay === false || await isIOS()) {
- await this.clickOnPlayButton()
- }
+ waitUntilPlaylistInfo (text: string, maxTime: number) {
+ return browser.waitUntil(async () => {
+ // Without this we have issues on iphone
+ await $('.video-js').click()
- await browserSleep(2000)
- await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
+ return (await $('.video-js .vjs-playlist-info').getText()).includes(text)
+ }, { timeout: maxTime })
+ }
+
+ waitUntilPlayerWrapper () {
+ return browser.waitUntil(async () => {
+ return !!(await $('#placeholder-preview'))
+ })
+ }
- const videojsEl = element(by.css('div.video-js'))
- await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
+ async playAndPauseVideo (isAutoplay: boolean, waitUntilSec: number) {
+ const videojsElem = () => $('div.video-js')
- // On Android, we need to click twice on "play" (BrowserStack particularity)
- if (await isMobileDevice()) {
- await browserSleep(5000)
+ await videojsElem().waitForExist()
- await videojsEl.click()
+ // Autoplay is disabled on iOS and Safari
+ if (isIOS() || isSafari() || isMobileDevice()) {
+ // We can't play the video if it is not muted
+ await browser.execute(`document.querySelector('video').muted = true`)
+ await this.clickOnPlayButton()
+ } else if (isAutoplay === false) {
+ await this.clickOnPlayButton()
}
- browser.ignoreSynchronization = false
- await browserSleep(7000)
- browser.ignoreSynchronization = true
+ await browserSleep(2000)
+
+ await browser.waitUntil(async () => {
+ return (await this.getWatchVideoPlayerCurrentTime()) >= waitUntilSec
+ })
- await videojsEl.click()
+ await videojsElem().click()
}
async playVideo () {
}
private async clickOnPlayButton () {
- const playButton = element(by.css('.vjs-big-play-button'))
- await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
- await playButton.click()
+ const playButton = () => $('.vjs-big-play-button')
+
+ await playButton().waitForClickable()
+ await playButton().click()
}
}