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

253 lines
7.8 KiB
TypeScript
Raw Normal View History

2018-05-17 03:55:01 -05:00
import { browser } from 'protractor'
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-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-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
2020-08-26 07:38:34 -05:00
browser.waitForAngularEnabled(false)
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()
})
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
2020-08-07 07:03:46 -05:00
if (await isMobileDevice() || await isSafari()) {
await browser.get('https://peertube2.cpy.re/w/122d093a-1ede-43bd-bd34-59d2931ffc5e')
2020-08-07 07:03:46 -05:00
videoNameToExcept = 'E2E tests'
} 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 () => {
2020-08-26 07:38:34 -05:00
const oldValue = await browser.waitForAngularEnabled()
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
2020-08-26 07:38:34 -05:00
await browser.waitForAngularEnabled(oldValue)
2019-02-21 04:24:07 -06:00
})
it('Should watch the p2p media loader embed video', async () => {
2020-08-26 07:38:34 -05:00
const oldValue = await browser.waitForAngularEnabled()
2019-02-21 04:24:07 -06:00
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
2020-08-26 07:38:34 -05:00
await browser.waitForAngularEnabled(oldValue)
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)
2021-03-05 03:26:10 -06:00
await browser.sleep(5000)
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-26 07:38:34 -05:00
const oldValue = await browser.waitForAngularEnabled()
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
2020-08-26 07:38:34 -05:00
await browser.waitForAngularEnabled(oldValue)
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-26 07:38:34 -05:00
const oldValue = await browser.waitForAngularEnabled()
2020-08-07 01:47:10 -05:00
await browser.waitForAngularEnabled(false)
await myAccountPage.goOnAssociatedPlaylistEmbed()
2020-11-30 02:11:12 -06:00
await playerPage.waitUntilPlayerWrapper()
2020-12-15 04:45:29 -06:00
console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)
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')
2020-08-26 07:38:34 -05:00
await browser.waitForAngularEnabled(oldValue)
2020-08-07 03:25:07 -05:00
})
it('Should watch the HLS playlist in the embed', async () => {
2020-08-26 07:38:34 -05:00
const oldValue = await browser.waitForAngularEnabled()
2020-08-07 03:25:07 -05:00
await browser.waitForAngularEnabled(false)
await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
await playerPage.playVideo()
await playerPage.waitUntilPlaylistInfo('2/2')
2020-08-07 01:47:10 -05:00
2020-08-26 07:38:34 -05:00
await browser.waitForAngularEnabled(oldValue)
2020-08-07 01:47:10 -05:00
})
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
})