]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/player.po.ts
Migrate to webdriverio
[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 if (isIOS()) {
9 return elem.getAttribute('currentTime')
10 .then(t => parseInt(t, 10))
11 .then(t => Math.round(t))
12 }
13
14 return elem.getProperty('currentTime')
15 }
16
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 })
21 }
22
23 waitUntilPlayerWrapper () {
24 return browser.waitUntil(async () => {
25 return !!(await $('#placeholder-preview'))
26 })
27 }
28
29 async playAndPauseVideo (isAutoplay: boolean) {
30 const videojsElem = () => $('div.video-js')
31
32 await videojsElem().waitForExist()
33
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()
41 }
42
43 await browserSleep(2000)
44
45 await browser.waitUntil(async () => {
46 return !await $('.vjs-loading-spinner').isDisplayedInViewport()
47 }, { timeout: 20 * 1000 })
48
49 await browserSleep(4000)
50
51 await videojsElem().click()
52 }
53
54 async playVideo () {
55 return this.clickOnPlayButton()
56 }
57
58 private async clickOnPlayButton () {
59 const playButton = () => $('.vjs-big-play-button')
60
61 await playButton().waitForClickable()
62 await playButton().click()
63 }
64 }