Device Commands
We will now be illustrating the various device commands available. Further we will illustrate each one of them using related examples (Using Java).
Type 1 Device Commands – Activity Commands
The first type of command under Device Commands is referred as ‘Activity Command’
1. Start Activity
The Start Activity Command is used to start an Android activity by providing package name and activity name
Example –
driver.startActivity(new Activity(“com.example”, “ActivityName”));
HTTP API Specifications
Endpoint – POST /wd/hub/session/:session_id/appium/device/start_activity
URL Parameters –
session_id ID of the session to route the command to
JSON Parameters –
name | type | description |
appPackage | string | Name of the package |
appActivity | string | Name of the activity |
appWaitPackage | string | Automation will begin after this package starts |
intentAction | string | Intent action which will be used to start activity |
intentCategory | string | Intent category which will be used to start activity |
intentFlags | string | Flags that will be used to start activity |
optionalIntentArguments | string | Additional intent arguments that will be used to start activity |
dontStopAppOnReset | boolean | Should the app stop on reset |
Response – null
2. Get Current Activity
The second command is ‘Get Current Activity’. Further, this command is used to get the name of the current Android activity.
Example –
String activity = driver.currentActivity();
HTTP API Specifications
Endpoint – GET /wd/hub/session/:session_id/appium/device/current_activity
URL Parameters –
- session_id ID of the session to route the command to
JSON Parameters – None
Response – Name of the current activity (string)
Type 2 Device Commands – App Commands
This is the second type of Device command referred as App Commands
1. Install App
In particular, the Install App is used to install the given app onto the device.
Example –
driver.installApp(“/Users/johndoe/path/to/app.apk”);
Such that,
iOS tests with XCUITest can also use the mobile: installApp method.
HTTP API Specifications
Endpoint – POST /wd/hub/session/:session_id/appium/device/install_app
URL Parameters –
- session_id ID of the session to route the command to
JSON Parameters –
name | type | description |
appPath | string | Path of the app being installed |
Response – null
2. Launch App
Here, the launch app is used to launch the app-under-test on the device
Example –
driver.launchApp();
In this case, if the app-under-test (AUT) is closed, or backgrounded, then it will launch it. Moreover, if the AUT is already open, it will background it and re-launch it. Also, iOS tests with XCUITest can also use the mobile: launchApp method.
HTTP API Specifications
Endpoint – POST /session/:session_id/appium/app/launch
URL Parameters –
- session_id ID of the session to route the command to
JSON Parameters – None
Response – null
TYPE 3 Device Commands – Interaction Command
1. Shake
This is the first type of interaction command. It is primarily used to perform a shake action on the device
Example –
driver.shake();
HTTP API Specifications
Endpoint – POST /session/:session_id/appium/device/shake
URL Parameters –
- session_id ID of the session to route the command to
JSON Parameters – None
Response – null
2. Lock
The second type of interaction command is used to lock the device
Example –
driver.lockDevice();
HTTP API Specifications
Endpoint – POST /session/:session_id/appium/device/lock
URL Parameters –
- session_id ID of the session to route the command to
JSON Parameters –
name | type | description |
seconds | number | How long to lock the screen (iOS only). |
Response – null
Type 4 Device Commands – Keys Command
1. Press Key Code
This is the first type of Keys Command that is used to press a particular key on an Android Device.
Example –
driver.pressKeyCode(AndroidKeyCode.SPACE, AndroidKeyMetastate.META_SHIFT_ON);
HTTP API Specifications
Endpoint – POST /session/:session_id/appium/device/press_keycode
URL Parameters –
session_id ID of the session to route the command to
JSON Parameters –
name | type | description |
keycode | number | Key code pressed on the device. |
metastate | number | Metastate for the keypress. |
flags | number | Flags for the keypress. |
Response – null
2. Long Press Key Code
Press and hold a particular key code on an Android device
Example –
driver.longPressKeyCode(AndroidKeyCode.HOME);
HTTP API Specifications
Endpoint – POST /session/:session_id/appium/device/long_press_keycode
URL Parameters –
session_id ID of the session to route the command to
JSON Parameters –
name | type | description |
keycode | number | Key code pressed on the device. |
metastate | number | Metastate for the keypress. |
flags | number | Flags for the keypress. |
Response – null
Type 5 Device Commands – Screen Recording Command
1. Start Recording Screen
This is the first type of screen recording command use to start recording screen
Example –
driver.startRecordingScreen();
driver.startRecordingScreen(new BaseStartScreenRecordingOptions(….));
HTTP API Specifications
Endpoint – POST /session/:session_id/appium/start_recording_screen
URL Parameters –
session_id ID of the session to route the command to
2. Stop Recording Screen
This command is used to stop the recording screen
Example –
driver.stopRecordingScreen();
driver.stopRecordingScreen(new BaseStopScreenRecordingOptions(….));
HTTP API Specifications
Endpoint – POST /session/:session_id/appium/stop_recording_screen
JSON Parameters – None
Response – Base64 encoded string. If remote_path is set, the response is empty string. (string)
Type 6 Device Commands – Finger print Command
1. Finger print
This command is primarily used to authenticate users by using their finger print scans on supported emulators.
Example –
driver.fingerPrint(1);
For Android emulator. Authenticate users by using their finger print scans.
HTTP API Specifications
Endpoint – POST /session/:session_id/appium/device/finger_print
URL Parameters –
session_id ID of the session to route the command to
JSON Parameters –
name | type | description |
fingerprintId | number | finger prints stored in Android Keystore system (from 1 to 10) |
Response – null