]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/e2e/src/po/video-watch.po.ts
Fix E2E tests
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
CommitLineData
e69cb173 1import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
5f92c4dc
C
2
3export class VideoWatchPage {
1fad099d 4 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
0b33c520
C
5 let url: string
6
1fad099d
C
7 // We did not upload a file on a mobile device
8 if (isMobileDevice === true || isSafari === true) {
0b33c520
C
9 url = 'https://peertube2.cpy.re/videos/local'
10 } else {
11 url = '/videos/recently-added'
12 }
5f92c4dc
C
13
14 await browser.get(url)
d1bd87e0
C
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))
5f92c4dc
C
21 }
22
23 getVideosListName () {
d1bd87e0 24 return element.all(by.css('.videos .video-miniature .video-miniature-name'))
0b33c520 25 .getText()
c199c427 26 .then((texts: any) => texts.map((t: any) => t.trim()))
5f92c4dc
C
27 }
28
6247b205
C
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)
1fad099d
C
34
35 if (isSafari) return browser.sleep(5000)
36
5f92c4dc
C
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
e69cb173
C
47 getVideoName () {
48 return this.getVideoNameElement().getText()
49 }
50
84c7cde6 51 async playAndPauseVideo (isAutoplay: boolean, isMobileDevice: boolean) {
d1bd87e0
C
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
d1bd87e0 58 await browser.sleep(1000)
cd4d7a2c
C
59 await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
60
1fad099d
C
61 const videojsEl = element(by.css('div.video-js'))
62 await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
5f92c4dc 63
91d95589
C
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
1fad099d 70 await browser.sleep(7000)
cd4d7a2c 71
1fad099d 72 return videojsEl.click()
5f92c4dc
C
73 }
74
cd4d7a2c 75 async clickOnVideo (videoName: string) {
3cf198e4
C
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
0b33c520
C
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 () {
1fad099d
C
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
0b33c520 91 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
5f92c4dc 92
1fad099d 93 const textToReturn = videoName.getText()
5f92c4dc
C
94 await video.click()
95
96 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
0b33c520 97 return textToReturn
5f92c4dc
C
98 }
99
d1bd87e0
C
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)
5f92c4dc 106 }
84c7cde6
C
107
108 async goOnP2PMediaLoaderEmbed () {
ac043122 109 return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50?mode=p2p-media-loader')
84c7cde6 110 }
e69cb173
C
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
bbe078ba
C
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()
e69cb173
C
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
3cf198e4 154 return element.all(by.css('.video-info-first-row .video-info-name'))
e69cb173
C
155 .filter(e => e.getText().then(t => !!t))
156 .first()
157 }
5f92c4dc 158}