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.ignoreSynchronization = true
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()) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
97 else await videoWatchPage.clickOnVideo(videoName)
99 return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
102 it('Should play the video', async () => {
103 videoWatchUrl = await browser.getCurrentUrl()
105 await playerPage.playAndPauseVideo(true)
106 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
109 it('Should watch the associated embed video', async () => {
110 await browser.waitForAngularEnabled(false)
112 await videoWatchPage.goOnAssociatedEmbed()
114 await playerPage.playAndPauseVideo(false)
115 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
117 await browser.waitForAngularEnabled(true)
120 it('Should watch the p2p media loader embed video', async () => {
121 await browser.waitForAngularEnabled(false)
123 await videoWatchPage.goOnP2PMediaLoaderEmbed()
125 await playerPage.playAndPauseVideo(false)
126 expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
128 await browser.waitForAngularEnabled(true)
131 it('Should update the video', async () => {
132 if (await skipIfUploadNotSupported()) return
134 await browser.get(videoWatchUrl)
136 await videoWatchPage.clickOnUpdate()
138 videoName += ' updated'
139 await videoUpdatePage.updateName(videoName)
141 await videoUpdatePage.validUpdate()
143 const name = await videoWatchPage.getVideoName()
144 expect(name).toEqual(videoName)
147 it('Should add the video in my playlist', async () => {
148 if (await skipIfUploadNotSupported()) return
150 await videoWatchPage.clickOnSave()
152 await videoWatchPage.createPlaylist(playlistName)
154 await videoWatchPage.saveToPlaylist(playlistName)
156 await videoUploadPage.navigateTo()
158 await videoUploadPage.uploadVideo()
159 await videoUploadPage.validSecondUploadStep(video2Name)
161 await videoWatchPage.clickOnSave()
162 await videoWatchPage.saveToPlaylist(playlistName)
165 it('Should have the playlist in my account', async () => {
166 if (await skipIfUploadNotSupported()) return
168 await myAccountPage.navigateToMyPlaylists()
170 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
171 expect(videosNumberText).toEqual('2 videos')
173 await myAccountPage.clickOnPlaylist(playlistName)
175 const count = await myAccountPage.countTotalPlaylistElements()
176 expect(count).toEqual(2)
179 it('Should watch the playlist', async () => {
180 if (await skipIfUploadNotSupported()) return
182 await myAccountPage.playPlaylist()
184 await browser.waitForAngularEnabled(false)
186 await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
188 await browser.waitForAngularEnabled(true)
191 it('Should watch the webtorrent playlist in the embed', async () => {
192 if (await skipIfUploadNotSupported()) return
194 const accessToken = await browser.executeScript(`return window.localStorage.getItem('access_token');`)
195 const refreshToken = await browser.executeScript(`return window.localStorage.getItem('refresh_token');`)
197 await browser.waitForAngularEnabled(false)
199 await myAccountPage.goOnAssociatedPlaylistEmbed()
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');`)
205 await browser.refresh()
207 await playerPage.playVideo()
209 await playerPage.waitUntilPlaylistInfo('2/2')
211 await browser.waitForAngularEnabled(true)
214 it('Should watch the HLS playlist in the embed', async () => {
215 await browser.waitForAngularEnabled(false)
217 await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
219 await playerPage.playVideo()
221 await playerPage.waitUntilPlaylistInfo('2/2')
223 await browser.waitForAngularEnabled(true)
226 it('Should delete the video 2', async () => {
227 if (await skipIfUploadNotSupported()) return
229 // Go to the dev website
230 await browser.get(videoWatchUrl)
232 await myAccountPage.navigateToMyVideos()
234 await myAccountPage.removeVideo(video2Name)
235 await myAccountPage.validRemove()
237 const count = await myAccountPage.countVideos([ videoName, video2Name ])
238 expect(count).toEqual(1)
241 it('Should delete the first video', async () => {
242 if (await skipIfUploadNotSupported()) return
244 await myAccountPage.removeVideo(videoName)
245 await myAccountPage.validRemove()