mirror of
https://github.com/appium/appium.git
synced 2026-02-07 01:58:55 -06:00
Merge pull request #3462 from 0x1mason/2969
Fix for #2969. Added ability to arbitrarily launch activities.
This commit is contained in:
@@ -125,6 +125,42 @@ $this->hideKeyboard(array('strategy' => 'pressKey', 'key' => 'Done'));
|
||||
driver.HideKeyboard("Done");
|
||||
```
|
||||
|
||||
### Start Activity
|
||||
|
||||
Open an activity in the current app or start a new app and open an activity *Android only*
|
||||
|
||||
```java
|
||||
// java
|
||||
driver.startActivity("appPackage","com.example.android.apis", null, null);
|
||||
```
|
||||
|
||||
```javascript
|
||||
// javascript
|
||||
driver.startActivity({appPackage: 'com.example.android.apis', appActivity: '.Foo'}, cb);
|
||||
```
|
||||
|
||||
```python
|
||||
# python
|
||||
driver.start_activity('com.example.android.apis', '.Foo')
|
||||
```
|
||||
|
||||
```ruby
|
||||
# ruby
|
||||
start_activity app_package: 'io.appium.android.apis', app_activity: '.accessibility.AccessibilityNodeProviderActivity'
|
||||
```
|
||||
|
||||
```csharp
|
||||
// c#
|
||||
driver.StartActivity("com.example.android.apis", ".Foo");
|
||||
```
|
||||
|
||||
```php
|
||||
// php
|
||||
$this->startActivity(array("appPackage" => "com.example.android.apis",
|
||||
"appActivity" => ".Foo"));
|
||||
```
|
||||
|
||||
|
||||
### Open Notifications
|
||||
|
||||
Open the notification shade *Android only*
|
||||
|
||||
@@ -707,7 +707,7 @@ androidController.resetAndStartApp = function (cb) {
|
||||
async.series([
|
||||
this.resetApp.bind(this),
|
||||
this.waitForActivityToStop.bind(this),
|
||||
this.startApp.bind(this)
|
||||
this.startAppUnderTest.bind(this)
|
||||
], cb);
|
||||
};
|
||||
|
||||
|
||||
@@ -361,21 +361,25 @@ Android.prototype.pushAppium = function (cb) {
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Android.prototype.startApp = function (cb) {
|
||||
if (!this.args.androidCoverage) {
|
||||
this.adb.startApp({
|
||||
pkg: this.args.appPackage,
|
||||
activity: this.args.appActivity,
|
||||
action: this.args.intentAction,
|
||||
category: this.args.intentCategory,
|
||||
flags: this.args.intentFlags,
|
||||
waitPkg: this.args.appWaitPackage,
|
||||
waitActivity: this.args.appWaitActivity,
|
||||
optionalIntentArguments: this.args.optionalIntentArguments
|
||||
}, cb);
|
||||
Android.prototype.startAppUnderTest = function (cb) {
|
||||
this.startApp(this.args, cb);
|
||||
};
|
||||
|
||||
Android.prototype.startApp = function (args, cb) {
|
||||
if (args.androidCoverage) {
|
||||
this.adb.androidCoverage(args.androidCoverage, args.appWaitPackage,
|
||||
args.appWaitActivity, cb);
|
||||
} else {
|
||||
this.adb.androidCoverage(this.args.androidCoverage, this.args.appWaitPackage,
|
||||
this.args.appWaitActivity, cb);
|
||||
this.adb.startApp({
|
||||
pkg: args.appPackage,
|
||||
activity: args.appActivity,
|
||||
action: args.intentAction,
|
||||
category: args.intentCategory,
|
||||
flags: args.intentFlags,
|
||||
waitPkg: args.appWaitPackage,
|
||||
waitActivity: args.appWaitActivity,
|
||||
optionalIntentArguments: args.optionalIntentArguments
|
||||
}, cb);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ var status = require('./status.js')
|
||||
, helpers = require('../helpers.js')
|
||||
, logCustomDeprecationWarning = helpers.logCustomDeprecationWarning
|
||||
, _ = require('underscore')
|
||||
, safely = require('./helpers').safely;
|
||||
, safely = require('./helpers').safely
|
||||
, NotImplementedError = require('./errors').NotImplementedError;
|
||||
|
||||
exports.getGlobalBeforeFilter = function (appium) {
|
||||
return function (req, res, next) {
|
||||
@@ -124,6 +125,22 @@ exports.isAppInstalled = function (req, res) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.startActivity = function (req, res) {
|
||||
var onErr = function (err) {
|
||||
respondError(req, res, "Unable to launch the app: " + err);
|
||||
};
|
||||
|
||||
// 8/21/14: currently not supported on all devices
|
||||
if (!req.device.startApp) {
|
||||
onErr(new NotImplementedError());
|
||||
} else {
|
||||
req.device.startApp(req.body, function (err) {
|
||||
if (err) return onErr(err);
|
||||
respondSuccess(req, res, "Successfully launched the app.");
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.launchApp = function (req, res) {
|
||||
var onErr = function (err) {
|
||||
respondError(req, res, "Unable to launch the app: " + err);
|
||||
@@ -140,7 +157,7 @@ exports.closeApp = function (req, res) {
|
||||
req.device.stop(function () {
|
||||
respondSuccess(req, res, "Successfully closed the [" + req.device.args.app + "] app.");
|
||||
}, function () {
|
||||
respondError(req, res, "Something whent wront whilst closing the [" + req.device.args.app + "] app.");
|
||||
respondError(req, res, "Something went wrong whilst closing the [" + req.device.args.app + "] app.");
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ module.exports = function (appium) {
|
||||
rest.post('/wd/hub/session/:sessionId?/appium/device/toggle_wifi', controller.toggleWiFi);
|
||||
rest.post('/wd/hub/session/:sessionId?/appium/device/toggle_location_services', controller.toggleLocationServices);
|
||||
rest.post('/wd/hub/session/:sessionId?/appium/device/open_notifications', controller.openNotifications);
|
||||
rest.post('/wd/hub/session/:sessionId?/appium/device/start_activity', controller.startActivity);
|
||||
|
||||
rest.post('/wd/hub/session/:sessionId?/appium/app/launch', controller.launchApp);
|
||||
rest.post('/wd/hub/session/:sessionId?/appium/app/close', controller.closeApp);
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
"socks": "~0.0.1",
|
||||
"underscore-cli": "~0.2.17",
|
||||
"unorm": "~1.3.3",
|
||||
"wd": "~0.3.4",
|
||||
"wd": "~0.3.7",
|
||||
"wd-bridge": "~0.0.1",
|
||||
"yiewd": "~0.5.0"
|
||||
}
|
||||
|
||||
@@ -128,7 +128,28 @@ describe("apidemo - basic @skip-ci", function () {
|
||||
})
|
||||
.nodeify(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('at any time', function () {
|
||||
var driver;
|
||||
setup(this, desired)
|
||||
.then(function (d) { driver = d; });
|
||||
|
||||
it('should open an activity in this application', function (done) {
|
||||
driver
|
||||
.startActivity({appPackage: "io.appium.android.apis", appActivity: ".accessibility.AccessibilityNodeProviderActivity"})
|
||||
.getCurrentActivity()
|
||||
.should.eventually.include("Node")
|
||||
.nodeify(done);
|
||||
});
|
||||
|
||||
it('should open an activity in another application', function (done) {
|
||||
driver
|
||||
.startActivity({appPackage: "com.android.contacts", appActivity: ".ContactsListActivity"})
|
||||
.getCurrentActivity()
|
||||
.should.eventually.include("Contact")
|
||||
.nodeify(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with fastReset', function () {
|
||||
|
||||
Reference in New Issue
Block a user