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 { browserSleep, go, isIOS, isMobileDevice, isSafari } from './utils'
9 function isUploadUnsupported () {
10 if (isMobileDevice() || isSafari()) {
11 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
18 describe('Videos workflow', () => {
19 let videoWatchPage: VideoWatchPage
20 let videoUploadPage: VideoUploadPage
21 let videoUpdatePage: VideoUpdatePage
22 let myAccountPage: MyAccountPage
23 let loginPage: LoginPage
24 let playerPage: PlayerPage
26 let videoName = Math.random() + ' video'
27 const video2Name = Math.random() + ' second video'
28 const playlistName = Math.random() + ' playlist'
29 let videoWatchUrl: string
33 console.log('iOS detected')
34 } else if (isMobileDevice()) {
35 console.log('Android detected.')
36 } else if (isSafari()) {
37 console.log('Safari detected.')
40 if (isUploadUnsupported()) return
42 await browser.waitUntil(async () => {
44 await browserSleep(500)
46 return $('<my-app>').isDisplayed()
47 }, { timeout: 20 * 1000 })
50 beforeEach(async () => {
51 videoWatchPage = new VideoWatchPage()
52 videoUploadPage = new VideoUploadPage()
53 videoUpdatePage = new VideoUpdatePage()
54 myAccountPage = new MyAccountPage()
55 loginPage = new LoginPage()
56 playerPage = new PlayerPage()
58 if (!isMobileDevice()) {
59 await browser.maximizeWindow()
63 it('Should log in', async () => {
64 if (isMobileDevice() || isSafari()) {
65 console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
69 return loginPage.loginAsRootUser()
72 it('Should upload a video', async () => {
73 if (isUploadUnsupported()) return
75 await videoUploadPage.navigateTo()
77 await videoUploadPage.uploadVideo()
78 return videoUploadPage.validSecondUploadStep(videoName)
81 it('Should list videos', async () => {
82 await videoWatchPage.goOnVideosList(isMobileDevice(), isSafari())
84 if (isUploadUnsupported()) return
86 const videoNames = await videoWatchPage.getVideosListName()
87 expect(videoNames).toContain(videoName)
90 it('Should go on video watch page', async () => {
91 let videoNameToExcept = videoName
93 if (isMobileDevice() || isSafari()) {
94 await go('https://peertube2.cpy.re/w/122d093a-1ede-43bd-bd34-59d2931ffc5e')
95 videoNameToExcept = 'E2E tests'
97 await videoWatchPage.clickOnVideo(videoName)
100 return videoWatchPage.waitWatchVideoName(videoNameToExcept, isMobileDevice(), isSafari())
103 it('Should play the video', async () => {
104 videoWatchUrl = await browser.getUrl()
106 await playerPage.playAndPauseVideo(true)
107 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
110 it('Should watch the associated embed video', async () => {
111 await videoWatchPage.goOnAssociatedEmbed()
113 await playerPage.playAndPauseVideo(false)
114 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
117 it('Should watch the p2p media loader embed video', async () => {
118 await videoWatchPage.goOnP2PMediaLoaderEmbed()
120 await playerPage.playAndPauseVideo(false)
121 expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
124 it('Should update the video', async () => {
125 if (isUploadUnsupported()) return
127 await go(videoWatchUrl)
129 await videoWatchPage.clickOnUpdate()
131 videoName += ' updated'
132 await videoUpdatePage.updateName(videoName)
134 await videoUpdatePage.validUpdate()
136 const name = await videoWatchPage.getVideoName()
137 expect(name).toEqual(videoName)
140 it('Should add the video in my playlist', async () => {
141 if (isUploadUnsupported()) return
143 await videoWatchPage.clickOnSave()
145 await videoWatchPage.createPlaylist(playlistName)
147 await videoWatchPage.saveToPlaylist(playlistName)
148 await browser.pause(5000)
150 await videoUploadPage.navigateTo()
152 await videoUploadPage.uploadVideo()
153 await videoUploadPage.validSecondUploadStep(video2Name)
155 await videoWatchPage.clickOnSave()
156 await videoWatchPage.saveToPlaylist(playlistName)
159 it('Should have the playlist in my account', async () => {
160 if (isUploadUnsupported()) return
162 await myAccountPage.navigateToMyPlaylists()
164 const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
165 expect(videosNumberText).toEqual('2 videos')
167 await myAccountPage.clickOnPlaylist(playlistName)
169 const count = await myAccountPage.countTotalPlaylistElements()
170 expect(count).toEqual(2)
173 it('Should watch the playlist', async () => {
174 if (isUploadUnsupported()) return
176 await myAccountPage.playPlaylist()
178 await videoWatchPage.waitUntilVideoName(video2Name, 30 * 1000)
181 it('Should watch the webtorrent playlist in the embed', async () => {
182 if (isUploadUnsupported()) return
184 const accessToken = await browser.execute(`return window.localStorage.getItem('access_token');`)
185 const refreshToken = await browser.execute(`return window.localStorage.getItem('refresh_token');`)
187 await myAccountPage.goOnAssociatedPlaylistEmbed()
189 await playerPage.waitUntilPlayerWrapper()
191 console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)
193 await browser.execute(`window.localStorage.setItem('access_token', '${accessToken}');`)
194 await browser.execute(`window.localStorage.setItem('refresh_token', '${refreshToken}');`)
195 await browser.execute(`window.localStorage.setItem('token_type', 'Bearer');`)
197 await browser.refresh()
199 await playerPage.playVideo()
201 await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
204 it('Should watch the HLS playlist in the embed', async () => {
205 await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
207 await playerPage.playVideo()
209 await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
212 it('Should delete the video 2', async () => {
213 if (isUploadUnsupported()) return
215 // Go to the dev website
216 await go(videoWatchUrl)
218 await myAccountPage.navigateToMyVideos()
220 await myAccountPage.removeVideo(video2Name)
221 await myAccountPage.validRemove()
223 await browser.waitUntil(async () => {
224 const count = await myAccountPage.countVideos([ videoName, video2Name ])
230 it('Should delete the first video', async () => {
231 if (isUploadUnsupported()) return
233 await myAccountPage.removeVideo(videoName)
234 await myAccountPage.validRemove()