aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/po/player.po.ts
blob: e41422359744c0716bb104d027b7b1ac7a75eff4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { browserSleep, isIOS, isMobileDevice, isSafari } from '../utils'

export class PlayerPage {

  getWatchVideoPlayerCurrentTime () {
    const elem = $('video')

    const p = isIOS()
      ? elem.getAttribute('currentTime')
      : elem.getProperty('currentTime')

    return p.then(t => parseInt(t + '', 10))
            .then(t => Math.ceil(t))
  }

  waitUntilPlaylistInfo (text: string, maxTime: number) {
    return browser.waitUntil(async () => {
      // Without this we have issues on iphone
      await $('.video-js').click()

      return (await $('.video-js .vjs-playlist-info').getText()).includes(text)
    }, { timeout: maxTime })
  }

  waitUntilPlayerWrapper () {
    return browser.waitUntil(async () => {
      return !!(await $('#placeholder-preview'))
    })
  }

  async playAndPauseVideo (isAutoplay: boolean, waitUntilSec: number) {
    // Autoplay is disabled on mobile and Safari
    if (isIOS() || isSafari() || isMobileDevice() || isAutoplay === false) {
      await this.playVideo()
    }

    await $('div.video-js.vjs-has-started').waitForExist()

    await browserSleep(2000)

    await browser.waitUntil(async () => {
      return (await this.getWatchVideoPlayerCurrentTime()) >= waitUntilSec
    })

    // Pause video
    await $('div.video-js').click()
  }

  async playVideo () {
    await $('div.video-js.vjs-paused').waitForExist()

    // 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`)
    }

    return this.clickOnPlayButton()
  }

  private async clickOnPlayButton () {
    const playButton = () => $('.vjs-big-play-button')

    await playButton().waitForClickable()
    await playButton().click()
  }

  async fillEmbedVideoPassword (videoPassword: string) {
    const videoPasswordInput = $('input#video-password-input')
    const confirmButton = await $('button#video-password-submit')

    await videoPasswordInput.clearValue()
    await videoPasswordInput.setValue(videoPassword)
    await confirmButton.waitForClickable()

    return confirmButton.click()
  }
}