]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/player.po.ts
Improve e2e workflow and add doc
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / player.po.ts
1 import { browserSleep, isIOS, isMobileDevice, isSafari } from '../utils'
2
3 export class PlayerPage {
4
5 getWatchVideoPlayerCurrentTime () {
6 const elem = $('video')
7
8 const p = isIOS()
9 ? elem.getAttribute('currentTime')
10 : elem.getProperty('currentTime')
11
12 return p.then(t => parseInt(t + '', 10))
13 .then(t => Math.ceil(t))
14 }
15
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 })
20 }
21
22 waitUntilPlayerWrapper () {
23 return browser.waitUntil(async () => {
24 return !!(await $('#placeholder-preview'))
25 })
26 }
27
28 async playAndPauseVideo (isAutoplay: boolean, waitUntilSec: number) {
29 const videojsElem = () => $('div.video-js')
30
31 await videojsElem().waitForExist()
32
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()
40 }
41
42 await browserSleep(2000)
43
44 await browser.waitUntil(async () => {
45 return (await this.getWatchVideoPlayerCurrentTime()) >= 2
46 })
47
48 await videojsElem().click()
49 }
50
51 async playVideo () {
52 return this.clickOnPlayButton()
53 }
54
55 private async clickOnPlayButton () {
56 const playButton = () => $('.vjs-big-play-button')
57
58 await playButton().waitForClickable()
59 await playButton().click()
60 }
61 }