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 { 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
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 appPage = new AppPage()
41 // iOS does not seem to work with protractor
42 // https://github.com/angular/protractor/issues/2840
43 browser.ignoreSynchronization = true
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 close the welcome modal', async () => {
67 if (await skipIfUploadNotSupported()) return
69 await appPage.closeWelcomeModal()
72 it('Should upload a video', async () => {
73 if (await skipIfUploadNotSupported()) return
75 await videoUploadPage.navigateTo()
77 await videoUploadPage.uploadVideo()
78 return videoUploadPage.validSecondUploadStep(videoName)
81 it('Should list videos', async () => {
82 await videoWatchPage.goOnVideosList(await isMobileDevice(), await isSafari())
84 if (await skipIfUploadNotSupported()) return
86 const videoNames = videoWatchPage.getVideosListName()
87 expect(videoNames).toContain(videoName)
90 it('Should go on video watch page', async () => {
91 let videoNameToExcept = videoName
93 if (await isMobileDevice() || await isSafari()) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
94 else await videoWatchPage.clickOnVideo(videoName)
96 return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
99 it('Should play the video', async () => {
100 videoWatchUrl = await browser.getCurrentUrl()
102 await videoWatchPage.playAndPauseVideo(true)
103 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
106 it('Should watch the associated embed video', async () => {
107 await browser.waitForAngularEnabled(false)
109 await videoWatchPage.goOnAssociatedEmbed()
111 await videoWatchPage.playAndPauseVideo(false)
112 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
114 await browser.waitForAngularEnabled(true)
117 it('Should watch the p2p media loader embed video', async () => {
118 await browser.waitForAngularEnabled(false)
120 await videoWatchPage.goOnP2PMediaLoaderEmbed()
122 await videoWatchPage.playAndPauseVideo(false)
123 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
125 await browser.waitForAngularEnabled(true)
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)
153 await videoUploadPage.navigateTo()
155 await videoUploadPage.uploadVideo()
156 await videoUploadPage.validSecondUploadStep(video2Name)
158 await videoWatchPage.clickOnSave()
159 await videoWatchPage.saveToPlaylist(playlistName)
162 it('Should have the playlist in my account', async () => {
163 if (await skipIfUploadNotSupported()) return
165 await myAccountPage.navigateToMyPlaylists()
167 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
168 expect(videosNumberText).toEqual('2 videos')
170 await myAccountPage.clickOnPlaylist(playlistName)
172 const count = await myAccountPage.countTotalPlaylistElements()
173 expect(count).toEqual(2)
176 it('Should watch the playlist', async () => {
177 if (await skipIfUploadNotSupported()) return
179 await myAccountPage.playPlaylist()
181 await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
184 it('Should watch the webtorrent playlist in the embed', async () => {
185 if (await skipIfUploadNotSupported()) return
187 await browser.waitForAngularEnabled(false)
189 await myAccountPage.goOnAssociatedPlaylistEmbed()
191 await videoWatchPage.playAndPauseVideo(false)
193 await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
195 await browser.waitForAngularEnabled(true)
198 it('Should delete the video 2', async () => {
199 if (await skipIfUploadNotSupported()) return
201 await myAccountPage.navigateToMyVideos()
203 await myAccountPage.removeVideo(video2Name)
204 await myAccountPage.validRemove()
206 const count = await myAccountPage.countVideos([ videoName, video2Name ])
207 expect(count).toEqual(1)
210 it('Should delete the first video', async () => {
211 if (await skipIfUploadNotSupported()) return
213 await myAccountPage.removeVideo(videoName)
214 await myAccountPage.validRemove()