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.')
58 it('Should log in', async () => {
59 if (await isMobileDevice() || await isSafari()) {
60 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
64 return loginPage.loginAsRootUser()
67 it('Should close the welcome modal', async () => {
68 if (await skipIfUploadNotSupported()) return
70 await appPage.closeWelcomeModal()
73 it('Should upload a video', async () => {
74 if (await skipIfUploadNotSupported()) return
76 await videoUploadPage.navigateTo()
78 await videoUploadPage.uploadVideo()
79 return videoUploadPage.validSecondUploadStep(videoName)
82 it('Should list videos', async () => {
83 await videoWatchPage.goOnVideosList(await isMobileDevice(), await isSafari())
85 if (await skipIfUploadNotSupported()) return
87 const videoNames = videoWatchPage.getVideosListName()
88 expect(videoNames).toContain(videoName)
91 it('Should go on video watch page', async () => {
92 let videoNameToExcept = videoName
94 if (await isMobileDevice() || await isSafari()) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
95 else await videoWatchPage.clickOnVideo(videoName)
97 return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
100 it('Should play the video', async () => {
101 videoWatchUrl = await browser.getCurrentUrl()
103 await videoWatchPage.playAndPauseVideo(true, await isMobileDevice())
104 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
107 it('Should watch the associated embed video', async () => {
108 await browser.waitForAngularEnabled(false)
110 await videoWatchPage.goOnAssociatedEmbed()
112 await videoWatchPage.playAndPauseVideo(false, await isMobileDevice())
113 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
115 await browser.waitForAngularEnabled(true)
118 it('Should watch the p2p media loader embed video', async () => {
119 await browser.waitForAngularEnabled(false)
121 await videoWatchPage.goOnP2PMediaLoaderEmbed()
123 await videoWatchPage.playAndPauseVideo(false, await isMobileDevice())
124 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
126 await browser.waitForAngularEnabled(true)
129 it('Should update the video', async () => {
130 if (await skipIfUploadNotSupported()) return
132 await browser.get(videoWatchUrl)
134 await videoWatchPage.clickOnUpdate()
136 videoName += ' updated'
137 await videoUpdatePage.updateName(videoName)
139 await videoUpdatePage.validUpdate()
141 const name = await videoWatchPage.getVideoName()
142 expect(name).toEqual(videoName)
145 it('Should add the video in my playlist', async () => {
146 if (await skipIfUploadNotSupported()) return
148 await videoWatchPage.clickOnSave()
150 await videoWatchPage.createPlaylist(playlistName)
152 await videoWatchPage.saveToPlaylist(playlistName)
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 await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
185 it('Should delete the video 2', async () => {
186 if (await skipIfUploadNotSupported()) return
188 await myAccountPage.navigateToMyVideos()
190 await myAccountPage.removeVideo(video2Name)
191 await myAccountPage.validRemove()
193 const count = await myAccountPage.countVideos([ videoName, video2Name ])
194 expect(count).toEqual(1)
197 it('Should delete the first video', async () => {
198 if (await skipIfUploadNotSupported()) return
200 await myAccountPage.removeVideo(videoName)
201 await myAccountPage.validRemove()