From 5981667cca8c78e68398ed178fe767e28bfb4e72 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Mon, 6 Jan 2014 18:18:52 -0800 Subject: [PATCH] add support for doing web testing against android stock browser --- .jshintrc | 1 - lib/appium.js | 32 ++++++++++++++----------- lib/devices/android/chrome.js | 20 +++++++++++----- test/functional/android/device-state.js | 3 +++ 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/.jshintrc b/.jshintrc index 631686a01db..d3a58637cec 100644 --- a/.jshintrc +++ b/.jshintrc @@ -6,7 +6,6 @@ "trailing": true, "node": true, "eqeqeq": true, - "indent": 2, "trailing": true, "es5": true } diff --git a/lib/appium.js b/lib/appium.js index b17f7b691e1..9c010da2069 100644 --- a/lib/appium.js +++ b/lib/appium.js @@ -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() { @@ -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")); @@ -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; @@ -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; }; @@ -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); diff --git a/lib/devices/android/chrome.js b/lib/devices/android/chrome.js index 13cd0e16a3f..fa8df2ee8a7 100644 --- a/lib/devices/android/chrome.js +++ b/lib/devices/android/chrome.js @@ -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"; @@ -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); }; @@ -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) { diff --git a/test/functional/android/device-state.js b/test/functional/android/device-state.js index 85fd615fb11..8e81e6af3a4 100644 --- a/test/functional/android/device-state.js +++ b/test/functional/android/device-state.js @@ -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();