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