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

235 lines
6.8 KiB
TypeScript
Raw Normal View History

2021-09-03 10:27:04 +02:00
import { LoginPage } from '../po/login.po'
import { MyAccountPage } from '../po/my-account'
import { PlayerPage } from '../po/player.po'
import { VideoListPage } from '../po/video-list.po'
import { VideoUpdatePage } from '../po/video-update.po'
import { VideoUploadPage } from '../po/video-upload.po'
import { VideoWatchPage } from '../po/video-watch.po'
import { FIXTURE_URLS, go, isIOS, isMobileDevice, isSafari, waitServerUp } from '../utils'
2019-06-17 08:11:25 +02:00
2021-08-30 16:24:25 +02:00
function isUploadUnsupported () {
if (isMobileDevice() || isSafari()) {
2019-06-17 08:11:25 +02:00
console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
return true
}
return false
}
2021-09-03 10:27:04 +02:00
describe('Videos all workflow', () => {
2018-05-17 10:55:01 +02:00
let videoWatchPage: VideoWatchPage
2021-09-03 10:27:04 +02:00
let videoListPage: VideoListPage
2019-06-17 08:11:25 +02:00
let videoUploadPage: VideoUploadPage
let videoUpdatePage: VideoUpdatePage
let myAccountPage: MyAccountPage
2018-05-17 10:55:01 +02:00
let loginPage: LoginPage
2020-08-07 10:25:07 +02:00
let playerPage: PlayerPage
2019-06-17 08:11:25 +02:00
2021-08-30 16:24:25 +02:00
let videoName = Math.random() + ' video'
const video2Name = Math.random() + ' second video'
const playlistName = Math.random() + ' playlist'
2019-06-17 08:11:25 +02:00
let videoWatchUrl: string
2018-05-19 13:58:29 +02:00
2021-08-30 16:24:25 +02:00
before(async () => {
if (isIOS()) {
console.log('iOS detected')
} else if (isMobileDevice()) {
console.log('Android detected.')
} else if (isSafari()) {
console.log('Safari detected.')
}
if (isUploadUnsupported()) return
2021-09-03 10:27:04 +02:00
await waitServerUp()
2021-08-30 16:24:25 +02:00
})
2018-05-19 13:58:29 +02:00
beforeEach(async () => {
2021-09-03 10:27:04 +02:00
videoWatchPage = new VideoWatchPage(isMobileDevice(), isSafari())
2019-06-17 08:11:25 +02:00
videoUploadPage = new VideoUploadPage()
videoUpdatePage = new VideoUpdatePage()
myAccountPage = new MyAccountPage()
2018-05-17 10:55:01 +02:00
loginPage = new LoginPage()
2020-08-07 10:25:07 +02:00
playerPage = new PlayerPage()
2021-09-03 10:27:04 +02:00
videoListPage = new VideoListPage(isMobileDevice(), isSafari())
2018-05-19 13:58:29 +02:00
2021-08-30 16:24:25 +02:00
if (!isMobileDevice()) {
await browser.maximizeWindow()
2020-05-11 09:41:39 +02:00
}
2018-05-17 10:55:01 +02:00
})
2019-06-17 08:11:25 +02:00
it('Should log in', async () => {
2021-08-30 16:24:25 +02:00
if (isMobileDevice() || isSafari()) {
2018-05-24 09:05:58 +02:00
console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
2018-05-19 13:58:29 +02:00
return
}
2018-05-17 10:55:01 +02:00
return loginPage.loginAsRootUser()
})
it('Should upload a video', async () => {
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2018-05-19 13:58:29 +02:00
2019-06-17 08:11:25 +02:00
await videoUploadPage.navigateTo()
2018-05-17 10:55:01 +02:00
2019-06-17 08:11:25 +02:00
await videoUploadPage.uploadVideo()
return videoUploadPage.validSecondUploadStep(videoName)
2018-05-17 10:55:01 +02:00
})
2019-05-14 13:59:10 +02:00
it('Should list videos', async () => {
2021-09-03 10:27:04 +02:00
await videoListPage.goOnVideosList()
2018-05-19 13:58:29 +02:00
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2018-05-17 10:55:01 +02:00
2021-09-03 10:27:04 +02:00
const videoNames = await videoListPage.getVideosListName()
2018-05-17 10:55:01 +02:00
expect(videoNames).toContain(videoName)
})
it('Should go on video watch page', async () => {
2018-05-19 13:58:29 +02:00
let videoNameToExcept = videoName
2021-08-30 16:24:25 +02:00
if (isMobileDevice() || isSafari()) {
2021-09-02 08:57:59 +02:00
await go(FIXTURE_URLS.WEBTORRENT_VIDEO)
2020-08-07 14:03:46 +02:00
videoNameToExcept = 'E2E tests'
} else {
2021-09-03 10:27:04 +02:00
await videoListPage.clickOnVideo(videoName)
2020-08-07 14:03:46 +02:00
}
2018-05-17 10:55:01 +02:00
2021-09-03 10:27:04 +02:00
return videoWatchPage.waitWatchVideoName(videoNameToExcept)
2018-05-17 10:55:01 +02:00
})
it('Should play the video', async () => {
2021-08-30 16:24:25 +02:00
videoWatchUrl = await browser.getUrl()
2019-06-17 08:11:25 +02:00
2021-09-02 08:57:59 +02:00
await playerPage.playAndPauseVideo(true, 2)
2021-08-30 16:24:25 +02:00
expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
2018-05-22 16:02:29 +02:00
})
it('Should watch the associated embed video', async () => {
await videoWatchPage.goOnAssociatedEmbed()
2021-09-02 08:57:59 +02:00
await playerPage.playAndPauseVideo(false, 2)
2021-08-30 16:24:25 +02:00
expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
2019-02-21 11:24:07 +01:00
})
it('Should watch the p2p media loader embed video', async () => {
await videoWatchPage.goOnP2PMediaLoaderEmbed()
2021-09-02 08:57:59 +02:00
await playerPage.playAndPauseVideo(false, 2)
2021-08-30 16:24:25 +02:00
expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
2018-05-17 10:55:01 +02:00
})
2019-06-17 08:11:25 +02:00
it('Should update the video', async () => {
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2019-06-17 08:11:25 +02:00
2021-08-30 16:24:25 +02:00
await go(videoWatchUrl)
2019-06-17 08:11:25 +02:00
await videoWatchPage.clickOnUpdate()
2019-06-18 10:20:55 +02:00
videoName += ' updated'
await videoUpdatePage.updateName(videoName)
2019-06-17 08:11:25 +02:00
await videoUpdatePage.validUpdate()
const name = await videoWatchPage.getVideoName()
2019-06-18 10:20:55 +02:00
expect(name).toEqual(videoName)
2019-06-17 08:11:25 +02:00
})
it('Should add the video in my playlist', async () => {
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2019-06-17 08:11:25 +02:00
await videoWatchPage.clickOnSave()
2019-06-18 10:20:55 +02:00
await videoWatchPage.createPlaylist(playlistName)
await videoWatchPage.saveToPlaylist(playlistName)
2021-08-30 16:24:25 +02:00
await browser.pause(5000)
2019-06-17 08:11:25 +02:00
await videoUploadPage.navigateTo()
await videoUploadPage.uploadVideo()
2019-06-18 10:20:55 +02:00
await videoUploadPage.validSecondUploadStep(video2Name)
2019-06-17 08:11:25 +02:00
await videoWatchPage.clickOnSave()
2019-06-18 10:20:55 +02:00
await videoWatchPage.saveToPlaylist(playlistName)
2019-06-17 08:11:25 +02:00
})
2019-06-18 10:20:55 +02:00
it('Should have the playlist in my account', async () => {
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2019-06-17 08:11:25 +02:00
await myAccountPage.navigateToMyPlaylists()
2019-06-18 10:20:55 +02:00
const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
2019-06-17 08:11:25 +02:00
expect(videosNumberText).toEqual('2 videos')
2019-06-18 10:20:55 +02:00
await myAccountPage.clickOnPlaylist(playlistName)
2019-06-17 08:11:25 +02:00
const count = await myAccountPage.countTotalPlaylistElements()
expect(count).toEqual(2)
})
it('Should watch the playlist', async () => {
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2019-06-17 08:11:25 +02:00
await myAccountPage.playPlaylist()
2021-08-30 16:24:25 +02:00
await videoWatchPage.waitUntilVideoName(video2Name, 30 * 1000)
2019-06-17 08:11:25 +02:00
})
2020-08-07 08:47:10 +02:00
it('Should watch the webtorrent playlist in the embed', async () => {
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2020-08-07 10:25:07 +02:00
2021-08-30 16:24:25 +02:00
const accessToken = await browser.execute(`return window.localStorage.getItem('access_token');`)
const refreshToken = await browser.execute(`return window.localStorage.getItem('refresh_token');`)
2020-08-07 08:47:10 +02:00
await myAccountPage.goOnAssociatedPlaylistEmbed()
2020-11-30 09:11:12 +01:00
await playerPage.waitUntilPlayerWrapper()
2020-12-15 11:45:29 +01:00
console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)
2021-08-30 16:24:25 +02:00
await browser.execute(`window.localStorage.setItem('access_token', '${accessToken}');`)
await browser.execute(`window.localStorage.setItem('refresh_token', '${refreshToken}');`)
await browser.execute(`window.localStorage.setItem('token_type', 'Bearer');`)
2020-08-07 08:47:10 +02:00
2020-08-07 10:25:07 +02:00
await browser.refresh()
await playerPage.playVideo()
2021-08-30 16:24:25 +02:00
await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
2020-08-07 10:25:07 +02:00
})
it('Should watch the HLS playlist in the embed', async () => {
await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()
await playerPage.playVideo()
2021-08-30 16:24:25 +02:00
await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
2020-08-07 08:47:10 +02:00
})
2019-06-18 10:20:55 +02:00
it('Should delete the video 2', async () => {
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2019-06-17 08:11:25 +02:00
2020-08-07 10:25:07 +02:00
// Go to the dev website
2021-08-30 16:24:25 +02:00
await go(videoWatchUrl)
2020-08-07 10:25:07 +02:00
2019-06-17 08:11:25 +02:00
await myAccountPage.navigateToMyVideos()
2019-06-18 10:20:55 +02:00
await myAccountPage.removeVideo(video2Name)
2019-06-17 08:11:25 +02:00
await myAccountPage.validRemove()
2021-08-30 16:24:25 +02:00
await browser.waitUntil(async () => {
const count = await myAccountPage.countVideos([ videoName, video2Name ])
return count === 1
})
2019-06-17 08:11:25 +02:00
})
it('Should delete the first video', async () => {
2021-08-30 16:24:25 +02:00
if (isUploadUnsupported()) return
2019-06-17 08:11:25 +02:00
2019-06-18 10:20:55 +02:00
await myAccountPage.removeVideo(videoName)
2019-06-17 08:11:25 +02:00
await myAccountPage.validRemove()
})
2018-05-17 10:55:01 +02:00
})