-import { by, element, browser } from 'protractor'
+import { browserSleep, FIXTURE_URLS, go } from '../utils'
export class VideoWatchPage {
- async goOnVideosList (isIphoneDevice: boolean) {
- let url: string
-
- if (isIphoneDevice === true) {
- // Local testing is buggy :/
- url = 'https://peertube2.cpy.re/videos/local'
- } else {
- url = '/videos/recently-added'
- }
- await browser.get(url)
- return browser.wait(browser.ExpectedConditions.elementToBeClickable(element(this.getFirstVideoListSelector())))
- }
+ constructor (private isMobileDevice: boolean, private isSafari: boolean) {
- getVideosListName () {
- return element.all(this.getFirstVideoListSelector())
- .getText()
- .then((texts: any) => texts.map(t => t.trim()))
}
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))
- }
-
- async pauseVideo (pauseAfterMs: number, isMobileDevice: boolean, isIphoneDevice: boolean) {
- if (isMobileDevice === true) {
- if (isIphoneDevice === false) {
- const playButton = element(by.css('.vjs-big-play-button'))
- await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
- await playButton.click()
- } else {
- const playButton = element(by.css('video'))
- await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
- await playButton.click()
+ if (this.isSafari) return browserSleep(5000)
+
+ // On mobile we display the first node, on desktop the second
+ const index = this.isMobileDevice ? 0 : 1
+
+ return browser.waitUntil(async () => {
+ return (await $$('.video-info .video-info-name')[index].getText()).includes(videoName)
+ })
+ }
+
+ getVideoName () {
+ return this.getVideoNameElement().then(e => e.getText())
+ }
+
+ getPrivacy () {
+ return $('.attribute-privacy .attribute-value').getText()
+ }
+
+ getLicence () {
+ return $('.attribute-licence .attribute-value').getText()
+ }
+
+ async isDownloadEnabled () {
+ await this.clickOnMoreDropdownIcon()
+
+ return $('.dropdown-item .icon-download').isExisting()
+ }
+
+ areCommentsEnabled () {
+ return $('my-video-comment-add').isExisting()
+ }
+
+ isPrivacyWarningDisplayed () {
+ return $('my-privacy-concerns').isDisplayed()
+ }
+
+ async goOnAssociatedEmbed () {
+ let url = await browser.getUrl()
+ url = url.replace('/w/', '/videos/embed/')
+ url = url.replace(':3333', ':9001')
+
+ await go(url)
+ await $('.vjs-big-play-button').waitForDisplayed()
+ }
+
+ async isEmbedWarningDisplayed () {
+ const text = await $('.vjs-dock-description').getText()
+
+ return !!text.trim()
+ }
+
+ goOnP2PMediaLoaderEmbed () {
+ return go(FIXTURE_URLS.HLS_EMBED)
+ }
+
+ goOnP2PMediaLoaderPlaylistEmbed () {
+ return go(FIXTURE_URLS.HLS_PLAYLIST_EMBED)
+ }
+
+ async clickOnUpdate () {
+ await this.clickOnMoreDropdownIcon()
+
+ const items = await $$('.dropdown-menu.show .dropdown-item')
+
+ for (const item of items) {
+ const href = await item.getAttribute('href')
+
+ if (href?.includes('/update/')) {
+ await item.click()
+ return
}
}
+ }
- await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
+ clickOnSave () {
+ return $('.action-button-save').click()
+ }
- const el = element(by.css('div.video-js'))
- await browser.wait(browser.ExpectedConditions.elementToBeClickable(el))
+ async createPlaylist (name: string) {
+ const newPlaylistButton = () => $('.new-playlist-button')
- await browser.sleep(pauseAfterMs)
+ await newPlaylistButton().waitForClickable()
+ await newPlaylistButton().click()
- if (isIphoneDevice === true) {
- // document.webkitCancelFullScreen()
- } else {
- return el.click()
- }
+ const displayName = () => $('#displayName')
+
+ await displayName().waitForDisplayed()
+ await displayName().setValue(name)
+
+ return $('.new-playlist-block input[type=submit]').click()
}
- async clickOnVideo (videoName: string) {
- const video = element(by.css('.videos .video-miniature .video-thumbnail[title="' + videoName + '"]'))
- await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
- await video.click()
+ async saveToPlaylist (name: string) {
+ const playlist = () => $('my-video-add-to-playlist').$(`.playlist=${name}`)
+
+ await playlist().waitForDisplayed()
- await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
+ return playlist().click()
}
- async clickOnFirstVideo () {
- const video = element(by.css('.videos .video-miniature:first-child .video-miniature-name'))
- await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
- const textToReturn = video.getText()
+ waitUntilVideoName (name: string, maxTime: number) {
+ return browser.waitUntil(async () => {
+ return (await this.getVideoName()) === name
+ }, { timeout: maxTime })
+ }
- await video.click()
+ async clickOnMoreDropdownIcon () {
+ const dropdown = $('my-video-actions-dropdown .action-button')
+ await dropdown.click()
- await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
- return textToReturn
+ await $('.dropdown-menu.show .dropdown-item').waitForDisplayed()
}
- private getFirstVideoListSelector () {
- return by.css('.videos .video-miniature-name')
+ private async getVideoNameElement () {
+ // We have 2 video info name block, pick the first that is not empty
+ 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()
}
}