Top Appium Commands every Developer must know

Read this article to learn about the top Appium commands every developer should know.

Get Started free
Top-Appium-Commands-every-Developer-must-know
Home Guide Top Appium Commands every Developer must know

Top Appium Commands every Developer must know

Mobile Application testing is either done manually or automated. Open-source tools such as Appium can automate mobile application tests.

Overview

What is Appium?

Appium is an open-source test automation tool for testing Mobile Applications. It supports various platforms, such as iOS, Android, and Windows.

Categories of Important Appium Commands and Methods

  1. Initialize Desired Capabilities: Define device, platform, and app settings to start a session.
  2. Locator Strategies: Identify UI elements using XPath, ID, class name, and more.
  3. App & Device Actions: Perform actions like tap, swipe, scroll, and keyboard input.
  4. Advanced Commands – iOS & Android: Execute platform-specific gestures and actions.
  5. ​​Execute Methods for Extended Functionality: Trigger mobile-specific actions like unlocking a device, simulating fingerprint scan, or toggling network settings.
  6. Advanced Commands – iOS: Run iOS-exclusive features like Touch ID or backgrounding apps.
  7. Advanced Commands – Android: Provide greater control over device behavior, allowing testers to simulate actual conditions and validate responses.
  8. App Management – iOS: Install, uninstall, and launch apps on iOS devices.
  9. App Management – Android: Manage APKs and app activities on Android devices.

This article provides a cheat sheet of the top Appium commands every developer must know.

What is Appium?

Appium is an open-source test automation tool for testing Mobile Applications. It supports various platforms, such as iOS, Android, and Windows.

It allows users to test various types of Mobile Applications, such as:

  • Native Apps: These are native to a particular platform and are written using Android, iOS, or Windows SDKs.
  • Web Apps: These are pure web apps accessed via native browsers like Chrome, Safari, Firefox, etc.
  • Hybrid Apps: These are an amalgamation of both Native and Web apps.

Appium offers cross-platform application testing. That is, a single API works for both Android and iOS platforms. This means developers or testers can use the same code for all platforms. Like Selenium, Appium allows testers to write test scripts in different programming languages such as Python, Java, Ruby, PHP, JavaScript, and C#.

Appium Commands Cheat Sheet

Appium provides various commands and methods for automating mobile applications across Android and iOS platforms. These commands allow testers to interact with mobile apps like a real user.

Below is a handy cheat sheet covering commonly used Appium commands to speed up your mobile automation workflow.

Pre-Requisites

Before starting with App Automation Testing with Appium, you would need to follow these steps:

1. Ensure that the Java Library is installed for Appium.

2. Download and install Maven following the steps from the official website.

3. Import statements for various commands can be as follows. Add them to your program as per the commands in use:

  • import org.openqa.selenium.WebElement;
  • import org.openqa.selenium.JavascriptExecutor;
  • import org.openqa.selenium.support.FindBy;
  • import org.openqa.selenium.support.FindBys;
  • import org.openqa.selenium.remote.RemoteWebElement;
  • import org.openqa.selenium.remote.DesiredCapabilities;
  • import org.openqa.selenium.Dimension;
  • import org.openqa.selenium.By;
  • import org.openqa.selenium.Keys;
  • import org.openqa.selenium.WebDriver;
  • import io.appium.java_client.pagefactory.*;
  • import io.appium.java_client.ios.IOSElement;
  • import io.appium.java_client.AppiumDriver;
  • import io.appium.java_client.MobileElement;
  • import io.appium.java_client.android.AndroidDriver;
  • import io.appium.java_client.ios.IOSDriver;
  • import io.appium.java_client.MobileElement;
  • import io.appium.java_client.MultiTouchAction;
  • import io.appium.java_client.TouchAction;
  • import io.appium.java_client.android.AndroidElement;

Here are the Basic Appium Commands in the Java version:

1. Initialize Desired Capabilities

Desired Capabilities define the properties of the mobile device and app under test (like platform name, device name, app path, etc.).

These capabilities are required to start an Appium session and connect to the target device or emulator.

  • Create local Appium Server instance
appiumLocalService = new AppiumServiceBuilder().usingAnyFreePort().build();
  • Start local Appium Server instance
appiumLocalService.start();
  • iOS Capabilities

Example:

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“automationName”, "XCUITest");

caps.setCapability(“deviceName”, "iPhone 13");

caps.setCapability(“platformName”, "iOS");

caps.setCapability(“platformVersion”, "15.6");
  • Android Capabilities

Example:

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“automationName”, "UiAutomator2");

caps.setCapability(“deviceName”, "Samsung");

caps.setCapability(“platformName”, "Android");

caps.setCapability(“platformVersion”, "7.1");
  • Install an app on iOS
DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“app”, "path/to/TestApp.app.zip");
  • Install an app on Android

Example:

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“appPackage”, "com.android.calculator2");

caps.setCapability(“appActivity”, "com.android.calculator2.Calculator");

caps.setCapability(“app”, "path/to/TestApp.apk");
  • Start browser on iOS
DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“browserName”, "Safari");
  • Start browser on Android
DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“browserName”, "Chrome");
  • Initialize iOS driver on the local server instance
driver = new IOSDriver<IOSElement>(appiumLocalService, caps);
  • Initialize Android driver on the local server instance
driver = new AndroidDriver<AndroidElement>(appiumLocalService, caps);
  • Set WebView Context for Hybrid Apps
driver.context(driver.getContextHandles().stream().filter(c -> c.contains("WEBVIEW")).findFirst().orElse(null));
  • Initialize iOS remote driver

Remote Webdriver helps in making a network request to a Selenium hub to start a driver session since Appium operates on the Client-Server model. It is not recommended to use the Remote WebDriver directly. Hence, it is used with the IOS Driver and Android Driver.

IOS and Android Drivers inherit from Appium Driver. They add additional functions that are useful to the context of mobile automation on IOS and Android devices respectively through Appium.

In the example below, the URL is pointing to the local host.

Note: You can include the URL which points to your remote web server as well here.

driver = new IOSDriver<IOSElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps); //This URL points to the local server
  • Initialize Android remote driver
driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps); //This URL points to the local server

2. Locator Strategies

To interact with app elements, Appium uses different locator strategies such as id, className, xpath, accessibilityId, and AndroidUIAutomator or iOSPredicateString.

Choosing the right strategy ensures reliable and fast element detection.

  • Locate by ID
driver.findElementById("android:id/button");
  • Locate by Accessibility ID
driver.findElementByAccessibilityId("Views");
  • Locate by Class (Single Element)
driver.findElementByClassName("android.widget.CheckBox");
  • Locate by Class (Multiple Elements)
driver.findElementsByClassName("android.widget.CheckBox");
  • Locate by AndroidUIAutomator (UI Automator 2)
driver.findElementByAndroidUIAutomator("new UiSelector().textContains(\"BUTTON\");");
  • Locate by Image
driver.findElementByImage(base64EncodedImageFile);
  • Locate by XPath – iOS
driver.findElementByXPath("(//XCUIElementTypeButton)[1]");
  • Locate by XPath – Android
driver.findElementByXPath("//*[@resource-id='com.example.android.apis:id/button']");

3. App & Device Actions

This category includes essential actions like clicking, typing, scrolling, swiping, and interacting with system features (e.g., locking the device or rotating the screen).

These simulate real user behavior for robust end-to-end testing.

  • For Handling Alert
driver.switchTo().alert().accept();

driver.switchTo().alert().dismiss();
  • For Basic Input operations
element.click();

element.clear();

element.sendKeys("textToType");
  • For Changing orientation
driver.rotate(ScreenOrientation.LANDSCAPE);
  • For Setting text on clipboard
driver.setClipboardText("9876", "UserText");

String clipboard = driver.getClipboardText();
  • For Mobile gestures using TouchAction
TouchAction touchAction = new TouchAction(driver);
  • For Tapping:
touchAction.tap(TapOptions.tapOptions()

.withPosition(PointOption.point(x, y));
  •  For Pressing:
touchAction.press(PointOption.point(x, y));
  • For Waiting:
touchAction.waitAction(WaitOptions

.waitOptions(Duration.ofMillis(200)));
  • For Moving:
touchAction.moveTo(PointOption.point(x, y));
  • For Long Press:
touchAction.longPress(PointOption.point(x, y));
  • For Releasing and Performing:
touchAction.release();

touchAction.perform();
  • For Toggle services
driver.toggleAirplaneMode();

driver.toggleData();

driver.toggleLocationServices();

driver.toggleWifi();
  • For Soft keyboard actions
driver.isKeyboardShown(); // returns boolean

driver.hideKeyboard();
  • For Locking device
driver.isDeviceLocked(); // returns boolean

driver.lockDevice();

driver.unlockDevice();
  • For Notifications
driver.openNotifications();
  • For File actions
driver.pushFile("/data/local/tmp/file", new File("path/to/file"));

driver.pullFile("/path/to/device/file"); // returns byte[]

driver.pullFolder("/path/to/device"); // returns byte[]
  • For getting System time
driver.getDeviceTime(); // returns String

4. Advanced Commands – both iOS & Android

These are platform-agnostic commands like switching contexts (for hybrid apps), performing multi-touch gestures, interacting with notifications, or capturing device logs that are important for deep functional and UI validation.

  • For Multitouch actions
TouchAction actionOne = new TouchAction(driver);
  • For Pressing at a point:
actionOne.press(PointOption.point(10, 10));
  • For Moving to a point:
actionOne.moveTo(PointOption.point(10, 100));
  • For Releasing
actionOne.release();

Example:

TouchAction actionTwo = new TouchAction(driver);

actionTwo.press(PointOption.point(20, 20));

actionTwo.moveTo(PointOption.point(20, 200));

actionTwo.release();

MultiTouchAction action = new MultiTouchAction(driver);

action.add(actionOne);

action.add(actionTwo);

action.perform();
  • For Swipe using TouchAction

Example:

TouchAction touchAction = new TouchAction(driver);

WebElement element =  (WebElement) driver.findElementById("android:id/text2");

Point point = element.getCoordinates().onPage();

Dimension size = element.getSize();

touchAction.press(PointOption.point(point.getX() + 5, point.getY() + 5))

.waitAction(WaitOptions.waitOptions(Duration.ofMillis(200)))

.moveTo(PointOption.point(point.getX() + size.getWidth() - 5,

point.getY() + size.getHeight() - 5)).release().perform();
  • For Scroll using Javascript Executor

Example:

JavascriptExecutor js = (JavascriptExecutor) driver;

HashMap<String, String> scrollObject = new HashMap<String, String>();

scrollObject.put("direction", "down"); // up, left, right

scrollObject.put("element", ((RemoteWebElement) element).getId());

js.executeScript("mobile: scroll", scrollObject);

Example:

driver.findElementByAndroidUIAutomator("new UiScrollable(new

UiSelector()).scrollIntoView(new UiSelector().text(\"Views\"));" );
  • For taking Screenshot
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

// BYTES,BASE64 – returns File, byte[] or String (base64 encoded PNG)
  • For updating Device Settings
driver.setSetting(Setting.KEYBOARD_AUTOCORRECTION, false);

driver.getSettings(); // returns Map<String, Object>
  • For Screen Recording
driver.startRecordingScreen();

driver.stopRecordingScreen();

5. Execute Methods for Extended Functionality

Some advanced Appium methods go beyond standard WebDriver commands. These are implemented using Execute Methods, allowing you to trigger mobile-specific actions like unlocking a device, simulating a fingerprint scan, or toggling network settings.

These extended Appium methods work through the execute command, making them compatible with any Appium or Selenium client.

Example:

driver.execute('mobile: unlock', [{ unlockType: 'pin', unlockKey: '1234' }]);

Use Execute Methods when you need advanced control over mobile behavior not covered by default WebDriver APIs.

6. Advanced Commands – iOS

Platform-specific commands exclusive to iOS devices, including handling biometric prompts, launching Safari, or interacting with system alerts, helpful for full iOS automation coverage.

  • For shaking device
driver.shake();
  • For adding photos
driver.pushFile("img.jpg", new File("path to img.jpg"));
  • For sending voice commands to SIRI

Example:

JavascriptExecutor js = (JavascriptExecutor) driver;

Map<String, Object> args = new HashMap<>();

args.put("text", "Hey Siri, what's happening?");

driver.executeScript("mobile: siriCommand", args);
  • For performing Touch ID in iOS Simulator
driver.performTouchID(true); // Simulates a correct touch ID

driver.performTouchID(false); // Simulates a failed touch ID
  • For simulating hardware key

Example:

JavascriptExecutor js = (JavascriptExecutor) driver;

Map<String, Object> args = new HashMap<>();

args.put("name", "home"); // volumeup; volumedown

driver.executeScript("mobile: pressButton", args);

7. Advanced Commands – Android

Advanced commands in Android testing provide greater control over device behavior, allowing testers to simulate real-world conditions and validate app responses.

Below are key Appium commands for manipulating device state, injecting files, simulating hardware keys, and retrieving performance data:

  • For setting Battery Percentage
driver.setPowerCapacity(100);;
  • For setting the state of the battery charger to connected or not
driver.setPowerAC(PowerACState.ON);

driver.setPowerAC(PowerACState.OFF);
  • For adding photos
driver.pushFile("/Pictures/img.jpg", new File("path to img.jpg"));
  • For simulating hardware key
driver.pressKey(new KeyEvent().withKey(AndroidKey.HOME));

driver.longPressKey(new KeyEvent().withKey(AndroidKey.POWER));
  • For getting performance data
driver.getPerformanceData("my.app.package", "cpuinfo", 6); // returns

List<List<Object>>

8. App Management – iOS

Appium also lets you install, uninstall, and reset apps directly on iOS devices through automation, saving time during repeated testing cycles.

  • For installing an app

Example:

args.put("app", "path/to/app.ipa");

driver.executeScript("mobile: installApp", args);
  • For verifying if the app is installed

Example:

args.put("bundleId", "com.myapp");

(boolean)driver.executeScript("mobile: isAppInstalled", args);
  • For launching the app

Example:

args.put("bundleId", "com.apple.calculator");

driver.executeScript("mobile: launchApp", args);
  • For switching the app to foreground

Example:

args.put("bundleId", "com.myapp");

driver.executeScript("mobile: activateApp", args);
  • For checking current state of the app

Example:

args.put("bundleId", "com.myapp");

(ApplicationState)driver.executeScript("mobile: queryAppState", args);

// will return false if app is not running, otherwise return true
  • For terminating the app

Example:

args.put("bundleId", "com.myapp");

(boolean)driver.executeScript("mobile: terminateApp", args);

// will return false if app is not running, otherwise return true
  • For removing the app

Example:

args.put("bundleId", "com.myapp");

driver.executeScript("mobile: removeApp", args);

9. App Management – Android

Commands in this category allow you to install APKs, manage app permissions, clear app data, and access Android-specific utilities from within your test script.

  • For installing an app
driver.installApp("path/to/app.apk");
  • For verifying if the app is installed
driver.isAppInstalled("com.example.android.apis");

// returns bool
  • For launching the app
driver.launchApp();
  • For starting activity
driver.startActivity(new Activity("com.example.android.apis",

".ApiDemos"));
  • For getting current activity
driver.currentActivity(); // returns String
  • For getting current package
driver.getCurrentPackage(); // returns String
  • For switching the app to foreground
driver.runAppInBackground(Duration.ofSeconds(10));

// Runs for 10 seconds
  • For checking current state of the app
driver.queryAppState("com.example.android.apis");

// returns Application State
  • For getting app strings
driver.getAppStringMap("en", "path/to/file");

// returns Map<String, String>
  • For closing the app
driver.closeApp();
  • For reseting the app
driver.resetApp();
  • For terminating the app
driver.terminateApp("com.example.android.apis"); // returns bool
  • For removing the app
driver.removeApp("com.example.AppName");

BrowserStack App Automate Banner

Test on Real Mobile Devices with BrowserStack

Appium is a go-to tool for mobile automation thanks to its cross-platform support and flexibility. However, real device testing is crucial, as emulators can’t replicate real-world conditions like hardware behavior, battery status, or network interruptions.

BrowserStack App Automate offers a powerful platform to run Appium tests on thousands of real iOS and Android devices on their real device cloud.

Benefits of Testing on Real Devices with BrowserStack:

  • Real User Conditions: Test under real-world scenarios like low battery, incoming calls, network fluctuations, etc.
  • Instant Access to Real Devices: No need to maintain an in-house device lab, access 3500+ real devices instantly.
  • Cross-Platform Support: Run Appium tests on Android and iOS versions across various screen sizes and manufacturers.
  • Parallel Test Execution: Speed up test cycles with parallel execution across multiple real devices.
  • CI/CD Integration: Easily integrate with Jenkins, GitHub Actions, Azure DevOps, and other CI tools.
  • Detailed Debugging Tools: Access logs, screenshots, video recordings, and network traffic for efficient root cause analysis

Talk to an Expert

Conclusion

Mastering key Appium commands is essential for building efficient and reliable mobile test automation.

With the right commands and real device testing on platforms like BrowserStack, developers can ensure robust app performance across devices, platforms, and real-world conditions.

Appium Useful Resources

Tutorials

Best Practices, Tips, and Tricks

Getting Started with

Differences and Comparisons

Tags
Appium Mobile App Testing

Get answers on our Discord Community

Join our Discord community to connect with others! Get your questions answered and stay informed.

Join Discord Community
Discord