MOBILE-3216 core: Check if user agent is controlled by automation

main
Pau Ferrer Ocaña 2019-12-04 12:36:43 +01:00
parent 9686113163
commit 067c46e8c5
2 changed files with 20 additions and 1 deletions

View File

@ -101,8 +101,10 @@ export class CoreAppProvider {
}, 100); }, 100);
// Export the app provider so Behat tests can change the forceOffline flag. // Export the app provider so Behat tests can change the forceOffline flag.
if (CoreAppProvider.isAutomated()) {
(<any> window).appProvider = this; (<any> window).appProvider = this;
} }
}
/** /**
* Check if the browser supports mediaDevices.getUserMedia. * Check if the browser supports mediaDevices.getUserMedia.
@ -159,6 +161,15 @@ export class CoreAppProvider {
return this.appCtrl.getRootNavs()[0]; 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). * Checks if the app is running in a 64 bits desktop environment (not browser).
* *

View File

@ -17,6 +17,7 @@ import { TranslateService } from '@ngx-translate/core';
import * as moment from 'moment'; import * as moment from 'moment';
import { Globalization } from '@ionic-native/globalization'; import { Globalization } from '@ionic-native/globalization';
import { Platform, Config } from 'ionic-angular'; import { Platform, Config } from 'ionic-angular';
import { CoreAppProvider } from '@providers/app';
import { CoreConfigProvider } from './config'; import { CoreConfigProvider } from './config';
import { CoreConfigConstants } from '../configconstants'; import { CoreConfigConstants } from '../configconstants';
@ -39,6 +40,13 @@ export class CoreLangProvider {
translate.use(this.defaultLanguage); translate.use(this.defaultLanguage);
platform.ready().then(() => { platform.ready().then(() => {
if (CoreAppProvider.isAutomated()) {
// Force current language to English when Behat is running.
this.changeCurrentLanguage('en');
return;
}
this.getCurrentLanguage().then((language) => { this.getCurrentLanguage().then((language) => {
this.changeCurrentLanguage(language); this.changeCurrentLanguage(language);
}); });