diff --git a/lib/api/protocol/getCurrentActivity.js b/lib/api/protocol/getCurrentActivity.js new file mode 100644 index 0000000000..d6d4e04eea --- /dev/null +++ b/lib/api/protocol/getCurrentActivity.js @@ -0,0 +1,20 @@ +const ProtocolAction = require('./_base-action.js'); + +/** + * Get the name of the current Android activity. + * + * More info here: https://appium.io/docs/en/commands/device/activity/current-activity/ + * + * @syntax browser.getCurrentActivity([callback]) + * @method getCurrentActivity + * @param {function} [callback] Callback function which is called with the result value. + * @returns {string} Name of the current activity. + * @see getCurrentPackage + * @see startActivity + * @api protocol.mobile + */ +module.exports = class Session extends ProtocolAction { + command(callback) { + return this.transportActions.getCurrentActivity(callback); + } +}; diff --git a/lib/api/protocol/getCurrentPackage.js b/lib/api/protocol/getCurrentPackage.js new file mode 100644 index 0000000000..775f45b7f9 --- /dev/null +++ b/lib/api/protocol/getCurrentPackage.js @@ -0,0 +1,20 @@ +const ProtocolAction = require('./_base-action.js'); + +/** + * Get the name of the current Android package. + * + * More info here: https://appium.io/docs/en/commands/device/activity/current-package/ + * + * @syntax browser.getCurrentPackage([callback]) + * @method getCurrentPackage + * @param {function} [callback] Callback function which is called with the result value. + * @returns {string} Name of the current package. + * @see getCurrentActivity + * @see startActivity + * @api protocol.mobile + */ +module.exports = class Session extends ProtocolAction { + command(callback) { + return this.transportActions.getCurrentPackage(callback); + } +}; diff --git a/lib/api/protocol/startActivity.js b/lib/api/protocol/startActivity.js new file mode 100644 index 0000000000..83b2cc9029 --- /dev/null +++ b/lib/api/protocol/startActivity.js @@ -0,0 +1,42 @@ +const ProtocolAction = require('./_base-action.js'); + +/** + * Start an Android activity by providing package name, activity name and other optional parameters. + * + * More info here: https://appium.io/docs/en/commands/device/activity/start-activity/ + * + * @example + * module.exports = { + * 'start an android activity': function (browser) { + * browser.startActivity({ + * appPackage: 'com.android.chrome', + * appActivity: 'com.google.android.apps.chrome.Main' + * }); + * }, + * + * 'start the main Android activity and wait for onboarding activity to start': function (browser) { + * browser.startActivity({ + * appPackage: 'org.wikipedia', + * appActivity: 'org.wikipedia.main.MainActivity', + * appWaitActivity: 'org.wikipedia.onboarding.InitialOnboardingActivity' + * }); + * } + * }; + * + * @syntax browser.startActivity(opts, [callback]) + * @method startActivity + * @param {string} opts Options to start the activity with. `appPackage` and `appActivity` are required, [others](https://appium.io/docs/en/commands/device/activity/start-activity/#json-parameters) are optional. + * @param {function} [callback] Optional callback function to be called when the command finishes. + * @see getCurrentActivity + * @see getCurrentPackage + * @api protocol.mobile + */ +module.exports = class Session extends ProtocolAction { + command(opts, callback) { + if (!('appPackage' in opts && 'appActivity' in opts)) { + throw new Error('Please provide both appPackage and appActivity options while using startActivity.'); + } + + return this.transportActions.startActivity(opts, callback); + } +}; diff --git a/lib/transport/selenium-webdriver/method-mappings.js b/lib/transport/selenium-webdriver/method-mappings.js index a0277cd902..742bb62bf7 100644 --- a/lib/transport/selenium-webdriver/method-mappings.js +++ b/lib/transport/selenium-webdriver/method-mappings.js @@ -902,6 +902,10 @@ module.exports = class MethodMappings { }; }, + /////////////////////////////////////////////////////////// + // Appium + /////////////////////////////////////////////////////////// + getAvailableContexts() { return '/contexts'; }, @@ -920,6 +924,22 @@ module.exports = class MethodMappings { }; }, + startActivity(opts) { + return { + method: 'POST', + path: '/appium/device/start_activity', + data: opts + }; + }, + + getCurrentActivity() { + return '/appium/device/current_activity'; + }, + + getCurrentPackage() { + return '/appium/device/current_package'; + }, + /////////////////////////////////////////////////////////////////////////// // Selenium Webdriver ///////////////////////////////////////////////////////////////////////////