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

163 lines
5.2 KiB
TypeScript
Raw Normal View History

2019-06-17 08:11:25 +02:00
import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
2020-05-13 10:15:31 +02:00
import { browserSleep, isIOS, isMobileDevice } from '../utils'
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
2020-05-12 16:38:55 +02:00
await browser.get(url, 20000)
2018-05-22 16:02:29 +02:00
// Waiting the following element does not work on Safari...
2020-05-12 16:38:55 +02:00
if (isSafari) return browserSleep(3000)
2018-05-22 16:02:29 +02:00
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) {
2020-05-12 16:38:55 +02:00
if (isSafari) return browserSleep(5000)
2018-09-20 15:45:11 +02:00
// 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-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-06-17 08:11:25 +02:00
getVideoName () {
return this.getVideoNameElement().getText()
}
2020-05-13 10:15:31 +02:00
async playAndPauseVideo (isAutoplay: boolean) {
// Autoplay is disabled on iOS
if (isAutoplay === false || await isIOS()) {
2018-05-22 16:02:29 +02:00
const playButton = element(by.css('.vjs-big-play-button'))
await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
await playButton.click()
}
2020-05-13 10:15:31 +02:00
await browserSleep(2000)
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)
2020-05-13 10:15:31 +02:00
if (await isMobileDevice()) {
await browserSleep(5000)
2020-05-12 16:38:55 +02:00
2018-06-08 14:20:43 +02:00
await videojsEl.click()
}
2020-05-12 16:38:55 +02:00
browser.ignoreSynchronization = false
await browserSleep(7000)
browser.ignoreSynchronization = true
2018-05-18 11:02:40 +02:00
2020-05-12 16:38:55 +02:00
await videojsEl.click()
2018-05-17 10:55:01 +02:00
}
2018-05-18 11:02:40 +02:00
async clickOnVideo (videoName: string) {
2020-05-10 10:36:42 +02:00
const video = element.all(by.css('.videos .video-miniature .video-miniature-name'))
.filter(e => e.getText().then(t => t === videoName ))
.first()
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 () {
2020-05-11 10:48:42 +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()
2018-05-24 09:05:58 +02:00
// 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
2020-05-11 10:48:42 +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 () {
2020-05-11 09:41:39 +02:00
return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50')
2019-02-21 11:24:07 +01:00
}
2019-06-17 08:11:25 +02:00
async clickOnUpdate () {
const dropdown = element(by.css('my-video-actions-dropdown .action-button'))
await dropdown.click()
const items: ElementFinder[] = await element.all(by.css('my-video-actions-dropdown .dropdown-menu .dropdown-item'))
for (const item of items) {
const href = await item.getAttribute('href')
if (href && href.includes('/update/')) {
await item.click()
return
}
}
}
async clickOnSave () {
return element(by.css('.action-button-save')).click()
}
2019-06-18 10:20:55 +02:00
async createPlaylist (name: string) {
await element(by.css('.new-playlist-button')).click()
await element(by.css('#displayName')).sendKeys(name)
return element(by.css('.new-playlist-block input[type=submit]')).click()
}
async saveToPlaylist (name: string) {
return element.all(by.css('my-video-add-to-playlist .playlist'))
.filter(p => p.getText().then(t => t === name))
.click()
2019-06-17 08:11:25 +02:00
}
waitUntilVideoName (name: string, maxTime: number) {
const elem = this.getVideoNameElement()
return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime)
}
private getVideoNameElement () {
// We have 2 video info name block, pick the first that is not empty
2020-05-10 10:36:42 +02:00
return element.all(by.css('.video-info-first-row .video-info-name'))
2019-06-17 08:11:25 +02:00
.filter(e => e.getText().then(t => !!t))
.first()
}
2018-05-17 10:55:01 +02:00
}