From 1c6b495cd2f3fbbb8622a9fb43f3e50aa79ab82e Mon Sep 17 00:00:00 2001 From: imrane Date: Fri, 3 Jan 2014 11:16:44 +0000 Subject: [PATCH] Implementing mobile:background command for Android and Selendroid --- lib/devices/android/android-common.js | 21 +++++++++++++++++++++ lib/devices/android/android-controller.js | 4 ---- lib/devices/android/selendroid.js | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/devices/android/android-common.js b/lib/devices/android/android-common.js index db0aa1dbb..f692979c5 100644 --- a/lib/devices/android/android-common.js +++ b/lib/devices/android/android-common.js @@ -14,6 +14,27 @@ var logTypesSupported = { var androidCommon = {}; +androidCommon.background = function(secs, cb) { + console.log("background " + this.appPackage + " " + this.appActivity); + this.adb.keyevent("3", function() { + cb(null, { + status: status.codes.Success.code + , value: null + }); + }); + setTimeout(function(){ + var appName = this.appActivity.replace(this.appPackage,this.appPackage + "/"); + this.adb.shell("am start -n "+ appName, function(err, stdout) { + if (err) return cb(err); + if (stdout.indexOf("No such file") !== -1) { + return cb(new Error("remote apk did not exist")); + } + cb(null, stdout.trim()); + }); + }.bind(this),secs *1000) ; + +}; + androidCommon.prepareDevice = function(onReady) { logger.info("Preparing device for session"); async.series([ diff --git a/lib/devices/android/android-controller.js b/lib/devices/android/android-controller.js index 8da70d292..a3a28f4d9 100644 --- a/lib/devices/android/android-controller.js +++ b/lib/devices/android/android-controller.js @@ -352,10 +352,6 @@ androidController.lock = function(secs, cb) { cb(new NotYetImplementedError(), null); }; -androidController.background = function(secs, cb) { - cb(new NotYetImplementedError(), null); -}; - androidController.getOrientation = function(cb) { this.proxy(["orientation", {}], cb); }; diff --git a/lib/devices/android/selendroid.js b/lib/devices/android/selendroid.js index 4cd88b483..d90735cc7 100644 --- a/lib/devices/android/selendroid.js +++ b/lib/devices/android/selendroid.js @@ -38,6 +38,7 @@ var Selendroid = function(opts) { , 'getCommandTimeout' , 'reset' , 'lock' + , 'background' , 'keyevent' , 'currentActivity' , 'installApp'