]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/video-watch.po.ts
Cleanup E2E tests
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
1 import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
2 import { browserSleep, isIOS, 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 getWatchVideoPlayerCurrentTime () {
41 return element(by.css('.video-js .vjs-current-time-display'))
42 .getText()
43 .then((t: string) => t.split(':')[1])
44 .then(seconds => parseInt(seconds, 10))
45 }
46
47 getVideoName () {
48 return this.getVideoNameElement().getText()
49 }
50
51 async playAndPauseVideo (isAutoplay: boolean) {
52 // Autoplay is disabled on iOS
53 if (isAutoplay === false || await isIOS()) {
54 const playButton = element(by.css('.vjs-big-play-button'))
55 await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
56 await playButton.click()
57 }
58
59 await browserSleep(2000)
60 await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
61
62 const videojsEl = element(by.css('div.video-js'))
63 await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
64
65 // On Android, we need to click twice on "play" (BrowserStack particularity)
66 if (await isMobileDevice()) {
67 await browserSleep(5000)
68
69 await videojsEl.click()
70 }
71
72 browser.ignoreSynchronization = false
73 await browserSleep(7000)
74 browser.ignoreSynchronization = true
75
76 await videojsEl.click()
77 }
78
79 async clickOnVideo (videoName: string) {
80 const video = element.all(by.css('.videos .video-miniature .video-miniature-name'))
81 .filter(e => e.getText().then(t => t === videoName ))
82 .first()
83
84 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
85 await video.click()
86
87 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
88 }
89
90 async clickOnFirstVideo () {
91 const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
92 const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
93
94 // Don't know why but the expectation fails on Safari
95 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
96
97 const textToReturn = videoName.getText()
98 await video.click()
99
100 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
101 return textToReturn
102 }
103
104 async goOnAssociatedEmbed () {
105 let url = await browser.getCurrentUrl()
106 url = url.replace('/watch/', '/embed/')
107 url = url.replace(':3333', ':9001')
108
109 return browser.get(url)
110 }
111
112 async goOnP2PMediaLoaderEmbed () {
113 return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50')
114 }
115
116 async clickOnUpdate () {
117 const dropdown = element(by.css('my-video-actions-dropdown .action-button'))
118 await dropdown.click()
119
120 const items: ElementFinder[] = await element.all(by.css('my-video-actions-dropdown .dropdown-menu .dropdown-item'))
121
122 for (const item of items) {
123 const href = await item.getAttribute('href')
124
125 if (href && href.includes('/update/')) {
126 await item.click()
127 return
128 }
129 }
130 }
131
132 async clickOnSave () {
133 return element(by.css('.action-button-save')).click()
134 }
135
136 async createPlaylist (name: string) {
137 await element(by.css('.new-playlist-button')).click()
138
139 await element(by.css('#displayName')).sendKeys(name)
140
141 return element(by.css('.new-playlist-block input[type=submit]')).click()
142 }
143
144 async saveToPlaylist (name: string) {
145 return element.all(by.css('my-video-add-to-playlist .playlist'))
146 .filter(p => p.getText().then(t => t === name))
147 .click()
148 }
149
150 waitUntilVideoName (name: string, maxTime: number) {
151 const elem = this.getVideoNameElement()
152
153 return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime)
154 }
155
156 private getVideoNameElement () {
157 // We have 2 video info name block, pick the first that is not empty
158 return element.all(by.css('.video-info-first-row .video-info-name'))
159 .filter(e => e.getText().then(t => !!t))
160 .first()
161 }
162 }