1 import { LoginPage } from '../po/login.po'
2 import { MyAccountPage } from '../po/my-account.po'
3 import { PlayerPage } from '../po/player.po'
4 import { VideoListPage } from '../po/video-list.po'
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 { FIXTURE_URLS, go, isIOS, isMobileDevice, isSafari, waitServerUp } from '../utils'
10 function isUploadUnsupported () {
11 if (isMobileDevice() || isSafari()) {
12 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
19 describe('Videos all workflow', () => {
20 let videoWatchPage: VideoWatchPage
21 let videoListPage: VideoListPage
22 let videoUploadPage: VideoUploadPage
23 let videoUpdatePage: VideoUpdatePage
24 let myAccountPage: MyAccountPage
25 let loginPage: LoginPage
26 let playerPage: PlayerPage
28 let videoName = Math.random() + ' video'
29 const video2Name = Math.random() + ' second video'
30 const playlistName = Math.random() + ' playlist'
31 let videoWatchUrl: string
35 console.log('iOS detected')
36 } else if (isMobileDevice()) {
37 console.log('Android detected.')
38 } else if (isSafari()) {
39 console.log('Safari detected.')
42 if (isUploadUnsupported()) return
47 beforeEach(async () => {
48 videoWatchPage = new VideoWatchPage(isMobileDevice(), isSafari())
49 videoUploadPage = new VideoUploadPage()
50 videoUpdatePage = new VideoUpdatePage()
51 myAccountPage = new MyAccountPage()
52 loginPage = new LoginPage(isMobileDevice())
53 playerPage = new PlayerPage()
54 videoListPage = new VideoListPage(isMobileDevice(), isSafari())
56 if (!isMobileDevice()) {
57 await browser.maximizeWindow()
61 it('Should log in', async () => {
62 if (isMobileDevice() || isSafari()) {
63 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
67 return loginPage.loginAsRootUser()
70 it('Should upload a video', async () => {
71 if (isUploadUnsupported()) return
73 await videoUploadPage.navigateTo()
75 await videoUploadPage.uploadVideo('video.mp4')
76 return videoUploadPage.validSecondUploadStep(videoName)
79 it('Should list videos', async () => {
80 await videoListPage.goOnVideosList()
82 if (isUploadUnsupported()) return
84 const videoNames = await videoListPage.getVideosListName()
85 expect(videoNames).toContain(videoName)
88 it('Should go on video watch page', async () => {
89 let videoNameToExcept = videoName
91 if (isMobileDevice() || isSafari()) {
92 await go(FIXTURE_URLS.WEBTORRENT_VIDEO)
93 videoNameToExcept = 'E2E tests'
95 await videoListPage.clickOnVideo(videoName)
98 return videoWatchPage.waitWatchVideoName(videoNameToExcept)
101 it('Should play the video', async () => {
102 videoWatchUrl = await browser.getUrl()
104 await playerPage.playAndPauseVideo(true, 2)
105 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
108 it('Should watch the associated embed video', async () => {
109 await videoWatchPage.goOnAssociatedEmbed()
111 await playerPage.playAndPauseVideo(false, 2)
112 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
115 it('Should watch the p2p media loader embed video', async () => {
116 await videoWatchPage.goOnP2PMediaLoaderEmbed()
118 await playerPage.playAndPauseVideo(false, 2)
119 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
122 it('Should update the video', async () => {
123 if (isUploadUnsupported()) return
125 await go(videoWatchUrl)
127 await videoWatchPage.clickOnUpdate()
129 videoName += ' updated'
130 await videoUpdatePage.updateName(videoName)
132 await videoUpdatePage.validUpdate()
134 const name = await videoWatchPage.getVideoName()
135 expect(name).toEqual(videoName)
138 it('Should add the video in my playlist', async () => {
139 if (isUploadUnsupported()) return
141 await videoWatchPage.clickOnSave()
143 await videoWatchPage.createPlaylist(playlistName)
145 await videoWatchPage.saveToPlaylist(playlistName)
146 await browser.pause(5000)
148 await videoUploadPage.navigateTo()
150 await videoUploadPage.uploadVideo('video2.mp4')
151 await videoUploadPage.validSecondUploadStep(video2Name)
153 await videoWatchPage.clickOnSave()
154 await videoWatchPage.saveToPlaylist(playlistName)
157 it('Should have the playlist in my account', async () => {
158 if (isUploadUnsupported()) return
160 await myAccountPage.navigateToMyPlaylists()
162 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
163 expect(videosNumberText).toEqual('2 videos')
165 await myAccountPage.clickOnPlaylist(playlistName)
167 const count = await myAccountPage.countTotalPlaylistElements()
168 expect(count).toEqual(2)
171 it('Should watch the playlist', async () => {
172 if (isUploadUnsupported()) return
174 await myAccountPage.playPlaylist()
176 await videoWatchPage.waitUntilVideoName(video2Name, 40 * 1000)
179 it('Should watch the webtorrent playlist in the embed', async () => {
180 if (isUploadUnsupported()) return
182 const accessToken = await browser.execute(`return window.localStorage.getItem('access_token');`)
183 const refreshToken = await browser.execute(`return window.localStorage.getItem('refresh_token');`)
185 await myAccountPage.goOnAssociatedPlaylistEmbed()
187 await playerPage.waitUntilPlayerWrapper()
189 console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)
191 await browser.execute(`window.localStorage.setItem('access_token', '${accessToken}');`)
192 await browser.execute(`window.localStorage.setItem('refresh_token', '${refreshToken}');`)
193 await browser.execute(`window.localStorage.setItem('token_type', 'Bearer');`)
195 await browser.refresh()
197 await playerPage.playVideo()
199 await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
202 it('Should watch the HLS playlist in the embed', async () => {
203 await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
205 await playerPage.playVideo()
207 await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
210 it('Should delete the video 2', async () => {
211 if (isUploadUnsupported()) return
213 // Go to the dev website
214 await go(videoWatchUrl)
216 await myAccountPage.navigateToMyVideos()
218 await myAccountPage.removeVideo(video2Name)
219 await myAccountPage.validRemove()
221 await browser.waitUntil(async () => {
222 const count = await myAccountPage.countVideos([ videoName, video2Name ])
228 it('Should delete the first video', async () => {
229 if (isUploadUnsupported()) return
231 await myAccountPage.removeVideo(videoName)
232 await myAccountPage.validRemove()