PeerTube/client/e2e/src/videos.e2e-spec.ts

248 lines
7.4 KiB
TypeScript
Raw Normal View History

2018-05-17 03:55:01 -05:00
import { browser } from 'protractor'
2020-01-23 07:23:19 -06:00
import { AppPage } from './po/app.po'
2020-05-12 09:38:55 -05:00
import { LoginPage } from './po/login.po'
import { MyAccountPage } from './po/my-account'
2020-08-07 03:25:07 -05:00
import { PlayerPage } from './po/player.po'
2020-05-12 09:38:55 -05:00
import { VideoUpdatePage } from './po/video-update.po'
import { VideoUploadPage } from './po/video-upload.po'
import { VideoWatchPage } from './po/video-watch.po'
import { isIOS, isMobileDevice, isSafari } from './utils'
2019-06-17 01:11:25 -05:00
async function skipIfUploadNotSupported () {
if (await isMobileDevice() || await isSafari()) {
console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
return true
}
return false
}
2018-05-17 03:55:01 -05:00
describe('Videos workflow', () => {
let videoWatchPage: VideoWatchPage
2019-06-17 01:11:25 -05:00
let videoUploadPage: VideoUploadPage
let videoUpdatePage: VideoUpdatePage
let myAccountPage: MyAccountPage
2018-05-17 03:55:01 -05:00
let loginPage: LoginPage
2020-01-23 07:23:19 -06:00
let appPage: AppPage
2020-08-07 03:25:07 -05:00
let playerPage: PlayerPage
2019-06-17 01:11:25 -05:00
2019-06-18 03:20:55 -05:00
let videoName = new Date().getTime() + ' video'
const video2Name = new Date().getTime() + ' second video'
const playlistName = new Date().getTime() + ' playlist'
2019-06-17 01:11:25 -05:00
let videoWatchUrl: string
2018-05-19 06:58:29 -05:00
beforeEach(async () => {
2018-05-17 03:55:01 -05:00
videoWatchPage = new VideoWatchPage()
2019-06-17 01:11:25 -05:00
videoUploadPage = new VideoUploadPage()
videoUpdatePage = new VideoUpdatePage()
myAccountPage = new MyAccountPage()
2018-05-17 03:55:01 -05:00
loginPage = new LoginPage()
2020-01-23 07:23:19 -06:00
appPage = new AppPage()
2020-08-07 03:25:07 -05:00
playerPage = new PlayerPage()
2018-05-19 06:58:29 -05:00
2020-05-12 09:38:55 -05:00
if (await isIOS()) {
// iOS does not seem to work with protractor
// https://github.com/angular/protractor/issues/2840
browser.ignoreSynchronization = true
2019-02-21 04:24:07 -06:00
2020-05-12 09:38:55 -05:00
console.log('iOS detected')
} else if (await isMobileDevice()) {
console.log('Android detected.')
} else if (await isSafari()) {
2019-02-21 04:24:07 -06:00
console.log('Safari detected.')
}
2020-05-11 02:41:39 -05:00
if (!await isMobileDevice()) {
await browser.driver.manage().window().maximize()
}
2018-05-17 03:55:01 -05:00
})
2019-06-17 01:11:25 -05:00
it('Should log in', async () => {
if (await isMobileDevice() || await isSafari()) {
2018-05-24 02:05:58 -05:00
console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
2018-05-19 06:58:29 -05:00
return
}
2018-05-17 03:55:01 -05:00
return loginPage.loginAsRootUser()
})
2020-01-23 07:23:19 -06:00
it('Should close the welcome modal', async () => {
if (await skipIfUploadNotSupported()) return
await appPage.closeWelcomeModal()
})
2018-05-17 03:55:01 -05:00
it('Should upload a video', async () => {
2019-06-17 01:11:25 -05:00
if (await skipIfUploadNotSupported()) return
2018-05-19 06:58:29 -05:00
2019-06-17 01:11:25 -05:00
await videoUploadPage.navigateTo()
2018-05-17 03:55:01 -05:00
2019-06-17 01:11:25 -05:00
await videoUploadPage.uploadVideo()
return videoUploadPage.validSecondUploadStep(videoName)
2018-05-17 03:55:01 -05:00
})
2019-05-14 06:59:10 -05:00
it('Should list videos', async () => {
2019-06-17 01:11:25 -05:00
await videoWatchPage.goOnVideosList(await isMobileDevice(), await isSafari())
2018-05-19 06:58:29 -05:00
2019-06-17 01:11:25 -05:00
if (await skipIfUploadNotSupported()) return
2018-05-17 03:55:01 -05:00
const videoNames = videoWatchPage.getVideosListName()
expect(videoNames).toContain(videoName)
})
it('Should go on video watch page', async () => {
2018-05-19 06:58:29 -05:00
let videoNameToExcept = videoName
2019-06-17 01:11:25 -05:00
if (await isMobileDevice() || await isSafari()) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
2018-05-19 06:58:29 -05:00
else await videoWatchPage.clickOnVideo(videoName)
2018-05-17 03:55:01 -05:00
2019-06-17 01:11:25 -05:00
return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
2018-05-17 03:55:01 -05:00
})
it('Should play the video', async () => {
2019-06-17 01:11:25 -05:00
videoWatchUrl = await browser.getCurrentUrl()
2020-08-07 03:25:07 -05:00
await playerPage.playAndPauseVideo(true)
expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
2018-05-22 09:02:29 -05:00
})
it('Should watch the associated embed video', async () => {
2019-02-21 04:24:07 -06:00
await browser.waitForAngularEnabled(false)
2018-05-22 09:02:29 -05:00
await videoWatchPage.goOnAssociatedEmbed()
2020-08-07 03:25:07 -05:00
await playerPage.playAndPauseVideo(false)
expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
2019-02-21 04:24:07 -06:00
await browser.waitForAngularEnabled(true)
})
it('Should watch the p2p media loader embed video', async () => {
await browser.waitForAngularEnabled(false)
await videoWatchPage.goOnP2PMediaLoaderEmbed()
2020-08-07 03:25:07 -05:00
await playerPage.playAndPauseVideo(false)
expect(playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
2019-02-21 04:24:07 -06:00
await browser.waitForAngularEnabled(true)
2018-05-17 03:55:01 -05:00
})
2019-06-17 01:11:25 -05:00
it('Should update the video', async () => {
if (await skipIfUploadNotSupported()) return
await browser.get(videoWatchUrl)
await videoWatchPage.clickOnUpdate()
2019-06-18 03:20:55 -05:00
videoName += ' updated'
await videoUpdatePage.updateName(videoName)
2019-06-17 01:11:25 -05:00
await videoUpdatePage.validUpdate()
const name = await videoWatchPage.getVideoName()
2019-06-18 03:20:55 -05:00
expect(name).toEqual(videoName)
2019-06-17 01:11:25 -05:00
})
it('Should add the video in my playlist', async () => {
if (await skipIfUploadNotSupported()) return
await videoWatchPage.clickOnSave()
2019-06-18 03:20:55 -05:00
await videoWatchPage.createPlaylist(playlistName)
await videoWatchPage.saveToPlaylist(playlistName)
2019-06-17 01:11:25 -05:00
await videoUploadPage.navigateTo()
await videoUploadPage.uploadVideo()
2019-06-18 03:20:55 -05:00
await videoUploadPage.validSecondUploadStep(video2Name)
2019-06-17 01:11:25 -05:00
await videoWatchPage.clickOnSave()
2019-06-18 03:20:55 -05:00
await videoWatchPage.saveToPlaylist(playlistName)
2019-06-17 01:11:25 -05:00
})
2019-06-18 03:20:55 -05:00
it('Should have the playlist in my account', async () => {
2019-06-17 01:11:25 -05:00
if (await skipIfUploadNotSupported()) return
await myAccountPage.navigateToMyPlaylists()
2019-06-18 03:20:55 -05:00
const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
2019-06-17 01:11:25 -05:00
expect(videosNumberText).toEqual('2 videos')
2019-06-18 03:20:55 -05:00
await myAccountPage.clickOnPlaylist(playlistName)
2019-06-17 01:11:25 -05:00
const count = await myAccountPage.countTotalPlaylistElements()
expect(count).toEqual(2)
})
it('Should watch the playlist', async () => {
if (await skipIfUploadNotSupported()) return
await myAccountPage.playPlaylist()
2020-08-07 03:25:07 -05:00
await browser.waitForAngularEnabled(false)
2019-06-18 03:20:55 -05:00
await videoWatchPage.waitUntilVideoName(video2Name, 20000 * 1000)
2020-08-07 03:25:07 -05:00
await browser.waitForAngularEnabled(true)
2019-06-17 01:11:25 -05:00
})
2020-08-07 01:47:10 -05:00
it('Should watch the webtorrent playlist in the embed', async () => {
if (await skipIfUploadNotSupported()) return
2020-08-07 03:25:07 -05:00
const accessToken = await browser.executeScript(`return window.localStorage.getItem('access_token');`)
const refreshToken = await browser.executeScript(`return window.localStorage.getItem('refresh_token');`)
2020-08-07 01:47:10 -05:00
await browser.waitForAngularEnabled(false)
await myAccountPage.goOnAssociatedPlaylistEmbed()
2020-08-07 03:25:07 -05:00
await browser.executeScript(`window.localStorage.setItem('access_token', '${accessToken}');`)
await browser.executeScript(`window.localStorage.setItem('refresh_token', '${refreshToken}');`)
await browser.executeScript(`window.localStorage.setItem('token_type', 'Bearer');`)
2020-08-07 01:47:10 -05:00
2020-08-07 03:25:07 -05:00
await browser.refresh()
await playerPage.playVideo()
await playerPage.waitUntilPlaylistInfo('2/2')
await browser.waitForAngularEnabled(true)
})
it('Should watch the HLS playlist in the embed', async () => {
await browser.waitForAngularEnabled(false)
await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
await playerPage.playVideo()
await playerPage.waitUntilPlaylistInfo('2/2')
2020-08-07 01:47:10 -05:00
await browser.waitForAngularEnabled(true)
})
2019-06-18 03:20:55 -05:00
it('Should delete the video 2', async () => {
2019-06-17 01:11:25 -05:00
if (await skipIfUploadNotSupported()) return
2020-08-07 03:25:07 -05:00
// Go to the dev website
await browser.get(videoWatchUrl)
2019-06-17 01:11:25 -05:00
await myAccountPage.navigateToMyVideos()
2019-06-18 03:20:55 -05:00
await myAccountPage.removeVideo(video2Name)
2019-06-17 01:11:25 -05:00
await myAccountPage.validRemove()
2019-06-18 03:20:55 -05:00
const count = await myAccountPage.countVideos([ videoName, video2Name ])
2019-06-17 01:11:25 -05:00
expect(count).toEqual(1)
})
it('Should delete the first video', async () => {
if (await skipIfUploadNotSupported()) return
2019-06-18 03:20:55 -05:00
await myAccountPage.removeVideo(videoName)
2019-06-17 01:11:25 -05:00
await myAccountPage.validRemove()
})
2018-05-17 03:55:01 -05:00
})