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'
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.')
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
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
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()
41 // iOS does not seem to work with protractor
42 // https://github.com/angular/protractor/issues/2840
43 browser.waitForAngularEnabled(false)
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.')
52 if (!await isMobileDevice()) {
53 await browser.driver.manage().window().maximize()
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.')
63 return loginPage.loginAsRootUser()
66 it('Should upload a video', async () => {
67 if (await skipIfUploadNotSupported()) return
69 await videoUploadPage.navigateTo()
71 await videoUploadPage.uploadVideo()
72 return videoUploadPage.validSecondUploadStep(videoName)
75 it('Should list videos', async () => {
76 await videoWatchPage.goOnVideosList(await isMobileDevice(), await isSafari())
78 if (await skipIfUploadNotSupported()) return
80 const videoNames = videoWatchPage.getVideosListName()
81 expect(videoNames).toContain(videoName)
84 it('Should go on video watch page', async () => {
85 let videoNameToExcept = videoName
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'
91 await videoWatchPage.clickOnVideo(videoName)
94 return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
97 it('Should play the video', async () => {
98 videoWatchUrl = await browser.getCurrentUrl()
100 await playerPage.playAndPauseVideo(true)
101 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
104 it('Should watch the associated embed video', async () => {
105 const oldValue = await browser.waitForAngularEnabled()
106 await browser.waitForAngularEnabled(false)
108 await videoWatchPage.goOnAssociatedEmbed()
110 await playerPage.playAndPauseVideo(false)
111 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
113 await browser.waitForAngularEnabled(oldValue)
116 it('Should watch the p2p media loader embed video', async () => {
117 const oldValue = await browser.waitForAngularEnabled()
118 await browser.waitForAngularEnabled(false)
120 await videoWatchPage.goOnP2PMediaLoaderEmbed()
122 await playerPage.playAndPauseVideo(false)
123 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
125 await browser.waitForAngularEnabled(oldValue)
128 it('Should update the video', async () => {
129 if (await skipIfUploadNotSupported()) return
131 await browser.get(videoWatchUrl)
133 await videoWatchPage.clickOnUpdate()
135 videoName += ' updated'
136 await videoUpdatePage.updateName(videoName)
138 await videoUpdatePage.validUpdate()
140 const name = await videoWatchPage.getVideoName()
141 expect(name).toEqual(videoName)
144 it('Should add the video in my playlist', async () => {
145 if (await skipIfUploadNotSupported()) return
147 await videoWatchPage.clickOnSave()
149 await videoWatchPage.createPlaylist(playlistName)
151 await videoWatchPage.saveToPlaylist(playlistName)
152 await browser.sleep(5000)
154 await videoUploadPage.navigateTo()
156 await videoUploadPage.uploadVideo()
157 await videoUploadPage.validSecondUploadStep(video2Name)
159 await videoWatchPage.clickOnSave()
160 await videoWatchPage.saveToPlaylist(playlistName)
163 it('Should have the playlist in my account', async () => {
164 if (await skipIfUploadNotSupported()) return
166 await myAccountPage.navigateToMyPlaylists()
168 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
169 expect(videosNumberText).toEqual('2 videos')
171 await myAccountPage.clickOnPlaylist(playlistName)
173 const count = await myAccountPage.countTotalPlaylistElements()
174 expect(count).toEqual(2)
177 it('Should watch the playlist', async () => {
178 if (await skipIfUploadNotSupported()) return
180 await myAccountPage.playPlaylist()
182 const oldValue = await browser.waitForAngularEnabled()
183 await browser.waitForAngularEnabled(false)
185 await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
187 await browser.waitForAngularEnabled(oldValue)
190 it('Should watch the webtorrent playlist in the embed', async () => {
191 if (await skipIfUploadNotSupported()) return
193 const accessToken = await browser.executeScript(`return window.localStorage.getItem('access_token');`)
194 const refreshToken = await browser.executeScript(`return window.localStorage.getItem('refresh_token');`)
196 const oldValue = await browser.waitForAngularEnabled()
197 await browser.waitForAngularEnabled(false)
199 await myAccountPage.goOnAssociatedPlaylistEmbed()
201 await playerPage.waitUntilPlayerWrapper()
203 console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)
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');`)
209 await browser.refresh()
211 await playerPage.playVideo()
213 await playerPage.waitUntilPlaylistInfo('2/2')
215 await browser.waitForAngularEnabled(oldValue)
218 it('Should watch the HLS playlist in the embed', async () => {
219 const oldValue = await browser.waitForAngularEnabled()
220 await browser.waitForAngularEnabled(false)
222 await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
224 await playerPage.playVideo()
226 await playerPage.waitUntilPlaylistInfo('2/2')
228 await browser.waitForAngularEnabled(oldValue)
231 it('Should delete the video 2', async () => {
232 if (await skipIfUploadNotSupported()) return
234 // Go to the dev website
235 await browser.get(videoWatchUrl)
237 await myAccountPage.navigateToMyVideos()
239 await myAccountPage.removeVideo(video2Name)
240 await myAccountPage.validRemove()
242 const count = await myAccountPage.countVideos([ videoName, video2Name ])
243 expect(count).toEqual(1)
246 it('Should delete the first video', async () => {
247 if (await skipIfUploadNotSupported()) return
249 await myAccountPage.removeVideo(videoName)
250 await myAccountPage.validRemove()