1 import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
2 import { browserSleep } from '../utils'
4 export class VideoWatchPage {
5 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
8 // We did not upload a file on a mobile device
9 if (isMobileDevice === true || isSafari === true) {
10 url = 'https://peertube2.cpy.re/videos/local'
12 url = '/videos/recently-added'
15 await browser.get(url, 20000)
17 // Waiting the following element does not work on Safari...
18 if (isSafari) return browserSleep(3000)
20 const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
21 return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
24 getVideosListName () {
25 return element.all(by.css('.videos .video-miniature .video-miniature-name'))
27 .then((texts: any) => texts.map((t: any) => t.trim()))
30 waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) {
31 if (isSafari) return browserSleep(5000)
33 // On mobile we display the first node, on desktop the second
34 const index = isMobileDevice ? 0 : 1
36 const elem = element.all(by.css('.video-info .video-info-name')).get(index)
37 return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName))
40 getWatchVideoPlayerCurrentTime () {
41 return element(by.css('.video-js .vjs-current-time-display'))
43 .then((t: string) => t.split(':')[1])
44 .then(seconds => parseInt(seconds, 10))
48 return this.getVideoNameElement().getText()
51 async playAndPauseVideo (isAutoplay: boolean, isMobileDevice: boolean) {
52 if (isAutoplay === false) {
53 const playButton = element(by.css('.vjs-big-play-button'))
54 await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
55 await playButton.click()
58 await browserSleep(1000)
59 await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
61 const videojsEl = element(by.css('div.video-js'))
62 await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
64 // On Android, we need to click twice on "play" (BrowserStack particularity)
66 await browserSleep(3000)
68 await videojsEl.click()
71 browser.ignoreSynchronization = false
72 await browserSleep(7000)
73 browser.ignoreSynchronization = true
75 await videojsEl.click()
78 async clickOnVideo (videoName: string) {
79 const video = element.all(by.css('.videos .video-miniature .video-miniature-name'))
80 .filter(e => e.getText().then(t => t === videoName ))
83 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
86 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
89 async clickOnFirstVideo () {
90 const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
91 const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
93 // Don't know why but the expectation fails on Safari
94 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
96 const textToReturn = videoName.getText()
99 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
103 async goOnAssociatedEmbed () {
104 let url = await browser.getCurrentUrl()
105 url = url.replace('/watch/', '/embed/')
106 url = url.replace(':3333', ':9001')
108 return browser.get(url)
111 async goOnP2PMediaLoaderEmbed () {
112 return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50')
115 async clickOnUpdate () {
116 const dropdown = element(by.css('my-video-actions-dropdown .action-button'))
117 await dropdown.click()
119 const items: ElementFinder[] = await element.all(by.css('my-video-actions-dropdown .dropdown-menu .dropdown-item'))
121 for (const item of items) {
122 const href = await item.getAttribute('href')
124 if (href && href.includes('/update/')) {
131 async clickOnSave () {
132 return element(by.css('.action-button-save')).click()
135 async createPlaylist (name: string) {
136 await element(by.css('.new-playlist-button')).click()
138 await element(by.css('#displayName')).sendKeys(name)
140 return element(by.css('.new-playlist-block input[type=submit]')).click()
143 async saveToPlaylist (name: string) {
144 return element.all(by.css('my-video-add-to-playlist .playlist'))
145 .filter(p => p.getText().then(t => t === name))
149 waitUntilVideoName (name: string, maxTime: number) {
150 const elem = this.getVideoNameElement()
152 return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime)
155 private getVideoNameElement () {
156 // We have 2 video info name block, pick the first that is not empty
157 return element.all(by.css('.video-info-first-row .video-info-name'))
158 .filter(e => e.getText().then(t => !!t))