Marketing5 min read

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

Łukasz Górski

QA Engineer

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…

Table of contents

  1. What is Appium tool?
    Appium benefits
  2. Appium architecture
  3. Installing Appium
  4. Writing automatic tests using Appium – Quickstart Tutorial
  5. Summary

For app developers, the growing number of mobileapps 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 native, mobile web, and hybrid applications on iOS mobile, Android mobile, and Windows desktop platforms. Importantly, Appium is “cross-platform”: it allows you to write tests against multiple platforms (iOS, Android, Windows), using the same API.

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.

Appium architecture view
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.

Appium interface view

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.


Łukasz Górski

QA Engineer

Post article


5/5 - (6 votes)

Got a project? Let’s talk!

Contact us