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

105 lines
3.5 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()
2018-10-18 14:35:31 +02:00
.then((texts: any) => texts.map((t: any) => t.trim()))
2018-05-17 10:55:01 +02:00
}
2018-09-20 15:45:11 +02:00
waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) {
// On mobile we display the first node, on desktop the second
const index = isMobileDevice ? 0 : 1
const elem = element.all(by.css('.video-info .video-info-name')).get(index)
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))
}
2019-02-21 11:24:07 +01:00
async playAndPauseVideo (isAutoplay: boolean, isMobileDevice: 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-06-08 14:20:43 +02:00
// On Android, we need to click twice on "play" (BrowserStack particularity)
if (isMobileDevice) {
await browser.sleep(3000)
await videojsEl.click()
}
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
}
2019-02-21 11:24:07 +01:00
async goOnP2PMediaLoaderEmbed () {
2019-05-14 13:59:10 +02:00
return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50?mode=p2p-media-loader')
2019-02-21 11:24:07 +01:00
}
2018-05-17 10:55:01 +02:00
}