]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/videos.e2e-spec.ts
Migrate to webdriverio
[github/Chocobozzz/PeerTube.git] / client / e2e / src / videos.e2e-spec.ts
1 import { LoginPage } from './po/login.po'
2 import { MyAccountPage } from './po/my-account'
3 import { PlayerPage } from './po/player.po'
4 import { VideoUpdatePage } from './po/video-update.po'
5 import { VideoUploadPage } from './po/video-upload.po'
6 import { VideoWatchPage } from './po/video-watch.po'
7 import { browserSleep, go, isIOS, isMobileDevice, isSafari } from './utils'
8
9 function isUploadUnsupported () {
10 if (isMobileDevice() || isSafari()) {
11 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
12 return true
13 }
14
15 return false
16 }
17
18 describe('Videos workflow', () => {
19 let videoWatchPage: VideoWatchPage
20 let videoUploadPage: VideoUploadPage
21 let videoUpdatePage: VideoUpdatePage
22 let myAccountPage: MyAccountPage
23 let loginPage: LoginPage
24 let playerPage: PlayerPage
25
26 let videoName = Math.random() + ' video'
27 const video2Name = Math.random() + ' second video'
28 const playlistName = Math.random() + ' playlist'
29 let videoWatchUrl: string
30
31 before(async () => {
32 if (isIOS()) {
33 console.log('iOS detected')
34 } else if (isMobileDevice()) {
35 console.log('Android detected.')
36 } else if (isSafari()) {
37 console.log('Safari detected.')
38 }
39
40 if (isUploadUnsupported()) return
41
42 await browser.waitUntil(async () => {
43 await go('/')
44 await browserSleep(500)
45
46 return $('<my-app>').isDisplayed()
47 }, { timeout: 20 * 1000 })
48 })
49
50 beforeEach(async () => {
51 videoWatchPage = new VideoWatchPage()
52 videoUploadPage = new VideoUploadPage()
53 videoUpdatePage = new VideoUpdatePage()
54 myAccountPage = new MyAccountPage()
55 loginPage = new LoginPage()
56 playerPage = new PlayerPage()
57
58 if (!isMobileDevice()) {
59 await browser.maximizeWindow()
60 }
61 })
62
63 it('Should log in', async () => {
64 if (isMobileDevice() || isSafari()) {
65 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
66 return
67 }
68
69 return loginPage.loginAsRootUser()
70 })
71
72 it('Should upload a video', async () => {
73 if (isUploadUnsupported()) return
74
75 await videoUploadPage.navigateTo()
76
77 await videoUploadPage.uploadVideo()
78 return videoUploadPage.validSecondUploadStep(videoName)
79 })
80
81 it('Should list videos', async () => {
82 await videoWatchPage.goOnVideosList(isMobileDevice(), isSafari())
83
84 if (isUploadUnsupported()) return
85
86 const videoNames = await videoWatchPage.getVideosListName()
87 expect(videoNames).toContain(videoName)
88 })
89
90 it('Should go on video watch page', async () => {
91 let videoNameToExcept = videoName
92
93 if (isMobileDevice() || isSafari()) {
94 await go('https://peertube2.cpy.re/w/122d093a-1ede-43bd-bd34-59d2931ffc5e')
95 videoNameToExcept = 'E2E tests'
96 } else {
97 await videoWatchPage.clickOnVideo(videoName)
98 }
99
100 return videoWatchPage.waitWatchVideoName(videoNameToExcept, isMobileDevice(), isSafari())
101 })
102
103 it('Should play the video', async () => {
104 videoWatchUrl = await browser.getUrl()
105
106 await playerPage.playAndPauseVideo(true)
107 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
108 })
109
110 it('Should watch the associated embed video', async () => {
111 await videoWatchPage.goOnAssociatedEmbed()
112
113 await playerPage.playAndPauseVideo(false)
114 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
115 })
116
117 it('Should watch the p2p media loader embed video', async () => {
118 await videoWatchPage.goOnP2PMediaLoaderEmbed()
119
120 await playerPage.playAndPauseVideo(false)
121 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
122 })
123
124 it('Should update the video', async () => {
125 if (isUploadUnsupported()) return
126
127 await go(videoWatchUrl)
128
129 await videoWatchPage.clickOnUpdate()
130
131 videoName += ' updated'
132 await videoUpdatePage.updateName(videoName)
133
134 await videoUpdatePage.validUpdate()
135
136 const name = await videoWatchPage.getVideoName()
137 expect(name).toEqual(videoName)
138 })
139
140 it('Should add the video in my playlist', async () => {
141 if (isUploadUnsupported()) return
142
143 await videoWatchPage.clickOnSave()
144
145 await videoWatchPage.createPlaylist(playlistName)
146
147 await videoWatchPage.saveToPlaylist(playlistName)
148 await browser.pause(5000)
149
150 await videoUploadPage.navigateTo()
151
152 await videoUploadPage.uploadVideo()
153 await videoUploadPage.validSecondUploadStep(video2Name)
154
155 await videoWatchPage.clickOnSave()
156 await videoWatchPage.saveToPlaylist(playlistName)
157 })
158
159 it('Should have the playlist in my account', async () => {
160 if (isUploadUnsupported()) return
161
162 await myAccountPage.navigateToMyPlaylists()
163
164 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
165 expect(videosNumberText).toEqual('2 videos')
166
167 await myAccountPage.clickOnPlaylist(playlistName)
168
169 const count = await myAccountPage.countTotalPlaylistElements()
170 expect(count).toEqual(2)
171 })
172
173 it('Should watch the playlist', async () => {
174 if (isUploadUnsupported()) return
175
176 await myAccountPage.playPlaylist()
177
178 await videoWatchPage.waitUntilVideoName(video2Name, 30 * 1000)
179 })
180
181 it('Should watch the webtorrent playlist in the embed', async () => {
182 if (isUploadUnsupported()) return
183
184 const accessToken = await browser.execute(`return window.localStorage.getItem('access_token');`)
185 const refreshToken = await browser.execute(`return window.localStorage.getItem('refresh_token');`)
186
187 await myAccountPage.goOnAssociatedPlaylistEmbed()
188
189 await playerPage.waitUntilPlayerWrapper()
190
191 console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)
192
193 await browser.execute(`window.localStorage.setItem('access_token', '${accessToken}');`)
194 await browser.execute(`window.localStorage.setItem('refresh_token', '${refreshToken}');`)
195 await browser.execute(`window.localStorage.setItem('token_type', 'Bearer');`)
196
197 await browser.refresh()
198
199 await playerPage.playVideo()
200
201 await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
202 })
203
204 it('Should watch the HLS playlist in the embed', async () => {
205 await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
206
207 await playerPage.playVideo()
208
209 await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
210 })
211
212 it('Should delete the video 2', async () => {
213 if (isUploadUnsupported()) return
214
215 // Go to the dev website
216 await go(videoWatchUrl)
217
218 await myAccountPage.navigateToMyVideos()
219
220 await myAccountPage.removeVideo(video2Name)
221 await myAccountPage.validRemove()
222
223 await browser.waitUntil(async () => {
224 const count = await myAccountPage.countVideos([ videoName, video2Name ])
225
226 return count === 1
227 })
228 })
229
230 it('Should delete the first video', async () => {
231 if (isUploadUnsupported()) return
232
233 await myAccountPage.removeVideo(videoName)
234 await myAccountPage.validRemove()
235 })
236 })