Getting Started with Appium for Android Java on Windows in 10 Minutes

Getting Started with Appium for Android Java on Windows in 10 Minutes

This is the first article from the new series dedicated to the mobile testing using Appium test automation framework. Here, I am going to show you how to configure your machine to test Android applications- prerequisite installations and setup of emulators. After that, you will find how to start your application on the emulator and perform actions on it.

What Is Appium?

Appium is an open source test automation framework for use with native, hybrid and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol. It is the “standard” for mobile test automation.

Machine Setup

1. Install Java Development Kit (JDK) version 7 or above

(version 8 recommended in order for UI Automation Viewer to work)

2. Set JAVA_HOME environmental variable to where Java JDK is installed

Open in explorer – Control Panel\System and Security\System then click Advanced system settings. Click Environmental Variables.

JAVA_HOME Environmental Variable

3. Add Java JDK bin folder to the end of Path environmental variable

Java bin PATH Variable

4. Install the Android Studio to install the Android SDK at its default location if it is not already installed: C:\Program Files (x86)\Android\android-sdk – follow the following guide 

5. Create a virtual device with the Android Virtual Device Manager

6. Install Node.js

7. Install Appium from the command line (skip if you install Appium Desktop)

npm install -g appium

8. Install Appium Desktop (optional)

Find Android App Info

Install APK to Virtual Device

ADB, Android Debug Bridge, is a command-line utility included with Google’s Android SDK. ADB can control your device over USB from a computer, copy files back and forth, install and uninstall apps, run shell commands, and more.

First, start the ADB shell using the command – adb shell.

Before automating your app, you may need to expect it and find some info about it. So, you need to install it on your virtual device. To do so, open the command line and execute the following command.

adb install pathToYourApk/yourTestApp.apk

To find the app package and current activity. Open your application on the virtual device and navigate to the desired view. Then open adb shell and use the following command.

dumpsys window windows | grep -E ‘mCurrentFocus|mFocusedApp’

ADB Shell Android Package and Activity Dump

Start Android App in Emulator

You need to make sure that the Appium server is started and listening on port 4723. 

private static AndroidDriver < AndroidElement > driver;
@BeforeClass
public void classInit() throws URISyntaxException, MalformedURLException {
  URL testAppUrl = getClass().getClassLoader().getResource("ApiDemos.apk");
  File testAppFile = Paths.get(Objects.requireNonNull(testAppUrl).toURI()).toFile();
  String testAppPath = testAppFile.getAbsolutePath();
  var desiredCaps = new DesiredCapabilities();
  desiredCaps.setCapability(MobileCapabilityType.DEVICE_NAME, "android25-test");
  desiredCaps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.example.android.apis");
  desiredCaps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
  desiredCaps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
  desiredCaps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.Controls1");
  desiredCaps.setCapability(MobileCapabilityType.APP, testAppPath);
  driver = new AndroidDriver < AndroidElement > (new URL("http://127.0.0.1:4723/wd/hub"), desiredCaps);
  driver.closeApp();
}
@BeforeMethod
public void testInit() {
  if (driver != null) {
    driver.launchApp();
    driver.startActivity(new Activity("com.example.android.apis", ".view.Controls1"));
  }
}
@AfterMethod
public void testCleanup() {
    if (driver != null) {
      driver.closeApp();
   }
}

After the driver is initialised we closed if the app is open. Then before each test, we launch the app and open the desired activity.

Start Appium Service

Instead of starting Appium server manually, we can start it from code.

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

Get Path to Test App

The apk file is copied from the Resources folder to the compiled binaries. This is how we get the path.

URL testAppUrl = getClass().getClassLoader().getResource("ApiDemos.apk");
File testAppFile = Paths.get(Objects.requireNonNull(testAppUrl).toURI()).toFile();
String testAppPath = testAppFile.getAbsolutePath();

Initialize Desired Capabilities

URL testAppUrl = getClass().getClassLoader().getResource("ApiDemos.apk");
File testAppFile = Paths.get(Objects.requireNonNull(testAppUrl).toURI()).toFile();
String testAppPath = testAppFile.getAbsolutePath();
var desiredCaps = new DesiredCapabilities();
desiredCaps.setCapability(MobileCapabilityType.DEVICE_NAME, "android25-test");
desiredCaps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.example.android.apis");
desiredCaps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
desiredCaps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
desiredCaps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.Controls1");
desiredCaps.setCapability(MobileCapabilityType.APP, testAppPath);

Find Android Locators

Using the Android SDK UI Automator Viewer, you can find the elements you are looking for. You can find it in the folder C:\Program Files (x86)\Android\android-sdk\tools\bin. Launch the following file – uiautomatorviewer.bat. Then click on the Device Screenshot and an image of the test app will appear.

Android UI Automation Viewer Windows

Find Android Locators with Appium Desktop

Appium provides you with a neat tool that allows you to find the elements you’re looking for. With Appium Desktop you can find any item and its locators by either clicking the element on the screenshot image or locating it in the source tree.

After launching Appium Desktop and starting a session, you can locate any element in the source. 

Appium Desktop Screen Inspector Android Windows

  • By ID

    AndroidElement button = driver.findElementById("com.example.android.apis:id/button");
    ```
    
-   #### By Class
    
```java
    AndroidElement checkBox = driver.findElementByClassName("android.widget.CheckBox");
    ```
    
-   #### By XPath
    
```java
    AndroidElement secondButton = driver.findElementByXPath("//*[@resource-id='com.example.android.apis:id/button']");
    ```
    
-   #### By AndroidUIAutomator
    
```java
    AndroidElement thirdButton = driver.findElementByAndroidUIAutomator("new UiSelector().textContains(\"BUTTO\");");
    ```
    

### Locate Elements inside Parent

```java
@Test
public void locatingElementsInsideAnotherElementTest() {
  var mainElement = driver.findElementById("android:id/content");
  var button = mainElement.findElementById("com.example.android.apis:id/button");
  button.click();
  var checkBox = mainElement.findElementByClassName("android.widget.CheckBox");
  checkBox.click();
  var secondButton = mainElement.findElementByXPath("//*[@resource-id='com.example.android.apis:id/button']");
  secondButton.click();
  var thirdButton = mainElement.findElementByAndroidUIAutomator("new UiSelector().textContains(\"BUTTO\");");
  thirdButton.click();
}

Gesture Actions in Appium

Swipe

@Test
public void swipeTest() {
  driver.startActivity(new Activity("com.example.android.apis", ".graphics.FingerPaint"));
  TouchAction touchAction = new TouchAction(driver);
  AndroidElement element = driver.findElementById("android:id/content");
  Point point = element.getLocation();
  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();
}

Related Articles

Java, Web Automation Java

Selenium WebDriver Tor Network Integration Java Code

For a long time, I wanted to write automation using the Tor Web Browser. My preferred automation framework is Selenium WebDriver. However, I found out that ther

Selenium WebDriver Tor Network Integration Java Code

Java, Kotlin, Web Automation Java

30 Advanced WebDriver Tips and Tricks Kotlin Code

This is the next article from the WebDriver Series where I will share with you 30 advanced tips and tricks using Java code. I wrote similar articles separated i

30 Advanced WebDriver Tips and Tricks Kotlin Code

AutomationTools, Free Tools, Java

Healenium: Self-Healing Library for Selenium-based Automated Tests

In this article, we're going to review a library called Healenium. It is an AI-powered open-source library for improving the stability of Selenium-based tests,

Healenium: Self-Healing Library for Selenium-based Automated Tests

Design Architecture Java, Design Patterns Java, Java

Facade Design Pattern in Automated Testing Java Code

In the series of articles Design Patterns in Automated Testing, you can read about useful techniques for structuring the automation test code. Today’s publicati

Facade Design Pattern in Automated Testing Java Code

Design Architecture Java, Design Patterns Java, Java

Fluent Page Object Pattern in Automated Testing Java Code

In my previous articles from the series Design Patterns in Automated Testing, I explained in detail how to improve your test automation framework through the im

Fluent Page Object Pattern in Automated Testing Java Code

Java, Kotlin, Mobile Automation Java

Getting Started with Appium for iOS Kotlin on macOS in 10 Minutes

The second article from the Appium Series is going to be about testing iOS apps. I am going to show you how to configure your machine to test iOS applications –

Getting Started with Appium for iOS Kotlin on macOS in 10 Minutes
Anton Angelov

About the author

Anton Angelov is Managing Director, Co-Founder, and Chief Test Automation Architect at Automate The Planet — a boutique consulting firm specializing in AI-augmented test automation strategy, implementation, and enablement. He is the creator of BELLATRIX, a cross-platform framework for web, mobile, desktop, and API testing, and the author of 8 bestselling books on test automation. A speaker at 60+ international conferences and researcher in AI-driven testing and LLM-based automation, he has been recognized as QA of the Decade and Webit Changemaker 2025.