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