]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/video-watch.po.ts
Fix E2E tests
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
1 import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
2
3 export class VideoWatchPage {
4 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
5 let url: string
6
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'
10 } else {
11 url = '/videos/recently-added'
12 }
13
14 await browser.get(url)
15
16 // Waiting the following element does not work on Safari...
17 if (isSafari === true) return browser.sleep(3000)
18
19 const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
20 return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
21 }
22
23 getVideosListName () {
24 return element.all(by.css('.videos .video-miniature .video-miniature-name'))
25 .getText()
26 .then((texts: any) => texts.map((t: any) => t.trim()))
27 }
28
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
32
33 const elem = element.all(by.css('.video-info .video-info-name')).get(index)
34
35 if (isSafari) return browser.sleep(5000)
36
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, 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()
56 }
57
58 await browser.sleep(1000)
59 await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
60
61 const videojsEl = element(by.css('div.video-js'))
62 await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
63
64 // On Android, we need to click twice on "play" (BrowserStack particularity)
65 if (isMobileDevice) {
66 await browser.sleep(3000)
67 await videojsEl.click()
68 }
69
70 await browser.sleep(7000)
71
72 return videojsEl.click()
73 }
74
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 ))
78 .first()
79
80 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
81 await video.click()
82
83 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
84 }
85
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()
89
90 // Don't know why but the expectation fails on Safari
91 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
92
93 const textToReturn = videoName.getText()
94 await video.click()
95
96 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
97 return textToReturn
98 }
99
100 async goOnAssociatedEmbed () {
101 let url = await browser.getCurrentUrl()
102 url = url.replace('/watch/', '/embed/')
103 url = url.replace(':3333', ':9001')
104
105 return browser.get(url)
106 }
107
108 async goOnP2PMediaLoaderEmbed () {
109 return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50?mode=p2p-media-loader')
110 }
111
112 async clickOnUpdate () {
113 const dropdown = element(by.css('my-video-actions-dropdown .action-button'))
114 await dropdown.click()
115
116 const items: ElementFinder[] = await element.all(by.css('my-video-actions-dropdown .dropdown-menu .dropdown-item'))
117
118 for (const item of items) {
119 const href = await item.getAttribute('href')
120
121 if (href && href.includes('/update/')) {
122 await item.click()
123 return
124 }
125 }
126 }
127
128 async clickOnSave () {
129 return element(by.css('.action-button-save')).click()
130 }
131
132 async createPlaylist (name: string) {
133 await element(by.css('.new-playlist-button')).click()
134
135 await element(by.css('#displayName')).sendKeys(name)
136
137 return element(by.css('.new-playlist-block input[type=submit]')).click()
138 }
139
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))
143 .click()
144 }
145
146 waitUntilVideoName (name: string, maxTime: number) {
147 const elem = this.getVideoNameElement()
148
149 return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime)
150 }
151
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))
156 .first()
157 }
158 }