From e29221f855a7135bcfb45720e3600c7401939abb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 13 Jul 2023 15:49:47 +0200 Subject: [PATCH] Fix e2e tests --- client/e2e/src/po/login.po.ts | 14 ++++++-- client/e2e/src/po/player.po.ts | 27 ++++++++------- client/e2e/src/utils/common.ts | 7 ++++ client/e2e/tsconfig.json | 4 +++ client/e2e/wdio.browserstack.conf.ts | 34 +++++++++++++------ .../player/shared/peertube/peertube-plugin.ts | 3 +- 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/client/e2e/src/po/login.po.ts b/client/e2e/src/po/login.po.ts index e2362ef51..a8606dbd2 100644 --- a/client/e2e/src/po/login.po.ts +++ b/client/e2e/src/po/login.po.ts @@ -1,4 +1,4 @@ -import { go } from '../utils' +import { browserSleep, go, isAndroid, isMobileDevice } from '../utils' export class LoginPage { @@ -23,9 +23,17 @@ export class LoginPage { await $('input#username').setValue(username) await $('input#password').setValue(password) - await browser.pause(1000) + await browserSleep(1000) - await $('form input[type=submit]').click() + const submit = $('.login-form-and-externals > form input[type=submit]') + await submit.click() + + // Have to do this on Android, don't really know why + // I think we need to "escape" from the password input, so click twice on the submit button + if (isAndroid()) { + await browserSleep(2000) + await submit.click() + } if (this.isMobileDevice) { const menuToggle = $('.top-left-block span[role=button]') diff --git a/client/e2e/src/po/player.po.ts b/client/e2e/src/po/player.po.ts index 33719da25..e41422359 100644 --- a/client/e2e/src/po/player.po.ts +++ b/client/e2e/src/po/player.po.ts @@ -29,29 +29,32 @@ export class PlayerPage { } async playAndPauseVideo (isAutoplay: boolean, waitUntilSec: number) { - const videojsElem = () => $('div.video-js') - - await videojsElem().waitForExist() - - // Autoplay is disabled on iOS and Safari - if (isIOS() || isSafari() || isMobileDevice()) { - // We can't play the video if it is not muted - await browser.execute(`document.querySelector('video').muted = true`) - await this.clickOnPlayButton() - } else if (isAutoplay === false) { - await this.clickOnPlayButton() + // Autoplay is disabled on mobile and Safari + if (isIOS() || isSafari() || isMobileDevice() || isAutoplay === false) { + await this.playVideo() } + await $('div.video-js.vjs-has-started').waitForExist() + await browserSleep(2000) await browser.waitUntil(async () => { return (await this.getWatchVideoPlayerCurrentTime()) >= waitUntilSec }) - await videojsElem().click() + // Pause video + await $('div.video-js').click() } async playVideo () { + await $('div.video-js.vjs-paused').waitForExist() + + // Autoplay is disabled on iOS and Safari + if (isIOS() || isSafari() || isMobileDevice()) { + // We can't play the video if it is not muted + await browser.execute(`document.querySelector('video').muted = true`) + } + return this.clickOnPlayButton() } diff --git a/client/e2e/src/utils/common.ts b/client/e2e/src/utils/common.ts index eb5f6b450..b04fe47f3 100644 --- a/client/e2e/src/utils/common.ts +++ b/client/e2e/src/utils/common.ts @@ -8,6 +8,12 @@ function isMobileDevice () { return platformName === 'android' || platformName === 'ios' } +function isAndroid () { + const platformName = (browser.capabilities['platformName'] || '').toLowerCase() + + return platformName === 'android' +} + function isSafari () { return browser.capabilities['browserName'] && browser.capabilities['browserName'].toLowerCase() === 'safari' @@ -41,6 +47,7 @@ export { isMobileDevice, isSafari, isIOS, + isAndroid, waitServerUp, go, browserSleep diff --git a/client/e2e/tsconfig.json b/client/e2e/tsconfig.json index c62ffa931..1291601c9 100644 --- a/client/e2e/tsconfig.json +++ b/client/e2e/tsconfig.json @@ -6,6 +6,10 @@ "esModuleInterop": true, "module": "commonjs", "target": "es5", + "typeRoots": [ + "../node_modules/@types", + "../node_modules" + ], "types": [ "node", "@wdio/globals/types", diff --git a/client/e2e/wdio.browserstack.conf.ts b/client/e2e/wdio.browserstack.conf.ts index 0d68c8541..ecab74078 100644 --- a/client/e2e/wdio.browserstack.conf.ts +++ b/client/e2e/wdio.browserstack.conf.ts @@ -17,18 +17,32 @@ function buildMainOptions (sessionName: string) { } } -function buildBStackDesktopOptions (sessionName: string, resolution: string, os?: string) { +function buildBStackDesktopOptions (options: { + sessionName: string + resolution: string + os?: string + osVersion?: string +}) { + const { sessionName, resolution, os, osVersion } = options + return { 'bstack:options': { ...buildMainOptions(sessionName), os, + osVersion, resolution } } } -function buildBStackMobileOptions (sessionName: string, deviceName: string, osVersion: string) { +function buildBStackMobileOptions (options: { + sessionName: string + deviceName: string + osVersion: string +}) { + const { sessionName, deviceName, osVersion } = options + return { 'bstack:options': { ...buildMainOptions(sessionName), @@ -53,45 +67,45 @@ module.exports = { { browserName: 'Chrome', - ...buildBStackDesktopOptions('Latest Chrome Desktop', '1280x1024') + ...buildBStackDesktopOptions({ sessionName: 'Latest Chrome Desktop', resolution: '1280x1024', os: 'Windows', osVersion: '8' }) }, { browserName: 'Firefox', browserVersion: '78', // Very old ESR - ...buildBStackDesktopOptions('Firefox ESR Desktop', '1280x1024', 'Windows') + ...buildBStackDesktopOptions({ sessionName: 'Firefox ESR Desktop', resolution: '1280x1024', os: 'Windows', osVersion: '8' }) }, { browserName: 'Safari', browserVersion: '12.1', - ...buildBStackDesktopOptions('Safari Desktop', '1280x1024') + ...buildBStackDesktopOptions({ sessionName: 'Safari Desktop', resolution: '1280x1024' }) }, { browserName: 'Firefox', - ...buildBStackDesktopOptions('Firefox Latest', '1280x1024') + ...buildBStackDesktopOptions({ sessionName: 'Firefox Latest', resolution: '1280x1024', os: 'Windows', osVersion: '8' }) }, { browserName: 'Edge', - ...buildBStackDesktopOptions('Edge Latest', '1280x1024') + ...buildBStackDesktopOptions({ sessionName: 'Edge Latest', resolution: '1280x1024' }) }, { browserName: 'Chrome', - ...buildBStackMobileOptions('Latest Chrome Android', 'Samsung Galaxy S8', '7.0') + ...buildBStackMobileOptions({ sessionName: 'Latest Chrome Android', deviceName: 'Samsung Galaxy S8', osVersion: '7.0' }) }, { browserName: 'Safari', - ...buildBStackMobileOptions('Safari iPhone', 'iPhone 8 Plus', '12.4') + ...buildBStackMobileOptions({ sessionName: 'Safari iPhone', deviceName: 'iPhone 8 Plus', osVersion: '12.4' }) }, { browserName: 'Safari', - ...buildBStackMobileOptions('Safari iPad', 'iPad 7th', '13') + ...buildBStackMobileOptions({ sessionName: 'Safari iPad', deviceName: 'iPad 7th', osVersion: '13' }) } ], diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts index 7e5a3ebb6..c405e37e0 100644 --- a/client/src/assets/player/shared/peertube/peertube-plugin.ts +++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts @@ -315,7 +315,8 @@ class PeerTubePlugin extends Plugin { } private initCaptions () { - debugLogger('Init captions with current subtitle ' + this.currentSubtitle) + if (this.currentSubtitle) debugLogger('Init captions with current subtitle ' + this.currentSubtitle) + else debugLogger('Init captions without current subtitle') this.player.tech(true).clearTracks('text')