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