1 import { VideoWatchPage } from './po/video-watch.po'
2 import { VideoUploadPage } from './po/video-upload.po'
3 import { LoginPage } from './po/login.po'
4 import { browser } from 'protractor'
5 import { VideoUpdatePage } from './po/video-update.po'
6 import { MyAccountPage } from './po/my-account'
7 import { AppPage } from './po/app.po'
9 async function skipIfUploadNotSupported () {
10 if (await isMobileDevice() || await isSafari()) {
11 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
18 async function isMobileDevice () {
19 const caps = await browser.getCapabilities()
20 return caps.get('realMobile') === 'true' || caps.get('realMobile') === true
23 async function isSafari () {
24 const caps = await browser.getCapabilities()
25 return caps.get('browserName') && caps.get('browserName').toLowerCase() === 'safari'
28 describe('Videos workflow', () => {
29 let videoWatchPage: VideoWatchPage
30 let videoUploadPage: VideoUploadPage
31 let videoUpdatePage: VideoUpdatePage
32 let myAccountPage: MyAccountPage
33 let loginPage: LoginPage
36 let videoName = new Date().getTime() + ' video'
37 const video2Name = new Date().getTime() + ' second video'
38 const playlistName = new Date().getTime() + ' playlist'
39 let videoWatchUrl: string
41 beforeEach(async () => {
42 videoWatchPage = new VideoWatchPage()
43 videoUploadPage = new VideoUploadPage()
44 videoUpdatePage = new VideoUpdatePage()
45 myAccountPage = new MyAccountPage()
46 loginPage = new LoginPage()
47 appPage = new AppPage()
49 if (await isMobileDevice()) {
50 console.log('Mobile device detected.')
53 if (await isSafari()) {
54 console.log('Safari detected.')
57 if (!await isMobileDevice()) {
58 await browser.driver.manage().window().maximize()
62 it('Should log in', async () => {
63 if (await isMobileDevice() || await isSafari()) {
64 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
68 return loginPage.loginAsRootUser()
71 it('Should close the welcome modal', async () => {
72 if (await skipIfUploadNotSupported()) return
74 await appPage.closeWelcomeModal()
77 it('Should upload a video', async () => {
78 if (await skipIfUploadNotSupported()) return
80 await videoUploadPage.navigateTo()
82 await videoUploadPage.uploadVideo()
83 return videoUploadPage.validSecondUploadStep(videoName)
86 it('Should list videos', async () => {
87 await videoWatchPage.goOnVideosList(await isMobileDevice(), await isSafari())
89 if (await skipIfUploadNotSupported()) return
91 const videoNames = videoWatchPage.getVideosListName()
92 expect(videoNames).toContain(videoName)
95 it('Should go on video watch page', async () => {
96 let videoNameToExcept = videoName
98 if (await isMobileDevice() || await isSafari()) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
99 else await videoWatchPage.clickOnVideo(videoName)
101 return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
104 it('Should play the video', async () => {
105 videoWatchUrl = await browser.getCurrentUrl()
107 await videoWatchPage.playAndPauseVideo(true, await isMobileDevice())
108 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
111 it('Should watch the associated embed video', async () => {
112 await browser.waitForAngularEnabled(false)
114 await videoWatchPage.goOnAssociatedEmbed()
116 await videoWatchPage.playAndPauseVideo(false, await isMobileDevice())
117 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
119 await browser.waitForAngularEnabled(true)
122 it('Should watch the p2p media loader embed video', async () => {
123 await browser.waitForAngularEnabled(false)
125 await videoWatchPage.goOnP2PMediaLoaderEmbed()
127 await videoWatchPage.playAndPauseVideo(false, await isMobileDevice())
128 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
130 await browser.waitForAngularEnabled(true)
133 it('Should update the video', async () => {
134 if (await skipIfUploadNotSupported()) return
136 await browser.get(videoWatchUrl)
138 await videoWatchPage.clickOnUpdate()
140 videoName += ' updated'
141 await videoUpdatePage.updateName(videoName)
143 await videoUpdatePage.validUpdate()
145 const name = await videoWatchPage.getVideoName()
146 expect(name).toEqual(videoName)
149 it('Should add the video in my playlist', async () => {
150 if (await skipIfUploadNotSupported()) return
152 await videoWatchPage.clickOnSave()
154 await videoWatchPage.createPlaylist(playlistName)
156 await videoWatchPage.saveToPlaylist(playlistName)
158 await videoUploadPage.navigateTo()
160 await videoUploadPage.uploadVideo()
161 await videoUploadPage.validSecondUploadStep(video2Name)
163 await videoWatchPage.clickOnSave()
164 await videoWatchPage.saveToPlaylist(playlistName)
167 it('Should have the playlist in my account', async () => {
168 if (await skipIfUploadNotSupported()) return
170 await myAccountPage.navigateToMyPlaylists()
172 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
173 expect(videosNumberText).toEqual('2 videos')
175 await myAccountPage.clickOnPlaylist(playlistName)
177 const count = await myAccountPage.countTotalPlaylistElements()
178 expect(count).toEqual(2)
181 it('Should watch the playlist', async () => {
182 if (await skipIfUploadNotSupported()) return
184 await myAccountPage.playPlaylist()
186 await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
189 it('Should delete the video 2', async () => {
190 if (await skipIfUploadNotSupported()) return
192 await myAccountPage.navigateToMyVideos()
194 await myAccountPage.removeVideo(video2Name)
195 await myAccountPage.validRemove()
197 const count = await myAccountPage.countVideos([ videoName, video2Name ])
198 expect(count).toEqual(1)
201 it('Should delete the first video', async () => {
202 if (await skipIfUploadNotSupported()) return
204 await myAccountPage.removeVideo(videoName)
205 await myAccountPage.validRemove()