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