Skip to content

Commit

Permalink
Add Android activity appium commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Nov 21, 2022
1 parent 0c52846 commit b2e5849
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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);
}
};
20 changes: 20 additions & 0 deletions 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);
}
};
42 changes: 42 additions & 0 deletions 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);
}
};
20 changes: 20 additions & 0 deletions lib/transport/selenium-webdriver/method-mappings.js
Expand Up @@ -902,6 +902,10 @@ module.exports = class MethodMappings {
};
},

///////////////////////////////////////////////////////////
// Appium
///////////////////////////////////////////////////////////

getAvailableContexts() {
return '/contexts';
},
Expand All @@ -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
///////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit b2e5849

Please sign in to comment.