Fix protractor with Safari

pull/586/head
Chocobozzz 2018-05-24 09:05:58 +02:00
parent 073279d5ea
commit 1fad099d72
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 36 additions and 35 deletions

View File

@ -12,7 +12,7 @@ exports.config = {
'browserstack.user': process.env.BROWSERSTACK_USER, 'browserstack.user': process.env.BROWSERSTACK_USER,
'browserstack.key': process.env.BROWSERSTACK_KEY, 'browserstack.key': process.env.BROWSERSTACK_KEY,
'browserstack.local': true, 'browserstack.local': true,
projec: 'PeerTube' project: 'PeerTube'
}, },
multiCapabilities: [ multiCapabilities: [
@ -22,8 +22,7 @@ exports.config = {
}, },
{ {
browserName: 'Safari', browserName: 'Safari',
version: '11.1', version: '11.1'
resolution: '1920x1080'
}, },
{ {
browserName: 'Firefox', browserName: 'Firefox',

View File

@ -1,11 +1,11 @@
import { by, element, browser } from 'protractor' import { by, element, browser } from 'protractor'
export class VideoWatchPage { export class VideoWatchPage {
async goOnVideosList (isIphoneDevice: boolean, isSafari: boolean) { async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
let url: string let url: string
if (isIphoneDevice === true) { // We did not upload a file on a mobile device
// Local testing is buggy :/ if (isMobileDevice === true || isSafari === true) {
url = 'https://peertube2.cpy.re/videos/local' url = 'https://peertube2.cpy.re/videos/local'
} else { } else {
url = '/videos/recently-added' url = '/videos/recently-added'
@ -26,8 +26,11 @@ export class VideoWatchPage {
.then((texts: any) => texts.map(t => t.trim())) .then((texts: any) => texts.map(t => t.trim()))
} }
waitWatchVideoName (videoName: string) { waitWatchVideoName (videoName: string, isSafari: boolean) {
const elem = element(by.css('.video-info .video-info-name')) const elem = element(by.css('.video-info .video-info-name'))
if (isSafari) return browser.sleep(5000)
return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName)) return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName))
} }
@ -38,27 +41,27 @@ export class VideoWatchPage {
.then(seconds => parseInt(seconds, 10)) .then(seconds => parseInt(seconds, 10))
} }
async pauseVideo (pauseAfterMs: number, isAutoplay: boolean, isSafari: boolean) { async pauseVideo (isAutoplay: boolean, isDesktopSafari: boolean) {
if (isAutoplay === false) { if (isAutoplay === false) {
const playButton = element(by.css('.vjs-big-play-button')) const playButton = element(by.css('.vjs-big-play-button'))
await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton)) await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
await playButton.click() await playButton.click()
} }
if (isSafari === true) { // if (isDesktopSafari === true) {
await browser.sleep(1000) // await browser.sleep(1000)
await element(by.css('.vjs-play-control')).click() // await element(by.css('.vjs-play-control')).click()
} // }
await browser.sleep(1000) await browser.sleep(1000)
await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner')))) await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
const el = element(by.css('div.video-js')) const videojsEl = element(by.css('div.video-js'))
await browser.wait(browser.ExpectedConditions.elementToBeClickable(el)) await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
await browser.sleep(pauseAfterMs) await browser.sleep(7000)
return el.click() return videojsEl.click()
} }
async clickOnVideo (videoName: string) { async clickOnVideo (videoName: string) {
@ -70,10 +73,13 @@ export class VideoWatchPage {
} }
async clickOnFirstVideo () { async clickOnFirstVideo () {
const video = element.all(by.css('.videos .video-miniature .video-miniature-name')).first() const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
await browser.wait(browser.ExpectedConditions.elementToBeClickable(video)) const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
const textToReturn = video.getText()
// Don't know why but the expectation fails on Safari
await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
const textToReturn = videoName.getText()
await video.click() await video.click()
await browser.wait(browser.ExpectedConditions.urlContains('/watch/')) await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))

View File

@ -9,7 +9,6 @@ describe('Videos workflow', () => {
let loginPage: LoginPage let loginPage: LoginPage
const videoName = new Date().getTime() + ' video' const videoName = new Date().getTime() + ' video'
let isMobileDevice = false let isMobileDevice = false
let isIphoneDevice = false
let isSafari = false let isSafari = false
beforeEach(async () => { beforeEach(async () => {
@ -21,13 +20,12 @@ describe('Videos workflow', () => {
const caps = await browser.getCapabilities() const caps = await browser.getCapabilities()
isMobileDevice = caps.get('realMobile') === 'true' || caps.get('realMobile') === true isMobileDevice = caps.get('realMobile') === 'true' || caps.get('realMobile') === true
isIphoneDevice = caps.get('device') === 'iphone'
isSafari = caps.get('browserName') && caps.get('browserName').toLowerCase() === 'safari' isSafari = caps.get('browserName') && caps.get('browserName').toLowerCase() === 'safari'
}) })
it('Should log in', () => { it('Should log in', () => {
if (isMobileDevice) { if (isMobileDevice || isSafari) {
console.log('Skipping because we are on a real device and BrowserStack does not support file upload.') console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
return return
} }
@ -35,8 +33,8 @@ describe('Videos workflow', () => {
}) })
it('Should upload a video', async () => { it('Should upload a video', async () => {
if (isMobileDevice) { if (isMobileDevice || isSafari) {
console.log('Skipping because we are on a real device and BrowserStack does not support file upload.') console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
return return
} }
@ -47,10 +45,10 @@ describe('Videos workflow', () => {
}) })
it('Should list the video', async () => { it('Should list the video', async () => {
await videoWatchPage.goOnVideosList(isIphoneDevice, isSafari) await videoWatchPage.goOnVideosList(isMobileDevice, isSafari)
if (isMobileDevice) { if (isMobileDevice || isSafari) {
console.log('Skipping because we are on a real device and BrowserStack does not support file upload.') console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
return return
} }
@ -61,21 +59,21 @@ describe('Videos workflow', () => {
it('Should go on video watch page', async () => { it('Should go on video watch page', async () => {
let videoNameToExcept = videoName let videoNameToExcept = videoName
if (isMobileDevice) videoNameToExcept = await videoWatchPage.clickOnFirstVideo() if (isMobileDevice || isSafari) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
else await videoWatchPage.clickOnVideo(videoName) else await videoWatchPage.clickOnVideo(videoName)
return videoWatchPage.waitWatchVideoName(videoNameToExcept) return videoWatchPage.waitWatchVideoName(videoNameToExcept, isSafari)
}) })
it('Should play the video', async () => { it('Should play the video', async () => {
await videoWatchPage.pauseVideo(7000, !isMobileDevice, isSafari) await videoWatchPage.pauseVideo(!isMobileDevice, isSafari && isMobileDevice === false)
expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2) expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
}) })
it('Should watch the associated embed video', async () => { it('Should watch the associated embed video', async () => {
await videoWatchPage.goOnAssociatedEmbed() await videoWatchPage.goOnAssociatedEmbed()
await videoWatchPage.pauseVideo(7000, false, isSafari) await videoWatchPage.pauseVideo(false, isSafari && isMobileDevice === false)
expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2) expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
}) })
}) })

View File

@ -270,6 +270,7 @@ class PeerTubePlugin extends Plugin {
private tryToPlay (done?: Function) { private tryToPlay (done?: Function) {
if (!done) done = function () { /* empty */ } if (!done) done = function () { /* empty */ }
const playPromise = this.player.play() const playPromise = this.player.play()
if (playPromise !== undefined) { if (playPromise !== undefined) {
return playPromise.then(done) return playPromise.then(done)
@ -355,9 +356,6 @@ class PeerTubePlugin extends Plugin {
// Proxy first play // Proxy first play
const oldPlay = this.player.play.bind(this.player) const oldPlay = this.player.play.bind(this.player)
this.player.play = () => { this.player.play = () => {
// Avoid issue new play policy on mobiles
if (isMobile()) oldPlay()
this.player.addClass('vjs-has-big-play-button-clicked') this.player.addClass('vjs-has-big-play-button-clicked')
this.player.play = oldPlay this.player.play = oldPlay