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