PeerTube/client/e2e/src/po/player.po.ts

62 lines
1.6 KiB
TypeScript
Raw Normal View History

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