Skip to content

Commit

Permalink
add avdLaunchTimeout/avdReadyTimeout (fix #2247)
Browse files Browse the repository at this point in the history
and retry launching emulator once if it doesn't connect (fix #1820)
  • Loading branch information
jlipps committed Apr 4, 2014
1 parent 4c1c9e1 commit 5147cbd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
2 changes: 2 additions & 0 deletions docs/caps.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Appium server capabilities
|`compressXml`| [setCompressedLayoutHeirarchy(true)](http://developer.android.com/tools/help/uiautomator/UiDevice.html#setCompressedLayoutHeirarchy%28boolean%29)| `true`|
|`androidCoverage`| Fully qualified instrumentation class. Passed to -w in adb shell am instrument -e coverage true -w | `com.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation`|
|`enablePerformanceLogging`| (Chrome and webview only) Enable Chromedriver's performance logging (default `false`)| `true`, `false`|
|`avdLaunchTimeout`| How long to wait in milliseconds for an avd to launch and connect to ADB (default `120000`)| `300000`|
|`avdReadyTimeout`| How long to wait in milliseconds for an avd to finish its boot animations (default `120000`)| `300000`|

--

Expand Down
28 changes: 22 additions & 6 deletions lib/devices/android/adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,14 @@ ADB.prototype.killAllEmulators = function (cb) {
});
};

ADB.prototype.launchAVD = function (avdName, avdArgs, cb) {
logger.info("Launching Emulator with AVD " + avdName);
ADB.prototype.launchAVD = function (avdName, avdArgs, avdLaunchTimeout,
avdReadyTimeout, cb, retry) {
if (typeof retry === "undefined") {
retry = 0;
}
logger.info("Launching Emulator with AVD " + avdName + ", launchTimeout " +
avdLaunchTimeout + "ms and readyTimeout " + avdReadyTimeout +
"ms");
this.checkSdkBinaryPresent("emulator", function (err, emulatorBinaryPath) {
if (err) return cb(err);

Expand All @@ -749,7 +755,7 @@ ADB.prototype.launchAVD = function (avdName, avdArgs, cb) {

if (avdArgs === null) {
avdArgs = [avdName];
} else {
} else if (typeof avdArgs === "string") {
avdArgs = [avdName, avdArgs];
}
var proc = spawn(emulatorBinaryPath.substr(1, emulatorBinaryPath.length - 2),
Expand All @@ -766,9 +772,19 @@ ADB.prototype.launchAVD = function (avdName, avdArgs, cb) {
logger.error("Unable to start Emulator: " + data);
}
});
this.getRunningAVDWithRetry(avdName.replace('@', ''), 120000, function (err) {
if (err) return cb(err);
this.waitForEmulatorReady(120000, cb);
this.getRunningAVDWithRetry(avdName.replace('@', ''), avdLaunchTimeout,
function (err) {
if (err) {
if (retry < 1) {
logger.warn("Emulator never became active. Going to retry once");
proc.kill();
return this.launchAVD(avdName, avdArgs, avdLaunchTimeout,
avdReadyTimeout, cb, retry + 1);
} else {
return cb(err);
}
}
this.waitForEmulatorReady(avdReadyTimeout, cb);
}.bind(this));
}.bind(this));
};
Expand Down
28 changes: 17 additions & 11 deletions lib/devices/android/android-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,25 @@ androidCommon.configure = function (args, caps, cb) {
this._deviceConfigure(args, caps);
this.setAndroidArgs();
if (!this.args.androidActivity) {
logger.info("No app-activity desired capability or server param. Parsing from apk.");
logger.info("No app-activity desired capability or server param. " +
"Parsing from apk.");
}
if (!this.args.androidPackage) {
logger.info("No app-package desired capability or server param. Parsing from apk.");
logger.info("No app-package desired capability or server param. " +
"Parsing from apk.");
}

if (this.args.app) {
this.configureApp(cb);
} else if (this.args.androidPackage) {
this.args.app = null;
logger.info("Didn't get app but did get Android package, will attempt to " +
"launch it on the device");
logger.info("Didn't get app but did get Android package, will attempt " +
"to launch it on the device");
cb(null);
} else {
var msg = "No app set; either start appium with --app or pass in an 'app' " +
"value in desired capabilities, or set androidPackage to launch pre-" +
"existing app on device";
var msg = "No app set; either start appium with --app or pass in an " +
"'app' value in desired capabilities, or set androidPackage " +
"to launch pre-existing app on device";
logger.error(msg);
cb(new Error(msg));
}
Expand All @@ -48,9 +50,10 @@ androidCommon.configureApp = function (cb) {
var _cb = cb;
cb = function (err) {
if (err) {
err = new Error("Bad app: " + this.args.app + ". App paths need to be absolute, " +
" relative to the appium server install dir, URL to compressed file, " +
"or special app name. cause: " + err);
err = new Error("Bad app: " + this.args.app + ". App paths need to be " +
"absolute, or relative to the appium server install " +
"dir, or a URL to compressed file, or a special app " +
"name. cause: " + err);
}
_cb(err);
};
Expand Down Expand Up @@ -83,6 +86,8 @@ androidCommon.setAndroidArgs = function () {
this.args.appActivity;
this.appProcess = this.args.appPackage;
this.args.appDeviceReadyTimeout = this.args.androidDeviceReadyTimeout;
this.args.avdLaunchTimeout = this.args.avdLaunchTimeout || 120000;
this.args.avdReadyTimeout = this.args.avdReadyTimeout || 120000;
};

androidCommon.background = function (secs, cb) {
Expand Down Expand Up @@ -302,7 +307,8 @@ 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, cb);
this.adb.launchAVD(this.args.avd, this.args.avdArgs,
this.args.avdLaunchTimeout, this.args.avdReadyTimeout, cb);
}.bind(this));
} else {
cb();
Expand Down

0 comments on commit 5147cbd

Please sign in to comment.