Appium Device Cheat Sheet
Device control is a core part of mobile test automation. With these Appium commands, you can install or remove apps, launch activities, manage files, simulate key presses, and even lock or shake the device. This quick reference focuses on the most useful device-level actions for both Android and iOS.
|
Command / Action |
Description |
Example / Notes |
|
Start Activity |
Launches a specific Android activity. |
driver.startActivity("com.android.calculator2", "com.android.calculator2.Calculator") |
|
Current Activity |
Returns the name of the currently focused activity (Android). |
driver.currentActivity() |
|
App Install |
Installs an app from local storage or URL. |
driver.installApp("C:/apps/MyApp.apk") |
|
App Remove |
Uninstalls an app from the device. |
driver.removeApp("com.example.myapp") |
|
Is App Installed |
Checks if an app is installed on the device. |
driver.isAppInstalled("com.example.myapp") |
|
Launch App |
Launches the app under test without creating a new session. |
driver.launchApp() |
|
Close App |
Closes the app under test. |
driver.closeApp() |
|
Background App |
Puts the app in the background for given seconds. |
driver.runAppInBackground(Duration.ofSeconds(5)) |
|
Push File |
Uploads a file from local machine to device. |
driver.pushFile("/sdcard/test.txt", fileData) |
|
Pull File |
Downloads a file from the device to local machine. |
driver.pullFile("/sdcard/test.txt") |
|
Press Key |
Sends a key press event (Android key codes). |
driver.pressKey(new KeyEvent(AndroidKey.HOME)) |
|
Long Press Key |
Long presses a key (Android key codes). |
driver.longPressKey(new KeyEvent(AndroidKey.VOLUME_UP)) |
|
Lock Device |
Locks the device screen for given seconds. |
driver.lockDevice() |
|
Unlock Device |
Unlocks the device screen. |
driver.unlockDevice() |
|
Is Device Locked |
Checks if the device screen is locked. |
driver.isDeviceLocked() |
|
Shake Device |
Simulates shaking the device (iOS only). |
driver.shake() |