From baad3287cd13e23568f577f609ee1e4ed38aa4aa Mon Sep 17 00:00:00 2001 From: msaravana123 Date: Thu, 28 Jul 2022 16:37:36 +1000 Subject: [PATCH] feat: Add `mobile: startActivity` extension (#803) --- README.md | 13 +++++++++++++ lib/commands/execute.js | 2 ++ lib/commands/general.js | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/README.md b/README.md index 86e3f1f76..b255dfd2c 100644 --- a/README.md +++ b/README.md @@ -730,6 +730,19 @@ Name | Type | Required | Description | Example --- | --- | --- | --- | --- remotePath | string | yes | The full path to the remote file or a file inside an application bundle | `/sdcard/myfile.txt` or `@my.app.id/path/in/bundle` +### mobile: startActivity + +Starts the given activity with intent options, activity options and locale. Activity could only be executed in scope of the current app package. + +#### Arguments + +Name | Type | Required | Description | Example +--- | --- | --- | --- | --- +appActivity | string | yes | Applicaiton acitivity identifier to start | `com.myapp.myacitivty` +locale | object | no | Sets the locale for the app under test. It only uses public APIs for its purpose. See https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers to get the list of available language abbreviations. | `{"language": "zh", "country": "CN", "variant": "Hans"}` +optionalIntentArguments | object | no | The mapping of custom options for the intent that is going to be passed to the main app activity. Check [Intent Options](#intent-options) for more details. | `{ 'flags': 'ACTIVITY_NEW_TASK', 'action': '', 'className': '', 'es': {'foo': 'bar'} }` +optionalActivityArguments | object | no | The mapping of custom options for the main app activity that is going to be started. Check [Activity Options](#activity-options) for more details. | `{ 'launchDisplayId': 1 }` + ### mobile: startService Starts the given service intent. diff --git a/lib/commands/execute.js b/lib/commands/execute.js index fe49ad5ac..a0c2dcd45 100644 --- a/lib/commands/execute.js +++ b/lib/commands/execute.js @@ -54,6 +54,8 @@ extensions.executeMobile = async function executeMobile (mobileCommand, opts = { deleteFile: 'mobileDeleteFile', + startActivity: 'mobileStartActivity', + startService: 'mobileStartService', stopService: 'mobileStopService', diff --git a/lib/commands/general.js b/lib/commands/general.js index ae2cf55d9..4d75926f2 100644 --- a/lib/commands/general.js +++ b/lib/commands/general.js @@ -296,6 +296,31 @@ helpers.suspendChromedriverProxy = function suspendChromedriverProxy () { this.jwpProxyActive = true; }; +/** + * Starts the given activity with intent options, activity options and locale. + * Activity could only be executed in scope of the current app package. + * + * appActivity is mandatory + * + * locale, optionalIntentArguments, optionalActivityArguments are optional + */ +commands.mobileStartActivity = async function mobileStartActivity (opts = {}) { + const appPackage = this.caps.appPackage; + const { + appActivity, + locale, + optionalIntentArguments, + optionalActivityArguments + } = assertRequiredOptions(opts, ['appActivity']); + return await this.espresso.jwproxy.command(`/appium/device/start_activity`, 'POST', { + appPackage, + appActivity, + locale, + optionalIntentArguments, + optionalActivityArguments + }); +}; + commands.startActivity = async function startActivity (appPackage, appActivity, appWaitPackage, appWaitActivity) { // intentAction, intentCategory, intentFlags, optionalIntentArguments, dontStopAppOnReset