]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/video-watch.po.ts
6d91d241e19d391f4d7a913e710924abbc9e8493
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
1 import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
2 import { browserSleep, isMobileDevice } from '../utils'
3
4 export class VideoWatchPage {
5 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
6 let url: string
7
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'
11 } else {
12 url = '/videos/recently-added'
13 }
14
15 await browser.get(url, 20000)
16
17 // Waiting the following element does not work on Safari...
18 if (isSafari) return browserSleep(3000)
19
20 const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
21 return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
22 }
23
24 getVideosListName () {
25 return element.all(by.css('.videos .video-miniature .video-miniature-name'))
26 .getText()
27 .then((texts: any) => texts.map((t: any) => t.trim()))
28 }
29
30 waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) {
31 if (isSafari) return browserSleep(5000)
32
33 // On mobile we display the first node, on desktop the second
34 const index = isMobileDevice ? 0 : 1
35
36 const elem = element.all(by.css('.video-info .video-info-name')).get(index)
37 return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName))
38 }
39
40 getVideoName () {
41 return this.getVideoNameElement().getText()
42 }
43
44 async goOnAssociatedEmbed () {
45 let url = await browser.getCurrentUrl()
46 url = url.replace('/w/', '/embed/')
47 url = url.replace(':3333', ':9001')
48
49 return browser.get(url)
50 }
51
52 async goOnP2PMediaLoaderEmbed () {
53 return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50')
54 }
55
56 async goOnP2PMediaLoaderPlaylistEmbed () {
57 return browser.get('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
58 }
59
60 async clickOnVideo (videoName: string) {
61 const video = element.all(by.css('.videos .video-miniature .video-miniature-name'))
62 .filter(e => e.getText().then(t => t === videoName ))
63 .first()
64
65 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
66 await video.click()
67
68 await browser.wait(browser.ExpectedConditions.urlContains('/w/'))
69 }
70
71 async clickOnFirstVideo () {
72 const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
73 const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
74
75 // Don't know why but the expectation fails on Safari
76 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
77
78 const textToReturn = videoName.getText()
79 await video.click()
80
81 await browser.wait(browser.ExpectedConditions.urlContains('/w/'))
82 return textToReturn
83 }
84
85 async clickOnUpdate () {
86 const dropdown = element(by.css('my-video-actions-dropdown .action-button'))
87 await dropdown.click()
88
89 const items: ElementFinder[] = await element.all(by.css('.dropdown-menu.show .dropdown-item'))
90
91 for (const item of items) {
92 const href = await item.getAttribute('href')
93
94 if (href && href.includes('/update/')) {
95 await item.click()
96 return
97 }
98 }
99 }
100
101 async clickOnSave () {
102 return element(by.css('.action-button-save')).click()
103 }
104
105 async createPlaylist (name: string) {
106 await element(by.css('.new-playlist-button')).click()
107
108 await element(by.css('#displayName')).sendKeys(name)
109
110 return element(by.css('.new-playlist-block input[type=submit]')).click()
111 }
112
113 async saveToPlaylist (name: string) {
114 return element.all(by.css('my-video-add-to-playlist .playlist'))
115 .filter(p => p.getText().then(t => t === name))
116 .click()
117 }
118
119 waitUntilVideoName (name: string, maxTime: number) {
120 const elem = this.getVideoNameElement()
121
122 return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime)
123 }
124
125 private getVideoNameElement () {
126 // We have 2 video info name block, pick the first that is not empty
127 return element.all(by.css('.video-info-first-row .video-info-name'))
128 .filter(e => e.getText().then(t => !!t))
129 .first()
130 }
131 }