mirror of
https://github.com/appium/appium.git
synced 2026-02-07 01:58:55 -06:00
Merge pull request #2529 from penguinho/android-language
Adding language and country support to Android
This commit is contained in:
@@ -49,8 +49,8 @@ All flags are optional, but some are required in conjunction with certain others
|
||||
|`--default-device`, `-dd`|false|(IOS-Simulator-only) use the default simulator that instruments launches on its own||
|
||||
|`--force-iphone`|false|(IOS-only) Use the iPhone Simulator no matter what the app wants||
|
||||
|`--force-ipad`|false|(IOS-only) Use the iPad Simulator no matter what the app wants||
|
||||
|`--language`|null|(IOS-only) language for the iOS simulator|`--language en`|
|
||||
|`--locale`|null|(IOS-only) locale for the iOS simulator|`--locale en_US`|
|
||||
|`--language`|null|language for the iOS simulator or Android Device|`--language en`|
|
||||
|`--locale`|null|locale for the iOS simulator or Android Device|`--locale en_US`|
|
||||
|`--calendar-format`|null|(IOS-only) calendar format for the iOS simulator|`--calendar-format gregorian`|
|
||||
|`--orientation`|null|(IOS-only) use LANDSCAPE or PORTRAIT to initialize all requests to this orientation|`--orientation LANDSCAPE`|
|
||||
|`--tracetemplate`|null|(IOS-only) .tracetemplate file to use with Instruments|`--tracetemplate /Users/me/Automation.tracetemplate`|
|
||||
|
||||
@@ -738,7 +738,7 @@ ADB.prototype.killAllEmulators = function (cb) {
|
||||
});
|
||||
};
|
||||
|
||||
ADB.prototype.launchAVD = function (avdName, avdArgs, avdLaunchTimeout,
|
||||
ADB.prototype.launchAVD = function (avdName, avdArgs, language, locale, avdLaunchTimeout,
|
||||
avdReadyTimeout, cb, retry) {
|
||||
if (typeof retry === "undefined") {
|
||||
retry = 0;
|
||||
@@ -749,18 +749,24 @@ ADB.prototype.launchAVD = function (avdName, avdArgs, avdLaunchTimeout,
|
||||
this.checkSdkBinaryPresent("emulator", function (err, emulatorBinaryPath) {
|
||||
if (err) return cb(err);
|
||||
|
||||
if (avdName[0] !== "@") {
|
||||
avdName = "@" + avdName;
|
||||
if (avdName[0] === "@") {
|
||||
avdName = avdName.substr(1);
|
||||
}
|
||||
|
||||
if (avdArgs === null) {
|
||||
avdArgs = [avdName];
|
||||
} else if (typeof avdArgs === "string") {
|
||||
avdArgs = avdArgs.split(" ");
|
||||
avdArgs.unshift(avdName);
|
||||
var launchArgs = ["-avd", avdName];
|
||||
if (typeof language === "string") {
|
||||
logger.info("Setting Android Device Language to " + language);
|
||||
launchArgs.push("-prop", "persist.sys.language=" + language.toLowerCase());
|
||||
}
|
||||
var proc = spawn(emulatorBinaryPath.substr(1, emulatorBinaryPath.length - 2),
|
||||
avdArgs);
|
||||
if (typeof locale === "string") {
|
||||
logger.info("Setting Android Device Country to " + locale);
|
||||
launchArgs.push("-prop", "persist.sys.country=" + locale.toUpperCase());
|
||||
}
|
||||
if (typeof avdArgs === "string") {
|
||||
avdArgs = avdArgs.split(" ");
|
||||
launchArgs = launchArgs.concat(avdArgs);
|
||||
}
|
||||
var proc = spawn(emulatorBinaryPath, launchArgs);
|
||||
proc.on("error", function (err) {
|
||||
logger.error("Unable to start Emulator: " + err.message);
|
||||
// actual error will get caught by getRunningAVDWithRetry
|
||||
@@ -779,7 +785,7 @@ ADB.prototype.launchAVD = function (avdName, avdArgs, avdLaunchTimeout,
|
||||
if (retry < 1) {
|
||||
logger.warn("Emulator never became active. Going to retry once");
|
||||
proc.kill();
|
||||
return this.launchAVD(avdName, avdArgs, avdLaunchTimeout,
|
||||
return this.launchAVD(avdName, avdArgs, language, locale, avdLaunchTimeout,
|
||||
avdReadyTimeout, cb, retry + 1);
|
||||
} else {
|
||||
return cb(err);
|
||||
|
||||
@@ -75,7 +75,7 @@ androidCommon.setAndroidArgs = function () {
|
||||
this.setArgFromCap("androidWaitPackage", "appWaitPackage");
|
||||
this.setArgFromCap("androidWaitActivity", "appWaitActivity");
|
||||
this.setArgFromCap("androidDeviceReadyTimeout", "deviceReadyTimeout");
|
||||
this.setArgFromCap("androidCoverage", "androidCoverage");
|
||||
|
||||
// must be enabled by default or XPath will be broken on API >= 18
|
||||
// compressXml is not available on API <= 17
|
||||
this.args.compressXml = true;
|
||||
@@ -310,9 +310,21 @@ androidCommon.prepareEmulator = function (cb) {
|
||||
logger.info("Did not launch AVD because it was already running.");
|
||||
return cb();
|
||||
}
|
||||
this.adb.launchAVD(this.args.avd, this.args.avdArgs,
|
||||
this.adb.launchAVD(this.args.avd, this.args.avdArgs, this.args.language, this.args.locale,
|
||||
this.args.avdLaunchTimeout, this.args.avdReadyTimeout, cb);
|
||||
}.bind(this));
|
||||
} else if (typeof this.args.language === "string" || typeof this.args.locale === "string") {
|
||||
var adbCmd = "";
|
||||
if (this.args.language && typeof this.args.language === "string") {
|
||||
logger.info("Setting Android Device Language to " + this.args.language);
|
||||
adbCmd += "setprop persist.sys.language " +this.args.language.toLowerCase() + ";";
|
||||
}
|
||||
if (this.args.locale && typeof this.args.locale === "string") {
|
||||
logger.info("Setting Android Device Country to " + this.args.locale);
|
||||
adbCmd += "setprop persist.sys.country " +this.args.locale.toUpperCase() + ";";
|
||||
}
|
||||
adbCmd += " stop; sleep 5; start";
|
||||
this.adb.shell(adbCmd, cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ Android.prototype.init = function () {
|
||||
this.args.devicePort = 4724;
|
||||
this.appMd5Hash = null;
|
||||
this.args.avd = null;
|
||||
this.args.language = null;
|
||||
this.args.locale = null;
|
||||
this.initQueue();
|
||||
this.implicitWaitMs = 0;
|
||||
this.shuttingDown = false;
|
||||
|
||||
Reference in New Issue
Block a user