1 import { LoginPage } from './po/login.po'
2 import { MyAccountPage } from './po/my-account'
3 import { PlayerPage } from './po/player.po'
4 import { VideoUpdatePage } from './po/video-update.po'
5 import { VideoUploadPage } from './po/video-upload.po'
6 import { VideoWatchPage } from './po/video-watch.po'
7 import { FIXTURE_URLS } from './urls'
8 import { browserSleep, go, isIOS, isMobileDevice, isSafari } 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 workflow', () => {
20 let videoWatchPage: VideoWatchPage
21 let videoUploadPage: VideoUploadPage
22 let videoUpdatePage: VideoUpdatePage
23 let myAccountPage: MyAccountPage
24 let loginPage: LoginPage
25 let playerPage: PlayerPage
27 let videoName = Math.random() + ' video'
28 const video2Name = Math.random() + ' second video'
29 const playlistName = Math.random() + ' playlist'
30 let videoWatchUrl: string
34 console.log('iOS detected')
35 } else if (isMobileDevice()) {
36 console.log('Android detected.')
37 } else if (isSafari()) {
38 console.log('Safari detected.')
41 if (isUploadUnsupported()) return
43 await browser.waitUntil(async () => {
45 await browserSleep(500)
47 return $('<my-app>').isDisplayed()
48 }, { timeout: 20 * 1000 })
51 beforeEach(async () => {
52 videoWatchPage = new VideoWatchPage()
53 videoUploadPage = new VideoUploadPage()
54 videoUpdatePage = new VideoUpdatePage()
55 myAccountPage = new MyAccountPage()
56 loginPage = new LoginPage()
57 playerPage = new PlayerPage()
59 if (!isMobileDevice()) {
60 await browser.maximizeWindow()
64 it('Should log in', async () => {
65 if (isMobileDevice() || isSafari()) {
66 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
70 return loginPage.loginAsRootUser()
73 it('Should upload a video', async () => {
74 if (isUploadUnsupported()) return
76 await videoUploadPage.navigateTo()
78 await videoUploadPage.uploadVideo()
79 return videoUploadPage.validSecondUploadStep(videoName)
82 it('Should list videos', async () => {
83 await videoWatchPage.goOnVideosList(isMobileDevice(), isSafari())
85 if (isUploadUnsupported()) return
87 const videoNames = await videoWatchPage.getVideosListName()
88 expect(videoNames).toContain(videoName)
91 it('Should go on video watch page', async () => {
92 let videoNameToExcept = videoName
94 if (isMobileDevice() || isSafari()) {
95 await go(FIXTURE_URLS.WEBTORRENT_VIDEO)
96 videoNameToExcept = 'E2E tests'
98 await videoWatchPage.clickOnVideo(videoName)
101 return videoWatchPage.waitWatchVideoName(videoNameToExcept, isMobileDevice(), isSafari())
104 it('Should play the video', async () => {
105 videoWatchUrl = await browser.getUrl()
107 await playerPage.playAndPauseVideo(true, 2)
108 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
111 it('Should watch the associated embed video', async () => {
112 await videoWatchPage.goOnAssociatedEmbed()
114 await playerPage.playAndPauseVideo(false, 2)
115 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
118 it('Should watch the p2p media loader embed video', async () => {
119 await videoWatchPage.goOnP2PMediaLoaderEmbed()
121 await playerPage.playAndPauseVideo(false, 2)
122 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
125 it('Should update the video', async () => {
126 if (isUploadUnsupported()) return
128 await go(videoWatchUrl)
130 await videoWatchPage.clickOnUpdate()
132 videoName += ' updated'
133 await videoUpdatePage.updateName(videoName)
135 await videoUpdatePage.validUpdate()
137 const name = await videoWatchPage.getVideoName()
138 expect(name).toEqual(videoName)
141 it('Should add the video in my playlist', async () => {
142 if (isUploadUnsupported()) return
144 await videoWatchPage.clickOnSave()
146 await videoWatchPage.createPlaylist(playlistName)
148 await videoWatchPage.saveToPlaylist(playlistName)
149 await browser.pause(5000)
151 await videoUploadPage.navigateTo()
153 await videoUploadPage.uploadVideo()
154 await videoUploadPage.validSecondUploadStep(video2Name)
156 await videoWatchPage.clickOnSave()
157 await videoWatchPage.saveToPlaylist(playlistName)
160 it('Should have the playlist in my account', async () => {
161 if (isUploadUnsupported()) return
163 await myAccountPage.navigateToMyPlaylists()
165 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
166 expect(videosNumberText).toEqual('2 videos')
168 await myAccountPage.clickOnPlaylist(playlistName)
170 const count = await myAccountPage.countTotalPlaylistElements()
171 expect(count).toEqual(2)
174 it('Should watch the playlist', async () => {
175 if (isUploadUnsupported()) return
177 await myAccountPage.playPlaylist()
179 await videoWatchPage.waitUntilVideoName(video2Name, 30 * 1000)
182 it('Should watch the webtorrent playlist in the embed', async () => {
183 if (isUploadUnsupported()) return
185 const accessToken = await browser.execute(`return window.localStorage.getItem('access_token');`)
186 const refreshToken = await browser.execute(`return window.localStorage.getItem('refresh_token');`)
188 await myAccountPage.goOnAssociatedPlaylistEmbed()
190 await playerPage.waitUntilPlayerWrapper()
192 console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)
194 await browser.execute(`window.localStorage.setItem('access_token', '${accessToken}');`)
195 await browser.execute(`window.localStorage.setItem('refresh_token', '${refreshToken}');`)
196 await browser.execute(`window.localStorage.setItem('token_type', 'Bearer');`)
198 await browser.refresh()
200 await playerPage.playVideo()
202 await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
205 it('Should watch the HLS playlist in the embed', async () => {
206 await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
208 await playerPage.playVideo()
210 await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
213 it('Should delete the video 2', async () => {
214 if (isUploadUnsupported()) return
216 // Go to the dev website
217 await go(videoWatchUrl)
219 await myAccountPage.navigateToMyVideos()
221 await myAccountPage.removeVideo(video2Name)
222 await myAccountPage.validRemove()
224 await browser.waitUntil(async () => {
225 const count = await myAccountPage.countVideos([ videoName, video2Name ])
231 it('Should delete the first video', async () => {
232 if (isUploadUnsupported()) return
234 await myAccountPage.removeVideo(videoName)
235 await myAccountPage.validRemove()