1 import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
3 export class VideoWatchPage {
4 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
7 // We did not upload a file on a mobile device
8 if (isMobileDevice === true || isSafari === true) {
9 url = 'https://peertube2.cpy.re/videos/local'
11 url = '/videos/recently-added'
14 await browser.get(url)
16 // Waiting the following element does not work on Safari...
17 if (isSafari) return browser.sleep(3000)
19 const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
20 return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
23 getVideosListName () {
24 return element.all(by.css('.videos .video-miniature .video-miniature-name'))
26 .then((texts: any) => texts.map((t: any) => t.trim()))
29 waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) {
30 // On mobile we display the first node, on desktop the second
31 const index = isMobileDevice ? 0 : 1
33 const elem = element.all(by.css('.video-info .video-info-name')).get(index)
35 if (isSafari) return browser.sleep(5000)
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 browser.sleep(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 browser.sleep(3000)
67 await videojsEl.click()
70 await browser.sleep(7000)
72 return videojsEl.click()
75 async clickOnVideo (videoName: string) {
76 const video = element.all(by.css('.videos .video-miniature .video-miniature-name'))
77 .filter(e => e.getText().then(t => t === videoName ))
80 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
83 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
86 async clickOnFirstVideo () {
87 const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
88 const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
90 // Don't know why but the expectation fails on Safari
91 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
93 const textToReturn = videoName.getText()
96 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
100 async goOnAssociatedEmbed () {
101 let url = await browser.getCurrentUrl()
102 url = url.replace('/watch/', '/embed/')
103 url = url.replace(':3333', ':9001')
105 return browser.get(url)
108 async goOnP2PMediaLoaderEmbed () {
109 return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50')
112 async clickOnUpdate () {
113 const dropdown = element(by.css('my-video-actions-dropdown .action-button'))
114 await dropdown.click()
116 const items: ElementFinder[] = await element.all(by.css('my-video-actions-dropdown .dropdown-menu .dropdown-item'))
118 for (const item of items) {
119 const href = await item.getAttribute('href')
121 if (href && href.includes('/update/')) {
128 async clickOnSave () {
129 return element(by.css('.action-button-save')).click()
132 async createPlaylist (name: string) {
133 await element(by.css('.new-playlist-button')).click()
135 await element(by.css('#displayName')).sendKeys(name)
137 return element(by.css('.new-playlist-block input[type=submit]')).click()
140 async saveToPlaylist (name: string) {
141 return element.all(by.css('my-video-add-to-playlist .playlist'))
142 .filter(p => p.getText().then(t => t === name))
146 waitUntilVideoName (name: string, maxTime: number) {
147 const elem = this.getVideoNameElement()
149 return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime)
152 private getVideoNameElement () {
153 // We have 2 video info name block, pick the first that is not empty
154 return element.all(by.css('.video-info-first-row .video-info-name'))
155 .filter(e => e.getText().then(t => !!t))