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

163 lines
4.2 KiB
TypeScript
Raw Normal View History

2021-09-02 08:57:59 +02:00
import { FIXTURE_URLS } from '../urls'
2021-08-30 16:24:25 +02:00
import { browserSleep, go } 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
2021-08-30 16:24:25 +02:00
await go(url)
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
2021-08-30 16:24:25 +02:00
await $('.videos .video-miniature .video-miniature-name').waitForDisplayed()
2018-05-17 10:55:01 +02:00
}
2021-08-30 16:24:25 +02:00
async getVideosListName () {
const elems = await $$('.videos .video-miniature .video-miniature-name')
const texts = await Promise.all(elems.map(e => e.getText()))
return texts.map(t => 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
2021-08-30 16:24:25 +02:00
return browser.waitUntil(async () => {
return (await $$('.video-info .video-info-name')[index].getText()).includes(videoName)
})
2018-05-17 10:55:01 +02:00
}
2019-06-17 08:11:25 +02:00
getVideoName () {
2021-08-30 16:24:25 +02:00
return this.getVideoNameElement().then(e => e.getText())
2019-06-17 08:11:25 +02:00
}
2020-08-07 10:25:07 +02:00
async goOnAssociatedEmbed () {
2021-08-30 16:24:25 +02:00
let url = await browser.getUrl()
2021-08-26 09:15:59 +02:00
url = url.replace('/w/', '/videos/embed/')
2020-08-07 10:25:07 +02:00
url = url.replace(':3333', ':9001')
2020-05-12 16:38:55 +02:00
2021-08-30 16:24:25 +02:00
return go(url)
2020-08-07 10:25:07 +02:00
}
2018-06-08 14:20:43 +02:00
2021-08-30 16:24:25 +02:00
goOnP2PMediaLoaderEmbed () {
2021-09-02 08:57:59 +02:00
return go(FIXTURE_URLS.HLS_EMBED)
2020-08-07 10:25:07 +02:00
}
2018-05-18 11:02:40 +02:00
2021-08-30 16:24:25 +02:00
goOnP2PMediaLoaderPlaylistEmbed () {
2021-09-02 08:57:59 +02:00
return go(FIXTURE_URLS.HLS_PLAYLIST_EMBED)
2018-05-17 10:55:01 +02:00
}
2018-05-18 11:02:40 +02:00
async clickOnVideo (videoName: string) {
2021-08-30 16:24:25 +02:00
const video = async () => {
const videos = await $$('.videos .video-miniature .video-miniature-name').filter(async e => {
const t = await e.getText()
return t === videoName
})
return videos[0]
}
await browser.waitUntil(async () => {
const elem = await video()
2020-05-10 10:36:42 +02:00
2021-08-30 16:24:25 +02:00
return elem?.isClickable()
});
2018-05-19 13:58:29 +02:00
2021-08-30 16:24:25 +02:00
(await video()).click()
await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
2018-05-19 13:58:29 +02:00
}
async clickOnFirstVideo () {
2021-08-30 16:24:25 +02:00
const video = () => $('.videos .video-miniature .video-thumbnail')
const videoName = () => $('.videos .video-miniature .video-miniature-name')
await video().waitForClickable()
2018-05-24 09:05:58 +02:00
2021-08-30 16:24:25 +02:00
const textToReturn = await videoName().getText()
await video().click()
2018-05-17 10:55:01 +02:00
2021-08-30 16:24:25 +02:00
await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
2018-05-17 10:55:01 +02:00
2018-05-19 13:58:29 +02:00
return textToReturn
2018-05-17 10:55:01 +02:00
}
2019-06-17 08:11:25 +02:00
async clickOnUpdate () {
2021-08-30 16:24:25 +02:00
const dropdown = $('my-video-actions-dropdown .action-button')
2019-06-17 08:11:25 +02:00
await dropdown.click()
2021-08-30 16:24:25 +02:00
await $('.dropdown-menu.show .dropdown-item').waitForDisplayed()
const items = await $$('.dropdown-menu.show .dropdown-item')
2019-06-17 08:11:25 +02:00
for (const item of items) {
const href = await item.getAttribute('href')
2021-08-30 16:24:25 +02:00
if (href?.includes('/update/')) {
2019-06-17 08:11:25 +02:00
await item.click()
return
}
}
}
2021-08-30 16:24:25 +02:00
clickOnSave () {
return $('.action-button-save').click()
2019-06-17 08:11:25 +02:00
}
2019-06-18 10:20:55 +02:00
async createPlaylist (name: string) {
2021-08-30 16:24:25 +02:00
const newPlaylistButton = () => $('.new-playlist-button')
await newPlaylistButton().waitForClickable()
await newPlaylistButton().click()
const displayName = () => $('#displayName')
2019-06-18 10:20:55 +02:00
2021-08-30 16:24:25 +02:00
await displayName().waitForDisplayed()
await displayName().setValue(name)
2019-06-18 10:20:55 +02:00
2021-08-30 16:24:25 +02:00
return $('.new-playlist-block input[type=submit]').click()
2019-06-18 10:20:55 +02:00
}
async saveToPlaylist (name: string) {
2021-08-30 16:24:25 +02:00
const playlist = () => $('my-video-add-to-playlist').$(`.playlist=${name}`)
await playlist().waitForDisplayed()
return playlist().click()
2019-06-17 08:11:25 +02:00
}
waitUntilVideoName (name: string, maxTime: number) {
2021-08-30 16:24:25 +02:00
return browser.waitUntil(async () => {
return (await this.getVideoName()) === name
}, { timeout: maxTime })
2019-06-17 08:11:25 +02:00
}
2021-08-30 16:24:25 +02:00
private async getVideoNameElement () {
2019-06-17 08:11:25 +02:00
// We have 2 video info name block, pick the first that is not empty
2021-08-30 16:24:25 +02:00
const elem = async () => {
const elems = await $$('.video-info-first-row .video-info-name').filter(e => e.isDisplayed())
return elems[0]
}
await browser.waitUntil(async () => {
const e = await elem()
return e?.isDisplayed()
})
return elem()
2019-06-17 08:11:25 +02:00
}
2018-05-17 10:55:01 +02:00
}