Configure & Running Simple Appium Test

Novita Tamba
5 min readMay 26, 2021

Appium is open-source tools used to automate mobile application (native, web & hybrid mobile application). Automation script can be run in multi-platform such as Android, IOs and Windows with minimal changes.

Appium uses Client-Server Architecture.

Appium Client / WebDriver Script:

  1. Can be written using multiple programming languages such as Java, Ruby, Python, PHP, C#, and JavaScript.
  2. The client will send the appropriate HTTP request to the Appium Server using JSON Wire Protocol.

Appium Server :

  1. Appium is an HTTP Server written using Node.js platform.
  2. JSON Wire Protocol will convert request from the client into HTTP REST base Request which is understood by Appium Server.
  3. Appium Server creates a new test session and invokes the Native Framework/Driver Specific Setup (XCUITest, UIAutomatior, etc) and then run commands/steps on a Mobile Application.

Prerequisites to use Appium on MacOs

There are two ways to install Appium, it can be via NPM or by downloading Appium Desktop and double click on the .dmg file to install. Appium Desktop provides a graphical interface to set options, start/stop the server, see the logs, etc. The installation also bundled Node runtime so we don’t need to use Node/NPM to install Appium.

However, just in case you prefer using NPM, make sure Homebrew is already installed first. Homebrew is used to installs packages to their directory and then symlinks their files into /usr/local. To do that, open Terminal and type the following command:

install homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

install Node.js

brew install node

install appium

npm install -g appium

verify installation

After successfully installed the Appium Dekstop, Install Appium Doctor. This tool is used to verify whether all the dependencies required before starting Appium is met. Open a terminal, and type the following command:

check all dependencies

appium-doctor

check android/ios dependencies

appium-doctor -h -ios

appium-doctor -h -android

Appium Doctor will display what dependencies is missing and recommend optional manual fixes as shown above. See the details on ### Diagnostic ### and ### Optional Manual Fixes ### sections. Try to download all necessary libraries in order to successfully run the appium desktop or npm.

Create Automation Project

To begin automation test, create Maven Project from IDE. This project will be acting as an Appium Client. We can freely choose what programming language/library however in this case, I prefer using Java and complement the library using Selenium & Appium Library from Maven Repository. Fyi, Maven Repo is a central repository where all the project jars, library jar, plugins or any other project specific artefacts are stored. Copy the xml code from Maven Repository to the pom.xml file and click retrieve. It will automatically download the library into the Local Project. The pom.xml will be as shown below:

Then, choose one installed application in your mobile devices to automate, and create a main class to represent actions steps and desired capabilities. The sample code much more like this:

In the AppiumTest.Java, there is information about Desired Capabilities and several lines of code that represent human activities that use calculators, such as Click Buttons.

Desired Capabilities are keys and values encoded in a JSON object, sent by Appium clients to the server when a new automation session is requested. Desired Capabilities can be scripted in the WebDriver test or set within the Appium Server GUI (via an Inspector Session).

Some important capabilities are demonstrated in the following example:

Some information above (deviceName, platformName, platformVersion) could obtain from your mobile testing devices. By tapping around 7 to 8 times on Build Number from Settings > Software Information on your mobile devices.

Value for udid could acquire by connecting your devices to your PC/Notebook and open the terminal then type the following command : adb devices.

Information related to appPackage and appActivity could be found using APK Info (third party application that can be installed from PlayStore).

Connect your mobile testing devices to PC and execute the AppiumTest.Java directly from IDEA. The code will send request to Appium Server and call the Calculator Application on your devices. Then execute steps as written in the runner class, which are click 9 * 2 and display the result.

Done, environment setup and first project running successfully ✌️

--

--