]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/e2e/src/po/video-watch.po.ts
Add more 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
C
75 async clickOnVideo (videoName: string) {
76 const video = element(by.css('.videos .video-miniature .video-thumbnail[title="' + videoName + '"]'))
0b33c520
C
77 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
78 await video.click()
79
80 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
81 }
82
83 async clickOnFirstVideo () {
1fad099d
C
84 const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
85 const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
86
87 // Don't know why but the expectation fails on Safari
0b33c520 88 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
5f92c4dc 89
1fad099d 90 const textToReturn = videoName.getText()
5f92c4dc
C
91 await video.click()
92
93 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
0b33c520 94 return textToReturn
5f92c4dc
C
95 }
96
d1bd87e0
C
97 async goOnAssociatedEmbed () {
98 let url = await browser.getCurrentUrl()
99 url = url.replace('/watch/', '/embed/')
100 url = url.replace(':3333', ':9001')
101
102 return browser.get(url)
5f92c4dc 103 }
84c7cde6
C
104
105 async goOnP2PMediaLoaderEmbed () {
ac043122 106 return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50?mode=p2p-media-loader')
84c7cde6 107 }
e69cb173
C
108
109 async clickOnUpdate () {
110 const dropdown = element(by.css('my-video-actions-dropdown .action-button'))
111 await dropdown.click()
112
113 const items: ElementFinder[] = await element.all(by.css('my-video-actions-dropdown .dropdown-menu .dropdown-item'))
114
115 for (const item of items) {
116 const href = await item.getAttribute('href')
117
118 if (href && href.includes('/update/')) {
119 await item.click()
120 return
121 }
122 }
123 }
124
125 async clickOnSave () {
126 return element(by.css('.action-button-save')).click()
127 }
128
129 async saveToWatchLater () {
130 return element.all(by.css('my-video-add-to-playlist .playlist')).first().click()
131 }
132
133 waitUntilVideoName (name: string, maxTime: number) {
134 const elem = this.getVideoNameElement()
135
136 return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime)
137 }
138
139 private getVideoNameElement () {
140 // We have 2 video info name block, pick the first that is not empty
141 return element.all(by.css('.video-bottom .video-info-name'))
142 .filter(e => e.getText().then(t => !!t))
143 .first()
144 }
5f92c4dc 145}