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