Automation tests for an Android app using Appium (Part 2)

Automation tests for an Android app using Appium (Part 2)

Introduction

In the previous post we have talked about the requirements for appium, the code structure of the project, running the first scenario, and going through some of the code. In this post I’m going to talk about the configuration in the project, how to set the appium server, and set your emulator for this example.

Setup Appium Server

There are two ways to setup the server:

  1. Through the Appium application
  2. Through Terminal

The easiest method is option 1, and this method is recommended when you are learning appium, but this method has downsides with newer Android versions. I would recommend using option 1 for Android versions below Android Nougat i.e. 7.0. If you try to use the Appium application with Android version 7.0 and later you are going to face issues. For the example described in part 1 I have used option 2, and the reason for this is that I’m using an emulator with Android version 7.1.1 for testing my application.

In order to install the latest Appium server version use the following command:

npm install -g appium

Once the Appium installation is finished make sure that appium is properly installed. On OSX you can check with the following command whether the apium server is going to start:

./node_modules/.bin/appium

If Appium is properly installed, this command is going to invoke the appium server, and the output result should be as described in the screenshot.

Starting Appium Server with Terminal.

 

Setup the configuration

For this step to be more clear download the code and open the file config_app.properties:

explicit.wait=30
application.path=app/material-demo.apk
base.pkg=com.csform.android.uiapptemplate
appium.server.port=4723
application.activity=.MainActivity
automation.instrumentation=Appium
browser.name=Android
platform.name=Android
device.name=emulator-5554
platform.version=7.1.1

I’m going to explain the properties in the configuration file, and how to use them when automating and Android application.

explicit.wait – This property is used to indicate the explicit wait time for locating the element.
application.path This property is used to hold the location of the .apk file that has to be installed. If the .apk file is already installed or your tests does not require the application to be installed every time when a test is executed, this property can be left empty.
base.pkgThis property is used to hold the package name of the Android application.
appium.server.port – In this property add the Appium port, the default value is 4723.
application.activity – In this property add the launcher activity of the Android application.
automation.instrumentation – In this property is set the instrumentation that is going to be used for automating the scenarios. In this case should be set as Appium.
browser.name – In this property is set the browser which is going to be executed for the automation. For the current example this field is obsolete, and it is not needed.
platform.name – In this property is set the platform name that is going to be used, in this case should be set with Android.
device.name – This property contains the device name on which the automation tests that are going to be executed. (I’m going to describe below, how to list all devices)
platform.version – This property contains the Android version of the device, on which the automation tests are going to be executed.

If you have an emulator running or connected device, you can find the device name with the following steps:

  • Open the directory of the Android SDK.
  • Navigate to the folder platform-tools, and open Terminal application in this directory.
  • Execute the following command:./adb devices

This command is going to list all connected devices, or running emulators as shown in the image below.

The emulator

For Android you can create the emulator by using the Android Virtual Devices (AVD), or through Android Studio which uses the AVD as wrapper. In my case I’m using Android Studio for creating the emulator, because it offers emulator with predefined configurations. For the current example I’m using the Google Pixel XL emulator running on Android 7.1.1.

In cases when you need specific configuration for your Android emulator, you would have to create the device specification. This could be easily achieved in Android Studio, by creating New Hardware Profile, and later this profile can be used when creating the emulator.

Before executing the automation scenarios the emulator has to be ready, this can be achieved with the following steps:

  • Open the directory of the Android SDK.
  • Navigate to the folder tools, and open Terminal application in this directory.
  • Execute the following command:./emulator -avd EmulatorName
  • In your case you should replace EmulatorName with the name of your emulator.

Already there

Before going further I would suggest playing a little with the Appium server, and the Android emulator to get more familiar. That is going to help you for inspecting the Android elements, and resolve the issues that are going to occur during the configuration of the Appium server. In the next post I’m going to be focused on inspecting the elements, using the Appium inspector.

Leave a Reply

Your email address will not be published. Required fields are marked *