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'
8 async function skipIfUploadNotSupported () {
9 if (await isMobileDevice() || await isSafari()) {
10 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
17 async function isMobileDevice () {
18 const caps = await browser.getCapabilities()
19 return caps.get('realMobile') === 'true' || caps.get('realMobile') === true
22 async function isSafari () {
23 const caps = await browser.getCapabilities()
24 return caps.get('browserName') && caps.get('browserName').toLowerCase() === 'safari'
27 describe('Videos workflow', () => {
28 let videoWatchPage: VideoWatchPage
29 let videoUploadPage: VideoUploadPage
30 let videoUpdatePage: VideoUpdatePage
31 let myAccountPage: MyAccountPage
32 let loginPage: LoginPage
34 let videoName = new Date().getTime() + ' video'
35 const video2Name = new Date().getTime() + ' second video'
36 const playlistName = new Date().getTime() + ' playlist'
37 let videoWatchUrl: string
39 beforeEach(async () => {
40 videoWatchPage = new VideoWatchPage()
41 videoUploadPage = new VideoUploadPage()
42 videoUpdatePage = new VideoUpdatePage()
43 myAccountPage = new MyAccountPage()
44 loginPage = new LoginPage()
46 if (await isMobileDevice()) {
47 console.log('Mobile device detected.')
50 if (await isSafari()) {
51 console.log('Safari detected.')
55 it('Should log in', async () => {
56 if (await isMobileDevice() || await isSafari()) {
57 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
61 return loginPage.loginAsRootUser()
64 it('Should upload a video', async () => {
65 if (await skipIfUploadNotSupported()) return
67 await videoUploadPage.navigateTo()
69 await videoUploadPage.uploadVideo()
70 return videoUploadPage.validSecondUploadStep(videoName)
73 it('Should list videos', async () => {
74 await videoWatchPage.goOnVideosList(await isMobileDevice(), await isSafari())
76 if (await skipIfUploadNotSupported()) return
78 const videoNames = videoWatchPage.getVideosListName()
79 expect(videoNames).toContain(videoName)
82 it('Should go on video watch page', async () => {
83 let videoNameToExcept = videoName
85 if (await isMobileDevice() || await isSafari()) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
86 else await videoWatchPage.clickOnVideo(videoName)
88 return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
91 it('Should play the video', async () => {
92 videoWatchUrl = await browser.getCurrentUrl()
94 await videoWatchPage.playAndPauseVideo(true, await isMobileDevice())
95 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
98 it('Should watch the associated embed video', async () => {
99 await browser.waitForAngularEnabled(false)
101 await videoWatchPage.goOnAssociatedEmbed()
103 await videoWatchPage.playAndPauseVideo(false, await isMobileDevice())
104 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
106 await browser.waitForAngularEnabled(true)
109 it('Should watch the p2p media loader embed video', async () => {
110 await browser.waitForAngularEnabled(false)
112 await videoWatchPage.goOnP2PMediaLoaderEmbed()
114 await videoWatchPage.playAndPauseVideo(false, await isMobileDevice())
115 expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
117 await browser.waitForAngularEnabled(true)
120 it('Should update the video', async () => {
121 if (await skipIfUploadNotSupported()) return
123 await browser.get(videoWatchUrl)
125 await videoWatchPage.clickOnUpdate()
127 videoName += ' updated'
128 await videoUpdatePage.updateName(videoName)
130 await videoUpdatePage.validUpdate()
132 const name = await videoWatchPage.getVideoName()
133 expect(name).toEqual(videoName)
136 it('Should add the video in my playlist', async () => {
137 if (await skipIfUploadNotSupported()) return
139 await videoWatchPage.clickOnSave()
141 await videoWatchPage.createPlaylist(playlistName)
143 await videoWatchPage.saveToPlaylist(playlistName)
145 await videoUploadPage.navigateTo()
147 await videoUploadPage.uploadVideo()
148 await videoUploadPage.validSecondUploadStep(video2Name)
150 await videoWatchPage.clickOnSave()
151 await videoWatchPage.saveToPlaylist(playlistName)
154 it('Should have the playlist in my account', async () => {
155 if (await skipIfUploadNotSupported()) return
157 await myAccountPage.navigateToMyPlaylists()
159 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
160 expect(videosNumberText).toEqual('2 videos')
162 await myAccountPage.clickOnPlaylist(playlistName)
164 const count = await myAccountPage.countTotalPlaylistElements()
165 expect(count).toEqual(2)
168 it('Should watch the playlist', async () => {
169 if (await skipIfUploadNotSupported()) return
171 await myAccountPage.playPlaylist()
173 await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
176 it('Should delete the video 2', async () => {
177 if (await skipIfUploadNotSupported()) return
179 await myAccountPage.navigateToMyVideos()
181 await myAccountPage.removeVideo(video2Name)
182 await myAccountPage.validRemove()
184 const count = await myAccountPage.countVideos([ videoName, video2Name ])
185 expect(count).toEqual(1)
188 it('Should delete the first video', async () => {
189 if (await skipIfUploadNotSupported()) return
191 await myAccountPage.removeVideo(videoName)
192 await myAccountPage.validRemove()