1 import { by, element, browser } from 'protractor'
3 export class VideoWatchPage {
4 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
7 // We did not upload a file on a mobile device
8 if (isMobileDevice === true || isSafari === true) {
9 url = 'https://peertube2.cpy.re/videos/local'
11 url = '/videos/recently-added'
14 await browser.get(url)
16 // Waiting the following element does not work on Safari...
17 if (isSafari === true) return browser.sleep(3000)
19 const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
20 return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
23 getVideosListName () {
24 return element.all(by.css('.videos .video-miniature .video-miniature-name'))
26 .then((texts: any) => texts.map(t => t.trim()))
29 waitWatchVideoName (videoName: string, isSafari: boolean) {
30 const elem = element(by.css('.video-info .video-info-name'))
32 if (isSafari) return browser.sleep(5000)
34 return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName))
37 getWatchVideoPlayerCurrentTime () {
38 return element(by.css('.video-js .vjs-current-time-display'))
40 .then((t: string) => t.split(':')[1])
41 .then(seconds => parseInt(seconds, 10))
44 async pauseVideo (isAutoplay: boolean, isDesktopSafari: boolean) {
45 if (isAutoplay === false) {
46 const playButton = element(by.css('.vjs-big-play-button'))
47 await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
48 await playButton.click()
51 // if (isDesktopSafari === true) {
52 // await browser.sleep(1000)
53 // await element(by.css('.vjs-play-control')).click()
56 await browser.sleep(1000)
57 await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
59 const videojsEl = element(by.css('div.video-js'))
60 await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
62 await browser.sleep(7000)
64 return videojsEl.click()
67 async clickOnVideo (videoName: string) {
68 const video = element(by.css('.videos .video-miniature .video-thumbnail[title="' + videoName + '"]'))
69 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
72 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
75 async clickOnFirstVideo () {
76 const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
77 const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
79 // Don't know why but the expectation fails on Safari
80 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
82 const textToReturn = videoName.getText()
85 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
89 async goOnAssociatedEmbed () {
90 let url = await browser.getCurrentUrl()
91 url = url.replace('/watch/', '/embed/')
92 url = url.replace(':3333', ':9001')
94 return browser.get(url)