fix pre-launch bug (fix #1772)

and add tests
This commit is contained in:
Jonathan Lipps
2014-01-20 12:43:30 -08:00
parent e1961db0cf
commit dba5e7393b
2 changed files with 72 additions and 2 deletions
+19 -2
View File
@@ -122,6 +122,19 @@ Appium.prototype.getDeviceType = function(desiredCaps) {
throw new Error(errMsg);
};
Appium.prototype.getDeviceTypeFromApp = function(app) {
if (this.args.ipa) {
return "ios";
} else if (this.args.androidPackage || this.args.avd) {
return "android";
} else if (/\.app/.test(app)) {
return "ios";
} else if (/\.apk/.test(app)) {
return "android";
}
throw new Error("Could not determine your device type from --app");
};
Appium.prototype.isMockIos = function() {
return this.deviceType === "mock_ios";
};
@@ -176,9 +189,13 @@ Appium.prototype.configure = function(desiredCaps, cb) {
app = desiredCaps.app;
}
try {
this.deviceType = this.getDeviceType(desiredCaps);
if (this.args.launch) {
this.deviceType = this.getDeviceTypeFromApp(this.args.app);
} else {
this.deviceType = this.getDeviceType(desiredCaps);
}
} catch (e) {
logger.error(e);
logger.error(e.message);
return cb(e);
}
if (this.isMockIos()) {
+53
View File
@@ -0,0 +1,53 @@
"use strict";
var path = require('path')
, iosApp = path.resolve(__dirname, "..", "..", "..", "sample-code", "apps",
"TestApp", "build", "Release-iphonesimulator", "TestApp.app")
, androidApp = path.resolve(__dirname, "..", "..", "..", "sample-code",
"apps", "ApiDemos", "bin", "ApiDemos-debug.apk")
, spawn = require('child_process').spawn
, crazyPort = 4799;
var waitForLaunch = function(app, extraArgs, cb) {
var args = [".", "-p", crazyPort, "-l", "-dd", "-m", "--app", app];
args = args.concat(extraArgs);
var proc = spawn('node', args, {cwd: path.resolve(__dirname, "..", "..", "..")});
proc.stdout.setEncoding('utf8');
proc.stderr.setEncoding('utf8');
var calledBack = false;
var output = '';
var tm = setTimeout(function() {
calledBack = true;
proc.kill();
cb(new Error("Appium never started. Output was: " + output));
}, 30000);
proc.stdout.on('data', function(data) {
output += data;
if (!calledBack &&/Appium REST http interface listener started on/.test(data)) {
clearTimeout(tm);
proc.kill();
calledBack = true;
cb();
}
});
proc.stderr.on('data', function(data) {
output += data;
});
proc.on('exit', function() {
if (!calledBack) {
calledBack = true;
cb(new Error("Appium never started. Output was: " + output));
}
});
};
describe('Pre-launching apps', function() {
it('should work for ios', function(done) {
waitForLaunch(iosApp, [], done);
});
it('should work for android', function(done) {
var args = ["--app-pkg", "com.example.android.apis", "--app-activity",
".ApiDemos"];
waitForLaunch(androidApp, args, done);
});
});