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

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

Introduction

In this part of the post I’m going to be focused on the tools needed for inspecting the elements. If you haven’t checked the previous parts, you can check part 1 and part 2 of this post. For inspecting the application elements you can use the Appium built inspector. The Appium built inspector comes built with the Appium application, and in order to use the Appium inspector, the application has to be opened i.e. the inspector cannot be opened separately through Terminal.

Appium application

Before getting in details with Appium inspector, I’m going to talk about the configuration of the Appium application. In the previous post I have talked about the configuration that it is used for the automation suite to run the scenarios. Setting the configuration in the Appium application is UI friendly, and I’m going to cover the fields that are required to get you started inspecting the elements of your Android application. On the image below it is shown the Appium application, and the available options for configuring the Appium application, to connect with the Android application.

The configuration menu can be opened by clicking the Android button at the top of the Appium application. I’m briefly going to explain the fields that I have configured for automating the demo application.

  • App Path – In this field should be placed the location of the .apk file that has to be opened in the emulator / device.
  • Package Name – This field should contain the package name of the application, and this should be provided by the developer of the application. In case you want to find the package name you can use the Package Browser in DevTools application.
  • Launch Activity – This field contains the name of the activity that has to be invoked to inspect the elements. All available activities of the application can be accessed with the Package Browser in DevTools application.
  • Platform Name – This field contains the name of the platform on which the application is going to be run. In this case the platform name should be set to Android.
  • Automation Name – This field contains the name of the automation that is going to be used. In this case should be set to Appium.
  • Platform Version – In this field should be placed the Android version on which the application is going to be run. In my case the platform version is set to 7.1.1 Nougat (API Level 25).
  • Device Name – This field contains the name of the device. In the previous post I have given an example how to get the device name of your device/emulator.
  • Language – The language of your device/emulator.
  • Locale – The locale of your device/emulator.

In the Advanced tab it is required the path of the Android SDK to be set.

  • Android SDK Path – This field contains the path to the Android SDK installed on your system.

Running appium inspector

The Appium inspector can be run by clicking the magnifier at the top of the Appium application. But before starting the Appium inspector make sure that you have started the Appium server through the Terminal as discussed in the previous post. This is going to ensure that you are running the latest version of Appium, and you are not going to have issues executing the automation tests on Android 7.1.1.

Once the Appium server is running open the Appium application, and fill the Android configuration as discussed above. Once this is done, don’t click the Launch button, because the Appium server is already started, instead at this point click the magnifying button. If everything is configured properly the Appium inspector should be launched, and snapshot of the current activity should be displayed. In the image below it is displayed the Appium inspector.

The Appium inspector displays the properties of the UI element by clicking on the snapshot. When the UI element is clicked the following properties are presented:

  • content-desc – The content description of the element.
  • type – The type of the element for example: TextView, Button, etc.
  • text – The text of the element.
  • index – The index of the element.
  • enabled – True if the element is enabled, False if the element is disabled.
  • location – Location of the element on the screen.
  • size – Size of the element displayed on the screen.
  • checkable – Whether the element is checkable.
  • checked – True if the element is checked, False if the element is not checked.
  • focusable – Whether the element is focusable.
  • clickable – Whether the element reacts to clicks.
  • long-clickable – Whether the element reacts to long clicks.
  • package – The package of the application.
  • password – Whether the text in the element is password.
  • resource-id – The id of the element.
  • scrollable – Whether the element can be scrolled.
  • selected – True if the element is selected, False if the element is not selected.
  • xpath – The plain xpath of the element.

On the image below it is shown an example, when an UI element is selected, and it’s properties are displayed.

The properties of the UI element can be used for locating the elements, or validating the scenario. Mostly the elements are located by the id, which is set by the developers. But in some cases the UI may be complex, or it may be created in a dynamic way, and in this situation the elements should be located by other properties, or by xpath (which is my favorite locator strategy).

Conclusion

With this post I’m going to end the Appium automation for Android apps, and I would recommend Appium for all black box testers. The benefits of using Appium is that can be used with multiple platform, and multiple platform versions. Currently there are some drawbacks when configuring Appium with your application, but with couple of tries you are going to be more familiar and you are going to start to love it. With the previous posts, and the example that I have uploaded I hope you are going to get familiar with the code structure, and how to optimize your code to be more reusable, configure the Appium server, and inspect the UI elements.

One thought on “Automation tests for an Android app using Appium (Part 3)

  1. Pingback: Testing Bits – 9/10/17 – 9/16/17 | Testing Curator Blog

Leave a Reply

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