Appium - Mobile Apps Automation Tool

Appium – free, open source tool for automatic testing of apps

The mobile app market keeps growing. Thousands of new apps are launched every day. People are starting to turn away from PCs and laptops and use their smartphones for almost everything – work, sports, entertainment, etc…

For app developers, the growing number of mobile apps means a constant increase in requirements for Quality Assurance for both new and existing software.

Testing of mobile applications is quite different from testing web apps and to be economical requires automation. One very interesting tool for automatic testing is Appium, which I will try to briefly describe.

What is Appium tool?

For starters – Appium is one of the most popular tools for automating application tests on mobile devices.

Appium benefits

There are multiple reasons why testers and developers choose Appium. To name a few:

  • it’s an open-source tool,
  • can be used to automate native, web and hybrid applications tests on Android and iOS platforms,
  • “cross-platform” which means Appium API can be used to write tests in carious languages,
  • it uses WebDriver library, which has been expanded by additional functions useful for mobile test automation.

The idea behind Appium is to enable automation of tests without the need to recompile the application. We are also not limited to a single programming language. What’s more, we do not have to reinvent the wheel when it comes to the automation API. Best thing is you get all this in an open source solution.

Appium architecture

Appium’s architecture is very simple. First of all, it’s worth pointing out that Appium is based on client-server architecture. The client connects to the Appium server in the form of a JSON object via the HTTP protocol. Then, the server creates a session, thus giving the client an individual session number (ID), which is active for the duration of the server’s operation. Then tests are run as part of the session you have created.

Source: PaktPub

Installing Appium

The installation of the Appium testing tool is very simple. We can do it in two ways:

  1. Using the npm manager by executing the following command:
    npm install -g appium
  2. By downloading the GUI interface installer.

Writing automatic tests using Appium – Quickstart Tutorial

To start writing automated tests using Appium, we need a number of tools. The list below shows the tools and settings you will need.

  1. Java – we install and set JAVA_HOME,
  2. Android SDK – we download and set ANDROID_HOME,
  3. Appium – install and run,
  4. IDE eg Eclipse with maven and testing – install and run,
  5. A device (or an emulator/simulator) with Android / iOS system – connect the device to a computer via a USB or WIFI. Check device visibility via adb devices.
  6. Application for testing.

We run the Appium on the 0.0.0.0 host and the default port 4723.

Configuring the connection to Appium server

In Eclipse, create a new project. Start by configuring the connection to Appium server.

Separate configurations are needed for Android and for iOS. For proper configuration, you will need information about the device on which tests are to run.

For Android, we use UiAutomator2 Driver. Here’s an exemple configuration:

capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Emulator");
capabilities.setCapability("device", "emulator-5554");
capabilities.setCapability("platformVersion", 8.0.0);
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("automationName", "uiautomator2");
capabilities.setCapability("appPackage", "pl.itcraft.application");
capabilities.setCapability("appActivity", "pl.itcraft.application.activity.LauncherActivity");

For iOS, we use XCUITest. Example configuration:

capabilities.setCapability("deviceName", "iPhone X");
capabilities.setCapability("platformVersion", "12.0");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("app", app.getAbsolutePath());

Lastly we initialize the Android Driver:

driver = new AndroidDriver(
  new URL("http://0.0.0.0:4723/wd/hub"), 
  capabilities
);

for iOS:

driver = new IOSDriver(
  new URL("http://0.0.0.0:4723/wd/hub"), 
  capabilities
);

For this example, we will use Page Object Model and Page Factory.
Page Object Model is a pattern in which each application screen is reflected as a separate class. Within a given class, we add elements and methods that perform operations on elements.
We use Page Factory as a support for the Page Object pattern initializing the elements and for assigning Android and iOS locators to one variable.

For example, we add the loginScreen.java class to the login screen

@iOSFindBy(accessibility = "login")
@AndroidFindBy(id = "loginInput")
MobileElement loginInput;

@iOSFindBy(accessibility = "pass")
@AndroidFindBy(id = "passInput")
MobileElement passwordInput;

@iOSFindBy(accessibility = "loginButton")
@AndroidFindBy(id = "loginBtn")
MobileElement loginButton;

public void loginApp(String login, String password) {
  loginInput.sendKeys(login);
  passwordInput.sendKeys(password);
  loginButton.click;
}

The test begins with the @Test annotation from the TestNG library. Then, using the written method, we create a test, adding a check at the end to ensure we have been logged in – we do this by checking the content of the message. The test written in this way will be made for both Android and iOS applications.

@Test
public void firstTest() {
  loginScreen.loginApp(“test”, ”test”);
  baseScreen.checkSuccessfulLogin();
}

Summary

The main advantages of Appium mobile app testing tool are that it’s free, open-source and multi-platform. The main feature making Appium a top choice is that using page object and page factory, we can have one test code, written in one of several popular languages, eg Java, C #. This code performs tests on both Android and iOS.

A big plus is the popularity of Appium, with the community providing extensive information and support.

5 (100%) 5 vote[s]
Łukasz Górski, QA Engineer

Lukasz has been the QA engineer with itCraft for over 5 years now, designing and executing both manual and automatic tests as well as supervising the work of our QA team. He is our top mobile app tester with extensive experience and capabilities. When not working, he fills his time running, cycling and working out.