From 067c46e8c55d0c277e0beaa554243eb6eaab521c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 4 Dec 2019 12:36:43 +0100 Subject: [PATCH] MOBILE-3216 core: Check if user agent is controlled by automation --- src/providers/app.ts | 13 ++++++++++++- src/providers/lang.ts | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/providers/app.ts b/src/providers/app.ts index 4129fe48e..7aa6a6a70 100644 --- a/src/providers/app.ts +++ b/src/providers/app.ts @@ -101,7 +101,9 @@ export class CoreAppProvider { }, 100); // Export the app provider so Behat tests can change the forceOffline flag. - ( window).appProvider = this; + if (CoreAppProvider.isAutomated()) { + ( window).appProvider = this; + } } /** @@ -159,6 +161,15 @@ export class CoreAppProvider { return this.appCtrl.getRootNavs()[0]; } + /** + * Returns whether the user agent is controlled by automation. I.e. Behat testing. + * + * @return {boolean} True if the user agent is controlled by automation, false otherwise. + */ + static isAutomated(): boolean { + return !!navigator.webdriver; + } + /** * Checks if the app is running in a 64 bits desktop environment (not browser). * diff --git a/src/providers/lang.ts b/src/providers/lang.ts index 14c478d9b..df16004e3 100644 --- a/src/providers/lang.ts +++ b/src/providers/lang.ts @@ -17,6 +17,7 @@ import { TranslateService } from '@ngx-translate/core'; import * as moment from 'moment'; import { Globalization } from '@ionic-native/globalization'; import { Platform, Config } from 'ionic-angular'; +import { CoreAppProvider } from '@providers/app'; import { CoreConfigProvider } from './config'; import { CoreConfigConstants } from '../configconstants'; @@ -39,6 +40,13 @@ export class CoreLangProvider { translate.use(this.defaultLanguage); platform.ready().then(() => { + if (CoreAppProvider.isAutomated()) { + // Force current language to English when Behat is running. + this.changeCurrentLanguage('en'); + + return; + } + this.getCurrentLanguage().then((language) => { this.changeCurrentLanguage(language); });