]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/video-watch.po.ts
Improve e2e workflow and add doc
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
1 import { FIXTURE_URLS } from '../urls'
2 import { browserSleep, go } 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 go(url)
16
17 // Waiting the following element does not work on Safari...
18 if (isSafari) return browserSleep(3000)
19
20 await $('.videos .video-miniature .video-miniature-name').waitForDisplayed()
21 }
22
23 async getVideosListName () {
24 const elems = await $$('.videos .video-miniature .video-miniature-name')
25 const texts = await Promise.all(elems.map(e => e.getText()))
26
27 return texts.map(t => 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 return browser.waitUntil(async () => {
37 return (await $$('.video-info .video-info-name')[index].getText()).includes(videoName)
38 })
39 }
40
41 getVideoName () {
42 return this.getVideoNameElement().then(e => e.getText())
43 }
44
45 async goOnAssociatedEmbed () {
46 let url = await browser.getUrl()
47 url = url.replace('/w/', '/videos/embed/')
48 url = url.replace(':3333', ':9001')
49
50 return go(url)
51 }
52
53 goOnP2PMediaLoaderEmbed () {
54 return go(FIXTURE_URLS.HLS_EMBED)
55 }
56
57 goOnP2PMediaLoaderPlaylistEmbed () {
58 return go(FIXTURE_URLS.HLS_PLAYLIST_EMBED)
59 }
60
61 async clickOnVideo (videoName: string) {
62 const video = async () => {
63 const videos = await $$('.videos .video-miniature .video-miniature-name').filter(async e => {
64 const t = await e.getText()
65
66 return t === videoName
67 })
68
69 return videos[0]
70 }
71
72 await browser.waitUntil(async () => {
73 const elem = await video()
74
75 return elem?.isClickable()
76 });
77
78 (await video()).click()
79
80 await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
81 }
82
83 async clickOnFirstVideo () {
84 const video = () => $('.videos .video-miniature .video-thumbnail')
85 const videoName = () => $('.videos .video-miniature .video-miniature-name')
86
87 await video().waitForClickable()
88
89 const textToReturn = await videoName().getText()
90 await video().click()
91
92 await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
93
94 return textToReturn
95 }
96
97 async clickOnUpdate () {
98 const dropdown = $('my-video-actions-dropdown .action-button')
99 await dropdown.click()
100
101 await $('.dropdown-menu.show .dropdown-item').waitForDisplayed()
102 const items = await $$('.dropdown-menu.show .dropdown-item')
103
104 for (const item of items) {
105 const href = await item.getAttribute('href')
106
107 if (href?.includes('/update/')) {
108 await item.click()
109 return
110 }
111 }
112 }
113
114 clickOnSave () {
115 return $('.action-button-save').click()
116 }
117
118 async createPlaylist (name: string) {
119 const newPlaylistButton = () => $('.new-playlist-button')
120
121 await newPlaylistButton().waitForClickable()
122 await newPlaylistButton().click()
123
124 const displayName = () => $('#displayName')
125
126 await displayName().waitForDisplayed()
127 await displayName().setValue(name)
128
129 return $('.new-playlist-block input[type=submit]').click()
130 }
131
132 async saveToPlaylist (name: string) {
133 const playlist = () => $('my-video-add-to-playlist').$(`.playlist=${name}`)
134
135 await playlist().waitForDisplayed()
136
137 return playlist().click()
138 }
139
140 waitUntilVideoName (name: string, maxTime: number) {
141 return browser.waitUntil(async () => {
142 return (await this.getVideoName()) === name
143 }, { timeout: maxTime })
144 }
145
146 private async getVideoNameElement () {
147 // We have 2 video info name block, pick the first that is not empty
148 const elem = async () => {
149 const elems = await $$('.video-info-first-row .video-info-name').filter(e => e.isDisplayed())
150
151 return elems[0]
152 }
153
154 await browser.waitUntil(async () => {
155 const e = await elem()
156
157 return e?.isDisplayed()
158 })
159
160 return elem()
161 }
162 }