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'
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.')
20 describe('Videos workflow', () => {
21 let videoWatchPage: VideoWatchPage
22 let videoUploadPage: VideoUploadPage
23 let videoUpdatePage: VideoUpdatePage
24 let myAccountPage: MyAccountPage
25 let loginPage: LoginPage
27 let playerPage: PlayerPage
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
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()
44 // iOS does not seem to work with protractor
45 // https://github.com/angular/protractor/issues/2840
46 browser.waitForAngularEnabled(false)
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.')
55 if (!await isMobileDevice()) {
56 await browser.driver.manage().window().maximize()
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.')
66 return loginPage.loginAsRootUser()
69 it('Should close the welcome modal', async () => {
70 if (await skipIfUploadNotSupported()) return
72 await appPage.closeWelcomeModal()
75 it('Should upload a video', async () => {
76 if (await skipIfUploadNotSupported()) return
78 await videoUploadPage.navigateTo()
80 await videoUploadPage.uploadVideo()
81 return videoUploadPage.validSecondUploadStep(videoName)
84 it('Should list videos', async () => {
85 await videoWatchPage.goOnVideosList(await isMobileDevice(), await isSafari())
87 if (await skipIfUploadNotSupported()) return
89 const videoNames = videoWatchPage.getVideosListName()
90 expect(videoNames).toContain(videoName)
93 it('Should go on video watch page', async () => {
94 let videoNameToExcept = videoName
96 if (await isMobileDevice() || await isSafari()) {
97 await browser.get('https://peertube2.cpy.re/videos/watch/122d093a-1ede-43bd-bd34-59d2931ffc5e')
98 videoNameToExcept = 'E2E tests'
100 await videoWatchPage.clickOnVideo(videoName)
103 return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
106 it('Should play the video', async () => {
107 videoWatchUrl = await browser.getCurrentUrl()
109 await playerPage.playAndPauseVideo(true)
110 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
113 it('Should watch the associated embed video', async () => {
114 const oldValue = await browser.waitForAngularEnabled()
115 await browser.waitForAngularEnabled(false)
117 await videoWatchPage.goOnAssociatedEmbed()
119 await playerPage.playAndPauseVideo(false)
120 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
122 await browser.waitForAngularEnabled(oldValue)
125 it('Should watch the p2p media loader embed video', async () => {
126 const oldValue = await browser.waitForAngularEnabled()
127 await browser.waitForAngularEnabled(false)
129 await videoWatchPage.goOnP2PMediaLoaderEmbed()
131 await playerPage.playAndPauseVideo(false)
132 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
134 await browser.waitForAngularEnabled(oldValue)
137 it('Should update the video', async () => {
138 if (await skipIfUploadNotSupported()) return
140 await browser.get(videoWatchUrl)
142 await videoWatchPage.clickOnUpdate()
144 videoName += ' updated'
145 await videoUpdatePage.updateName(videoName)
147 await videoUpdatePage.validUpdate()
149 const name = await videoWatchPage.getVideoName()
150 expect(name).toEqual(videoName)
153 it('Should add the video in my playlist', async () => {
154 if (await skipIfUploadNotSupported()) return
156 await videoWatchPage.clickOnSave()
158 await videoWatchPage.createPlaylist(playlistName)
160 await videoWatchPage.saveToPlaylist(playlistName)
161 await browser.sleep(5000)
163 await videoUploadPage.navigateTo()
165 await videoUploadPage.uploadVideo()
166 await videoUploadPage.validSecondUploadStep(video2Name)
168 await videoWatchPage.clickOnSave()
169 await videoWatchPage.saveToPlaylist(playlistName)
172 it('Should have the playlist in my account', async () => {
173 if (await skipIfUploadNotSupported()) return
175 await myAccountPage.navigateToMyPlaylists()
177 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
178 expect(videosNumberText).toEqual('2 videos')
180 await myAccountPage.clickOnPlaylist(playlistName)
182 const count = await myAccountPage.countTotalPlaylistElements()
183 expect(count).toEqual(2)
186 it('Should watch the playlist', async () => {
187 if (await skipIfUploadNotSupported()) return
189 await myAccountPage.playPlaylist()
191 const oldValue = await browser.waitForAngularEnabled()
192 await browser.waitForAngularEnabled(false)
194 await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
196 await browser.waitForAngularEnabled(oldValue)
199 it('Should watch the webtorrent playlist in the embed', async () => {
200 if (await skipIfUploadNotSupported()) return
202 const accessToken = await browser.executeScript(`return window.localStorage.getItem('access_token');`)
203 const refreshToken = await browser.executeScript(`return window.localStorage.getItem('refresh_token');`)
205 const oldValue = await browser.waitForAngularEnabled()
206 await browser.waitForAngularEnabled(false)
208 await myAccountPage.goOnAssociatedPlaylistEmbed()
210 await playerPage.waitUntilPlayerWrapper()
212 console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)
214 await browser.executeScript(`window.localStorage.setItem('access_token', '${accessToken}');`)
215 await browser.executeScript(`window.localStorage.setItem('refresh_token', '${refreshToken}');`)
216 await browser.executeScript(`window.localStorage.setItem('token_type', 'Bearer');`)
218 await browser.refresh()
220 await playerPage.playVideo()
222 await playerPage.waitUntilPlaylistInfo('2/2')
224 await browser.waitForAngularEnabled(oldValue)
227 it('Should watch the HLS playlist in the embed', async () => {
228 const oldValue = await browser.waitForAngularEnabled()
229 await browser.waitForAngularEnabled(false)
231 await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
233 await playerPage.playVideo()
235 await playerPage.waitUntilPlaylistInfo('2/2')
237 await browser.waitForAngularEnabled(oldValue)
240 it('Should delete the video 2', async () => {
241 if (await skipIfUploadNotSupported()) return
243 // Go to the dev website
244 await browser.get(videoWatchUrl)
246 await myAccountPage.navigateToMyVideos()
248 await myAccountPage.removeVideo(video2Name)
249 await myAccountPage.validRemove()
251 const count = await myAccountPage.countVideos([ videoName, video2Name ])
252 expect(count).toEqual(1)
255 it('Should delete the first video', async () => {
256 if (await skipIfUploadNotSupported()) return
258 await myAccountPage.removeVideo(videoName)
259 await myAccountPage.validRemove()