App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

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

Top Appium Commands every Developer must know

Mobile phones have evolved from communication devices to a gadget that can basically fulfill a common man’s requirement- from online shopping to online food ordering. This is done via Mobile Applications that form the core of a number of businesses around the globe. Due to this, there is a need to develop quality Apps which has led to an increase in demand for Mobile Application testing

Mobile Application testing is either done Manually or is Automated. Mobile Application tests can be automated via open-source tools such as Appium. Every automation tester or developer should be familiar with different Appium commands in order to create robust mobile apps. However, knowing all the commands is a challenge, hence, a quick reference cheat sheet will be quite helpful here.

What is Appium?

Appium is a test automation tool used for testing Mobile Applications. It’s open source and supports various platforms such as iOS, Android, and Windows. It allows users to test various types of Mobile Applications such as:

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

Learn about the difference between Native, Web, and Hybrid Apps in detail.

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

Appium Commands Cheat Sheet


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

  • Ensure that the Java Library is installed for Appium.
  • Download and install Maven following the steps from the official website.
  • Import statements for various commands can be as follows. Add them to your program as per the commands in use:
  1. import org.openqa.selenium.WebElement;
  2. import org.openqa.selenium.JavascriptExecutor;
  3. import;
  4. import;
  5. import org.openqa.selenium.remote.RemoteWebElement;
  6. import org.openqa.selenium.remote.DesiredCapabilities;
  7. import org.openqa.selenium.Dimension;
  8. import org.openqa.selenium.By;
  9. import org.openqa.selenium.Keys;
  10. import org.openqa.selenium.WebDriver;
  11. import io.appium.java_client.pagefactory.*;
  12. import io.appium.java_client.ios.IOSElement;
  13. import io.appium.java_client.AppiumDriver;
  14. import io.appium.java_client.MobileElement;
  15. import;
  16. import io.appium.java_client.ios.IOSDriver;
  17. import io.appium.java_client.MobileElement;
  18. import io.appium.java_client.MultiTouchAction;
  19. import io.appium.java_client.TouchAction;
  20. import;

Here are the Basic Appium Commands in the Java version:

Initialize Desired Capabilities

  • Create local Appium Server instance

 appiumLocalService = new AppiumServiceBuilder().usingAnyFreePort().build(); 

  • Start local Appium Server instance


  • iOS Capabilities


DesiredCapabilities caps = new DesiredCapabilities();

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

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

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

caps.setCapability(“platformVersion”, “15.6”);

  • Android Capabilities


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/”);

  • Install an app on Android


DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“appPackage”, “”);

caps.setCapability(“appActivity”, “”);

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(““), caps); //This URL points to the local server

  • Initialize Android remote driver

driver = new AndroidDriver<AndroidElement>(new URL(““), caps); //This URL points to the local server

Locator Strategies

  • Locate by ID


  • Locate by Accessibility ID


  • Locate by Class (Single Element)


  • Locate by Class (Multiple Elements)


  • Locate by AndroidUIAutomator (UI Automator 2)

driver.findElementByAndroidUIAutomator(“new UiSelector().textContains(\”BUTTON\”);”); 

  • Locate by Image


  • Locate by XPath – iOS


  • Locate by XPath – Android


App & Device Actions

  • For Handling Alert



  • For Basic Input operations;



  • For Changing orientation


  • 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:


.withPosition(PointOption.point(x, y));

  •  For Pressing:, y)); 

  • For Waiting:



  • For Moving:

touchAction.moveTo(PointOption.point(x, y));

  • For Long Press:

touchAction.longPress(PointOption.point(x, y)); 

  • For Releasing and Performing:



  • For Toggle services





  • For Soft keyboard actions

driver.isKeyboardShown(); // returns boolean


  • For Locking device

driver.isDeviceLocked(); // returns boolean



  • For Notifications


  • 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 

Advanced Commands – both iOS & Android

  • For Multitouch actions

TouchAction actionOne = new TouchAction(driver); 

  • For Pressing at a point:, 10)); 

  • For Moving to a point:

actionOne.moveTo(PointOption.point(10, 100)); 

  • For Releasing



TouchAction actionTwo = new TouchAction(driver);, 20));

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


MultiTouchAction action = new MultiTouchAction(driver);




  • For Swipe using TouchAction


TouchAction touchAction = new TouchAction(driver);

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

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

Dimension size = element.getSize(); + 5, point.getY() + 5))


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

point.getY() + size.getHeight() – 5)).release().perform();

  • For Scroll using Javascript Executor


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);


driver.findElementByAndroidUIAutomator(“new UiScrollable(new

UiSelector()).scrollIntoView(new UiSelector().text(\”Views\”));” );

  • For taking Screenshot


 // 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



Advanced Commands – iOS 

  • For shaking device


  • For adding photos

driver.pushFile(“img.jpg”, new File(“path to img.jpg”));

  • For sending voice commands to SIRI


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


JavascriptExecutor js = (JavascriptExecutor) driver;

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

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

driver.executeScript(“mobile: pressButton”, args);

Advanced Commands – Android 

  • For setting Battery Percentage


  • For setting the state of the battery charger to connected or not



  • 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(“”, “cpuinfo”, 6); // returns


App Management – iOS 

  • For installing an app


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

driver.executeScript(“mobile: installApp”, args);

  • For verifying if the app is installed


args.put(“bundleId”, “com.myapp”);

(boolean)driver.executeScript(“mobile: isAppInstalled”, args);

  • For launching the app


args.put(“bundleId”, “”);

driver.executeScript(“mobile: launchApp”, args);

  • For switching the app to foreground


args.put(“bundleId”, “com.myapp”);

driver.executeScript(“mobile: activateApp”, args);

  • For checking current state of the app


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


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


args.put(“bundleId”, “com.myapp”);

driver.executeScript(“mobile: removeApp”, args);

App Management – Android

  • For installing an app


  • For verifying if the app is installed


// returns bool

  • For launching the app


  • For starting activity

driver.startActivity(new Activity(“”,


  • For getting current activity

driver.currentActivity(); // returns String 

  • For getting current package

driver.getCurrentPackage(); // returns String 

  • For switching the app to foreground


// Runs for 10 seconds

  • For checking current state of the app


// returns Application State

  • For getting app strings

driver.getAppStringMap(“en”, “path/to/file”);

 // returns Map<String, String>

  • For closing the app


  • For reseting the app


  • For terminating the app

driver.terminateApp(“”); // returns bool 

  • For removing the app


Appium mobile testing has become indispensable with the ever-increasing demands of fast and reliable testing that spans over various platforms, devices, and versions. Appium offers feasibility, flexibility, and cost-friendliness above other testing methods, which enables both development and testing teams to deliver great user experiences within the continuous delivery approach.

To perform mobile app testing using Appium, you could try apps like BrowserStack App Automate, which provides thousands of real mobile devices for testing. Using BrowserStack QAs can access real devices with real operating systems in order to run automated tests via Appium.

Try BrowserStack for Free

Appium Mobile App Testing

Featured Articles

Appium Tutorial for Mobile Application Testing

Desired Capabilities in Appium

App & Browser Testing Made Easy

Seamlessly test across 20,000+ real devices with BrowserStack