]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/e2e/src/po/video-watch.po.ts
Add playlist embed E2E test
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
CommitLineData
e69cb173 1import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
7f90579c 2import { browserSleep, isMobileDevice } from '../utils'
5f92c4dc
C
3
4export class VideoWatchPage {
1fad099d 5 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
0b33c520
C
6 let url: string
7
1fad099d
C
8 // We did not upload a file on a mobile device
9 if (isMobileDevice === true || isSafari === true) {
0b33c520
C
10 url = 'https://peertube2.cpy.re/videos/local'
11 } else {
12 url = '/videos/recently-added'
13 }
5f92c4dc 14
ee68bbc4 15 await browser.get(url, 20000)
d1bd87e0
C
16
17 // Waiting the following element does not work on Safari...
ee68bbc4 18 if (isSafari) return browserSleep(3000)
d1bd87e0
C
19
20 const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
21 return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
5f92c4dc
C
22 }
23
24 getVideosListName () {
d1bd87e0 25 return element.all(by.css('.videos .video-miniature .video-miniature-name'))
0b33c520 26 .getText()
c199c427 27 .then((texts: any) => texts.map((t: any) => t.trim()))
5f92c4dc
C
28 }
29
6247b205 30 waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) {
ee68bbc4
C
31 if (isSafari) return browserSleep(5000)
32
6247b205
C
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)
5f92c4dc
C
37 return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName))
38 }
39
e69cb173
C
40 getVideoName () {
41 return this.getVideoNameElement().getText()
42 }
43
7f90579c
C
44 async goOnAssociatedEmbed () {
45 let url = await browser.getCurrentUrl()
46 url = url.replace('/watch/', '/embed/')
47 url = url.replace(':3333', ':9001')
ee68bbc4 48
7f90579c
C
49 return browser.get(url)
50 }
91d95589 51
7f90579c
C
52 async goOnP2PMediaLoaderEmbed () {
53 return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50')
54 }
cd4d7a2c 55
7f90579c
C
56 async goOnP2PMediaLoaderPlaylistEmbed () {
57 return browser.get('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
5f92c4dc
C
58 }
59
cd4d7a2c 60 async clickOnVideo (videoName: string) {
3cf198e4
C
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
0b33c520
C
65 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
66 await video.click()
67
68 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
69 }
70
71 async clickOnFirstVideo () {
3a1a00a4
C
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()
1fad099d
C
74
75 // Don't know why but the expectation fails on Safari
0b33c520 76 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
5f92c4dc 77
3a1a00a4 78 const textToReturn = videoName.getText()
5f92c4dc
C
79 await video.click()
80
81 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
0b33c520 82 return textToReturn
5f92c4dc
C
83 }
84
e69cb173
C
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('my-video-actions-dropdown .dropdown-menu .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
bbe078ba
C
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()
e69cb173
C
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
3cf198e4 127 return element.all(by.css('.video-info-first-row .video-info-name'))
e69cb173
C
128 .filter(e => e.getText().then(t => !!t))
129 .first()
130 }
5f92c4dc 131}