]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix protractor with Safari
authorChocobozzz <me@florianbigard.com>
Thu, 24 May 2018 07:05:58 +0000 (09:05 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 24 May 2018 07:16:15 +0000 (09:16 +0200)
client/e2e/protractor.conf.js
client/e2e/src/po/video-watch.po.ts
client/e2e/src/videos.e2e-spec.ts
client/src/assets/player/peertube-videojs-plugin.ts

index 5dcd7728427af0240645e9157020a9329f3356aa..60b0ad9044732e87fa6d0a206a71d43fc5ec1557 100644 (file)
@@ -12,7 +12,7 @@ exports.config = {
     'browserstack.user': process.env.BROWSERSTACK_USER,
     'browserstack.key': process.env.BROWSERSTACK_KEY,
     'browserstack.local': true,
-    projec: 'PeerTube'
+    project: 'PeerTube'
   },
 
   multiCapabilities: [
@@ -22,8 +22,7 @@ exports.config = {
     },
     {
       browserName: 'Safari',
-      version: '11.1',
-      resolution: '1920x1080'
+      version: '11.1'
     },
     {
       browserName: 'Firefox',
index 19d02ff51b422f16f7331e2bf41f85d46b88e402..ec3d16c3b2b2b309aee36beccc3c5c6afd8d8187 100644 (file)
@@ -1,11 +1,11 @@
 import { by, element, browser } from 'protractor'
 
 export class VideoWatchPage {
-  async goOnVideosList (isIphoneDevice: boolean, isSafari: boolean) {
+  async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
     let url: string
 
-    if (isIphoneDevice === true) {
-      // Local testing is buggy :/
+    // We did not upload a file on a mobile device
+    if (isMobileDevice === true || isSafari === true) {
       url = 'https://peertube2.cpy.re/videos/local'
     } else {
       url = '/videos/recently-added'
@@ -26,8 +26,11 @@ export class VideoWatchPage {
                   .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'))
+
+    if (isSafari) return browser.sleep(5000)
+
     return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName))
   }
 
@@ -38,27 +41,27 @@ export class VideoWatchPage {
       .then(seconds => parseInt(seconds, 10))
   }
 
-  async pauseVideo (pauseAfterMs: number, isAutoplay: boolean, isSafari: boolean) {
+  async pauseVideo (isAutoplay: boolean, isDesktopSafari: boolean) {
     if (isAutoplay === false) {
       const playButton = element(by.css('.vjs-big-play-button'))
       await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
       await playButton.click()
     }
 
-    if (isSafari === true) {
-      await browser.sleep(1000)
-      await element(by.css('.vjs-play-control')).click()
-    }
+    // if (isDesktopSafari === true) {
+    //   await browser.sleep(1000)
+    //   await element(by.css('.vjs-play-control')).click()
+    // }
 
     await browser.sleep(1000)
     await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
 
-    const el = element(by.css('div.video-js'))
-    await browser.wait(browser.ExpectedConditions.elementToBeClickable(el))
+    const videojsEl = element(by.css('div.video-js'))
+    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) {
@@ -70,10 +73,13 @@ export class VideoWatchPage {
   }
 
   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()
+    const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
+
+    // Don't know why but the expectation fails on Safari
     await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
-    const textToReturn = video.getText()
 
+    const textToReturn = videoName.getText()
     await video.click()
 
     await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
index f216f8dd18b4d805c91087af8ab1f31097522bbe..16fe6b70d9253b901baa21f51bb80064057c1456 100644 (file)
@@ -9,7 +9,6 @@ describe('Videos workflow', () => {
   let loginPage: LoginPage
   const videoName = new Date().getTime() + ' video'
   let isMobileDevice = false
-  let isIphoneDevice = false
   let isSafari = false
 
   beforeEach(async () => {
@@ -21,13 +20,12 @@ describe('Videos workflow', () => {
 
     const caps = await browser.getCapabilities()
     isMobileDevice = caps.get('realMobile') === 'true' || caps.get('realMobile') === true
-    isIphoneDevice = caps.get('device') === 'iphone'
     isSafari = caps.get('browserName') && caps.get('browserName').toLowerCase() === 'safari'
   })
 
   it('Should log in', () => {
-    if (isMobileDevice) {
-      console.log('Skipping because we are on a real device and BrowserStack does not support file upload.')
+    if (isMobileDevice || isSafari) {
+      console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
       return
     }
 
@@ -35,8 +33,8 @@ describe('Videos workflow', () => {
   })
 
   it('Should upload a video', async () => {
-    if (isMobileDevice) {
-      console.log('Skipping because we are on a real device and BrowserStack does not support file upload.')
+    if (isMobileDevice || isSafari) {
+      console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
       return
     }
 
@@ -47,10 +45,10 @@ describe('Videos workflow', () => {
   })
 
   it('Should list the video', async () => {
-    await videoWatchPage.goOnVideosList(isIphoneDevice, isSafari)
+    await videoWatchPage.goOnVideosList(isMobileDevice, isSafari)
 
-    if (isMobileDevice) {
-      console.log('Skipping because we are on a real device and BrowserStack does not support file upload.')
+    if (isMobileDevice || isSafari) {
+      console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
       return
     }
 
@@ -61,21 +59,21 @@ describe('Videos workflow', () => {
   it('Should go on video watch page', async () => {
     let videoNameToExcept = videoName
 
-    if (isMobileDevice) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
+    if (isMobileDevice || isSafari) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
     else await videoWatchPage.clickOnVideo(videoName)
 
-    return videoWatchPage.waitWatchVideoName(videoNameToExcept)
+    return videoWatchPage.waitWatchVideoName(videoNameToExcept, isSafari)
   })
 
   it('Should play the video', async () => {
-    await videoWatchPage.pauseVideo(7000, !isMobileDevice, isSafari)
+    await videoWatchPage.pauseVideo(!isMobileDevice, isSafari && isMobileDevice === false)
     expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
   })
 
   it('Should watch the associated embed video', async () => {
     await videoWatchPage.goOnAssociatedEmbed()
 
-    await videoWatchPage.pauseVideo(7000, false, isSafari)
+    await videoWatchPage.pauseVideo(false, isSafari && isMobileDevice === false)
     expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
   })
 })
index 1e68100d1ddd325ba89f2b2516aff556c062a804..d9ded7a7ed0979eb9084e0362849b61967f3cd04 100644 (file)
@@ -270,6 +270,7 @@ class PeerTubePlugin extends Plugin {
 
   private tryToPlay (done?: Function) {
     if (!done) done = function () { /* empty */ }
+
     const playPromise = this.player.play()
     if (playPromise !== undefined) {
       return playPromise.then(done)
@@ -355,9 +356,6 @@ class PeerTubePlugin extends Plugin {
       // Proxy first play
       const oldPlay = this.player.play.bind(this.player)
       this.player.play = () => {
-        // Avoid issue new play policy on mobiles
-        if (isMobile()) oldPlay()
-
         this.player.addClass('vjs-has-big-play-button-clicked')
         this.player.play = oldPlay