Skip to content

Commit

Permalink
add support for doing web testing against android stock browser
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Jan 7, 2014
1 parent 38cd211 commit 5981667
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Expand Up @@ -6,7 +6,6 @@
"trailing": true,
"node": true,
"eqeqeq": true,
"indent": 2,
"trailing": true,
"es5": true
}
32 changes: 18 additions & 14 deletions lib/appium.js
Expand Up @@ -138,7 +138,9 @@ Appium.prototype.isChrome = function() {
return this.args.app === "chrome" ||
this.args.androidPackage === "com.android.chrome" ||
this.args.app === "chromium" ||
this.args.androidPackage === "org.chromium.chrome.testshell";
this.args.androidPackage === "org.chromium.chrome.testshell" ||
this.args.app === "browser" ||
this.args.androidPackage === "com.android.browser";
};

Appium.prototype.isSelendroid = function() {
Expand Down Expand Up @@ -192,7 +194,7 @@ Appium.prototype.configure = function(desiredCaps, cb) {
if (this.isAndroid() || this.isSelendroid()) {
this.setAndroidArgs(desiredCaps);
//chrome apps do not need this checking, native and normal apps do
if (app === null || app.toLowerCase() !== "chrome") {
if (app === null || (app.toLowerCase() !== "chrome" && app.toLowerCase() !== "browser")) {
if (!this.args.androidActivity) {
return cb(new Error("You need to pass in the app-activity desired " +
"capability or server param"));
Expand Down Expand Up @@ -252,14 +254,8 @@ Appium.prototype.configureApp = function(desiredCaps, hasAppInCaps, cb) {
this.args.app = null;
logger.info("App is an Android package, will attempt to run on device");
cb(null);
} else if (_.contains(["chrome", "chromium"], appPath.toLowerCase())) {
logger.info("Looks like we want chrome on android");
if (appPath.toLowerCase() === "chromium") {
this.args.chromium = true;
} else {
this.args.chromium = false;
}
this.configureChromeAndroid();
} else if (_.contains(["chrome", "chromium", "browser"], appPath.toLowerCase())) {
this.configureChromeAndroid(appPath);
cb(null);
} else if (this.isFirefoxOS()) {
this.args.app = desiredCaps.app;
Expand Down Expand Up @@ -393,10 +389,19 @@ Appium.prototype.configureSafariForLauncher = function (desiredCaps, cb) {
});
};

Appium.prototype.configureChromeAndroid = function() {
Appium.prototype.configureChromeAndroid = function(appPath) {
logger.info("Looks like we want chrome on android");
this.deviceType = "android";
this.args.androidPackage = "com.android.chrome";
this.args.androidActivity = "com.google.android.apps.chrome.Main";
if (appPath.toLowerCase() === "chromium") {
this.args.androidPackage = "org.chromium.chrome.testshell";
this.args.androidActivity = "org.chromium.chrome.testshell.Main";
} else if (appPath.toLowerCase() === "browser") {
this.args.androidPackage = "com.android.browser";
this.args.androidActivity = "com.android.browser.BrowserActivity";
} else {
this.args.androidPackage = "com.android.chrome";
this.args.androidActivity = "com.google.android.apps.chrome.Main";
}
this.args.app = null;
};

Expand Down Expand Up @@ -546,7 +551,6 @@ Appium.prototype.initDevice = function() {
, logNoColors: this.args.logNoColors
};
if (this.isChrome()) {
androidOpts.chromium = this.args.chromium;
this.device = new Chrome(androidOpts);
} else {
this.device = new Android(androidOpts);
Expand Down
20 changes: 14 additions & 6 deletions lib/devices/android/chrome.js
Expand Up @@ -35,11 +35,19 @@ ChromeAndroid.prototype.start = function(cb, onDie) {
this.onChromedriverStart = null;
async.waterfall([
this.ensureChromedriverExists.bind(this),
this.unlock.bind(this),
this.startChromedriver.bind(this),
this.createSession.bind(this)
], cb);
};

ChromeAndroid.prototype.unlock = function(cb) {
this.pushUnlock(function(err) {
if (err) return err;
this.unlockScreen(cb);
}.bind(this));
};

ChromeAndroid.prototype.ensureChromedriverExists = function(cb) {
logger.info("Ensuring Chromedriver exists");
var cmd = isWindows ? "where chromedriver.exe" : "which chromedriver";
Expand Down Expand Up @@ -87,18 +95,18 @@ ChromeAndroid.prototype.startChromedriver = function(cb) {

ChromeAndroid.prototype.createSession = function(cb) {
logger.info("Creating Chrome session");
var pkg = 'com.android.chrome';
if (this.opts.chromium) {
pkg = 'org.chromium.chrome.testshell';
}
var data = {
sessionId: null,
desiredCapabilities: {
chromeOptions: {
androidPackage: pkg
androidPackage: this.opts.appPackage,
androidActivity: this.opts.appActivity
}
}
};
if (this.opts.appPackage === "com.android.chrome") {
delete data.desiredCapabilities.chromeOptions.androidActivity;
}
this.proxyNewSession(data, cb);
};

Expand Down Expand Up @@ -127,7 +135,7 @@ ChromeAndroid.prototype.proxyNewSession = function(data, cb) {
}
} catch(ignore) {}
if (this.chromeSessionId) return cb(null, this.chromeSessionId);

// then check redirect success case
try {
if (res.statusCode === 303 && res.headers.location) {
Expand Down
3 changes: 3 additions & 0 deletions test/functional/android/device-state.js
Expand Up @@ -14,6 +14,9 @@ describe('Android Device State module', function() {
childProcess.exec("adb devices", function(err, stdout) {
should.not.exist(err);
var device = /\n([A-Za-z0-9\-]+)\W+device\n/.exec(stdout);
if (!device) {
throw new Error("Looks like device isn't ready for test");
}
device = device[1];
should.exist(device);
done();
Expand Down

0 comments on commit 5981667

Please sign in to comment.