Nowadays mobile apps market grows increasingly. User is able to do almost everything with the help of their mobile and tablet devices instead of their PC. That’s why there is an awful lot of apps that are developed and need to be properly tested. To avoid human mistakes and time consumption, to decrease time on regression testing it is common practice to automate some test scenarios. All the necessary tools required for starting automate testing of your Android mobile application are described in this article.

To create and run UI tests on Android the following tools should be set up:

  • testing framework that provides a set of APIs to build UI tests to test user flows within an app (Appium, Robotium, Espresso, Calabash)
  • Android Emulator ( Android Studio, BlueStack, Genymotion)
  • IDE ( IntelliJ IDEA, Eclipse)

Step 1: Appium setup

Appium is an open source test automation tool for mobile, hybrid and native apps. It could be used to automate any mobile app from any language and any test framework, with full access to back-end APIs and DBs from test code. Appium supports such platforms as iOS, Android, FirefoxOS. Appium uses JSON Wire Protocol (JSONWP) for interaction with Android and iOS apps via Selenium WebDriver API. Appium uses WebDriver and DesiredCapabilities, the same as Selenium. To install Appium you will need npm - default package manager for the JavaScript runtime environment Node.js.

The best way to install npm on Linux is to use brew (the Mac OS package manager for Linux). Do not install nodejs via apt-get, which will need sudo rights and appium will not work if node is installed as sudo user.

  • First of all - required dependencies. Paste the command below to terminal:

    sudo apt-get install build-essential curl git python-setuptools ruby

  • Now install linux brew with ruby. Paste the command below to terminal: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)"

  • Add to your .bashrc or .zshrc:

    export PATH="$HOME/.linuxbrew/bin:$PATH"
    
    export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
    
    export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"`
    
  • Now we can install node using linux brew:

    brew update
    
    brew install node
    
    brew link node
    

And fill free to make a cup of tea. It would take about 25 minutes or even more to install depending on your workstation power.

  • After a successful node installation Appium can be installed:

    npm install -g appium

  • To run appium restart terminal and type:

    appium

terminal's screenshot

Step 2: Android SDK

Download and setup Android SDK. Select instructions for Linux and then follow them step-by-step. After the first run of Android SDK Manager select necessary packages for needed Android versions.

Step 3: Android Emulator

As emulator we prefer to use Genymotion. On the one hand, it is very fast, simple and easy to use. On the other hand, Genymotion has lots of functionality and even supports GPS and wifi Internet in real time.

  • First of all install Virtualbox via Ubuntu Software Center on your workstation;

  • Navigate to genymotion.com and select plan. To be confident that this particular emulator satisfies your expectations we recommend you to select free “Basic” one and to try use it. Create an account and Download Genymotion package for Ubuntu;

  • Open terminal and run command:

    chmod a+x ./genymotion-2.7.2-linux_x64

  • Run Genymotion:

    ./genymotion-2.7.2-linux_x64

  • To select needed virtual device login with the user id and password, that you can register with the Genymotion website. Make sure that you select the same version of device as for Android SDK Manager;

  • Click on start and emulator will run.

screenshot

Step 4: IDE

Open IDE which you are used to. If you use maven don’t forget to add Selenium, TestNG and Appium to dependencies. Create folder apps where your .apk file will be stored. Also class like Appium Setup should be created with DesiredCapabilities and initialisation of AndroidDriver.

Step 5: UIAutomatorviewer

For analysis of UI of application UIAutomatorviewer could be used. It is the part of Android Studio that was set up in step 2. This tool allows to inspect the UI of an application in order to find the layout hierarchy, to view the properties associated with the controls and to expose the Id and other attributes of the element. You can find documentation by link.

The main advantages of using UIAutomatorviewer is:

  • Independence on screen resolution;

  • No coordinates dependence;

  • External buttons on the device can be used; Ability to use device’s external buttons

If you like, you can also use Appium Inspector do define elements hierarchy and get xpath of elements using their attributes.

Useful links:

  1. Official documentation for Android platform
  2. Official page of Appium
  3. Official page of Genymotion