Mobile Test Automation In Java With Appium- Part 1

Mobile Test Automation In Java With Appium- Part 1

2019 / 9 / 5

Load Testing, Performance Testing, Best Practices

Appium is an open-source test automation tool which allows you to write functional tests to automate iOS and Android mobile applications. One big advantage of Appium over other test automation tools is that Appium tests can be written in any language that has Selenium Client Library including Python, Ruby, Node.js.
Appium supports native, hybrid and web application testing and also supports testing on emulators, simulators and real devices.
It supports cross-platform application testing i.e. single API works for both Android and iOS platform test scripts.

In this post we will walk through the steps involved in testing the Android sample app. We will be discussing this blog post in 2 parts: Part 1: Getting environment setup with Appium and TestNG.
And Part 2: Writing your Test Cases.

Part 1: Getting environment setup with Appium and TestNG.
The most difficult part of getting automated mobile testing, is to determine the correct set of tools to use, which version to use and how to install everything correctly so that it works seamlessly together. Sadly, it is not that easy, not a job of just a few clicks to install everything you need.
In this tutorial, we have discussed the recommended tools, that we will be using to show how to automate an Android app. But, there are plenty of other variations also. Below is a comprehensive list of all the tools, which we will be discussing one by one in detail.

  1. Chocolatey
  2. Node & NPM
  3. JDK
  4. Android Studio and Android SDK
  5. Appium
  6. Appium Doctor
  7. Gradle
  8. Maven
  9. Eclipse
  10. TestNG

Steps to install Chocolatey:
Chocolatey is simply a package management software that makes it easier for us to install and manage other software.

  1. Go to the link
  2. Open command prompt or powershell using administrative privileges.
  3. From the start menu search command to open a command prompt and search power to open powershell.
  4. For both the cases right click and select “Run as administrator” option.

Installing Chocolatey

Installing Chocolatey

  1. Click on “Yes” button in the dialog that appears.

  2. In case of command prompt enter the following command to install chocolatey-

    @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString(''))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" 
  3. In case of powershell enter following command to install chocolatey:

    Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(''))

Steps to Install Node and NPM:
Node is a javascript run-time environment and npm is the node package manager. And why we need these? Because Appium is a node application.

  1. Use chocolatey to install Node. NPM comes installed with Node. SO, you don’t need to install it separately.

  2. Use command:

    choco install nodejs.install

Installing NodeJS

Steps to install JDK and set JAVA_HOME:
Since our tests will be written using Java language, so we will be requiring JDK- Java Development Kit.

  1. Go to the link and Download JDK.
  2. Double click the JDK and follow the installation steps.
  3. Next step is to setup the Path variable in System Variables.
  4. Set Path variable to the path of bin folder in jdk directory like “C:\Program Files\Java\jdk-12.0.2\bin”
    NOTE: Replace this with path of bin folder in your jdk directory. This is for illustration purpose only.
  5. Open a command prompt and type java. If you can see some output, it means the path is set correctly and now jdk ready for use.

JAVA jdk

Steps to install Android Studio and Android SDK:
We need Android Studio to write and run tests on Android Apps and Devices.

  1. Go to the link and Download Android Studio.
  2. Launch Android Studio and complete the setup process until you reach the welcome page.
  3. You can find the SDK Manager icon from the top rightmost menu.

Android Studio

  1. From the “SDK Tools”, ensure following options are selected:
    a. Android SDK Build-Tools
    b. Android SDK Platform-Tools
    c. Android SDK Tools
    d. Intel x86 Emulator Accelerator (HAXM installer)
    e. Android Support Repository
    f. Google Repository

  2. Click “OK” and install if there are any additions.

  3. Edit the Path Variable under the System Variables to add path of Sdk folder under Android directory “C:\Users\Rashi\AppData\Local\Android\Sdk\”

Steps to install Appium:

Appium is an open-source test automation framework and the hero of today’s tutorial.

  1. Open the Node.js command prompt from the start menu.

  2. Type the following command in the terminal:

    npm install -g [email protected]
  3. Successful installation of appium can be checked by entering the command- appium in command prompt. If no error message is displayed, it means appium is successfully installed.

Steps to install Appium Doctor:

Appium Doctor is the mini software, whose job is to check whether all of the preconditions for the execution of appium are true or not.

  1. Open the Node.js command prompt.

  2. Type the following command in the terminal :

    npm install -g appium-doctor

Installing Appium

  1. To check the successful install, type the command: appium-doctor in the terminal.
  2. The output will be like this:

Appium Doctor

Steps to install Gradle:
Gradle is used to create apk and jar files. It is an open-source build automation system.

  1. Open the command prompt.

  2. Type the following command:

    choco install gradle

Installing Gradle

  1. This command will automatically edit the Path variable under Environment Variable to add Gradle Path.

Steps to install Maven:
Maven is a tool used to build and manage Java based projects.

  1. Open the command prompt..

  2. Type the following command:

    choco install maven

Installing Maven

  1. This command will automatically edit the Path variable under Environment variable to add path of Maven.

Steps to install Eclipse:
Eclipse is an Integrated Development Environment (IDE). We are going to use eclipse to write, compile and run test scripts.

  1. Go to the link and Download the Eclipse.
  2. Double click the downloaded file and follow the steps to install eclipse.

Steps to install TestNG:

  1. Open the Eclipse.
  2. Go to the Help option in the top main horizontal menu.
  3. Select Install New Software from the list.
  4. Paste “” in the “Work with” field and press enter on the keyboard.
  5. Eclipse will show the name of the relevant package.
  6. Select the checkbox next to “TestNG” and click on Next.


  1. Eclipse will take a while to download and install TestNG. You will see a prompt to restart the Eclipse.
  2. Restart Eclipse and now you are ready for the actual coding.

With this we are done with all the installation. Now it’s time to get your setup ready and get started with the actual coding of test cases in the next blog post.

You might also like