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

91 lines
2.9 KiB
TypeScript
Raw Normal View History

2018-05-17 03:55:01 -05:00
import { by, element, browser } from 'protractor'
export class VideoWatchPage {
2018-05-22 09:02:29 -05:00
async goOnVideosList (isIphoneDevice: boolean, isSafari: boolean) {
2018-05-19 06:58:29 -05:00
let url: string
if (isIphoneDevice === true) {
// Local testing is buggy :/
url = 'https://peertube2.cpy.re/videos/local'
} else {
url = '/videos/recently-added'
}
2018-05-17 03:55:01 -05:00
await browser.get(url)
2018-05-22 09:02:29 -05: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 03:55:01 -05:00
}
getVideosListName () {
2018-05-22 09:02:29 -05:00
return element.all(by.css('.videos .video-miniature .video-miniature-name'))
2018-05-19 06:58:29 -05:00
.getText()
.then((texts: any) => texts.map(t => t.trim()))
2018-05-17 03:55:01 -05:00
}
waitWatchVideoName (videoName: string) {
const elem = element(by.css('.video-info .video-info-name'))
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-22 09:02:29 -05:00
async pauseVideo (pauseAfterMs: number, isAutoplay: boolean, isSafari: boolean) {
if (isAutoplay === false) {
const playButton = element(by.css('.vjs-big-play-button'))
await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
await playButton.click()
}
if (isSafari === true) {
await browser.sleep(1000)
await element(by.css('.vjs-play-control')).click()
2018-05-19 06:58:29 -05:00
}
2018-05-22 09:02:29 -05:00
await browser.sleep(1000)
2018-05-18 04:02:40 -05:00
await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
const el = element(by.css('div.video-js'))
2018-05-17 03:55:01 -05:00
await browser.wait(browser.ExpectedConditions.elementToBeClickable(el))
2018-05-18 04:02:40 -05:00
await browser.sleep(pauseAfterMs)
2018-05-22 09:02:29 -05:00
return el.click()
2018-05-17 03:55:01 -05:00
}
2018-05-18 04:02:40 -05:00
async clickOnVideo (videoName: string) {
const video = element(by.css('.videos .video-miniature .video-thumbnail[title="' + videoName + '"]'))
2018-05-19 06:58:29 -05:00
await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
await video.click()
await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
}
async clickOnFirstVideo () {
2018-05-22 09:02:29 -05:00
const video = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
2018-05-19 06:58:29 -05:00
await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
const textToReturn = video.getText()
2018-05-17 03:55:01 -05:00
await video.click()
await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
2018-05-19 06:58:29 -05:00
return textToReturn
2018-05-17 03:55:01 -05:00
}
2018-05-22 09:02:29 -05: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 03:55:01 -05:00
}
}