PeerTube/client/e2e/src/po/video-watch.po.ts

92 lines
3.0 KiB
TypeScript
Raw Normal View History

2018-05-24 14:33:58 +02:00
import { browser, by, element } from 'protractor'
2018-05-17 10:55:01 +02:00
export class VideoWatchPage {
2018-05-24 09:05:58 +02:00
async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
2018-05-19 13:58:29 +02:00
let url: string
2018-05-24 09:05:58 +02:00
// We did not upload a file on a mobile device
if (isMobileDevice === true || isSafari === true) {
2018-05-19 13:58:29 +02:00
url = 'https://peertube2.cpy.re/videos/local'
} else {
url = '/videos/recently-added'
}
2018-05-17 10:55:01 +02:00
await browser.get(url)
2018-05-22 16:02:29 +02:00
// Waiting the following element does not work on Safari...
if (isSafari === true) return browser.sleep(3000)
const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
2018-05-17 10:55:01 +02:00
}
getVideosListName () {
2018-05-22 16:02:29 +02:00
return element.all(by.css('.videos .video-miniature .video-miniature-name'))
2018-05-19 13:58:29 +02:00
.getText()
.then((texts: any) => texts.map(t => t.trim()))
2018-05-17 10:55:01 +02:00
}
2018-05-24 09:05:58 +02:00
waitWatchVideoName (videoName: string, isSafari: boolean) {
2018-05-17 10:55:01 +02:00
const elem = element(by.css('.video-info .video-info-name'))
2018-05-24 09:05:58 +02:00
if (isSafari) return browser.sleep(5000)
2018-05-17 10:55:01 +02:00
return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName))
}
getWatchVideoPlayerCurrentTime () {
return element(by.css('.video-js .vjs-current-time-display'))
.getText()
.then((t: string) => t.split(':')[1])
.then(seconds => parseInt(seconds, 10))
}
2018-05-24 14:33:58 +02:00
async pauseVideo (isAutoplay: boolean) {
2018-05-22 16:02:29 +02:00
if (isAutoplay === false) {
const playButton = element(by.css('.vjs-big-play-button'))
await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
await playButton.click()
}
await browser.sleep(1000)
2018-05-18 11:02:40 +02:00
await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
2018-05-24 09:05:58 +02:00
const videojsEl = element(by.css('div.video-js'))
await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
2018-05-17 10:55:01 +02:00
2018-05-24 09:05:58 +02:00
await browser.sleep(7000)
2018-05-18 11:02:40 +02:00
2018-05-24 09:05:58 +02:00
return videojsEl.click()
2018-05-17 10:55:01 +02:00
}
2018-05-18 11:02:40 +02:00
async clickOnVideo (videoName: string) {
const video = element(by.css('.videos .video-miniature .video-thumbnail[title="' + videoName + '"]'))
2018-05-19 13:58:29 +02:00
await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
await video.click()
await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
}
async clickOnFirstVideo () {
2018-05-24 09:05:58 +02:00
const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
// Don't know why but the expectation fails on Safari
2018-05-19 13:58:29 +02:00
await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
2018-05-17 10:55:01 +02:00
2018-05-24 09:05:58 +02:00
const textToReturn = videoName.getText()
2018-05-17 10:55:01 +02:00
await video.click()
await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
2018-05-19 13:58:29 +02:00
return textToReturn
2018-05-17 10:55:01 +02:00
}
2018-05-22 16:02:29 +02:00
async goOnAssociatedEmbed () {
let url = await browser.getCurrentUrl()
url = url.replace('/watch/', '/embed/')
url = url.replace(':3333', ':9001')
return browser.get(url)
2018-05-17 10:55:01 +02:00
}
}