How to Automate Android Applications Using TestComplete Tool

Automating Android Applications using TestComplete (Part-III)

In last two TestComplete tutorials we saw the TestComplete introduction and Data Driven Testing using TestComplete. In this tutorial, let us continue learning this tool with a new feature – how to automate Android Applications.

In this modern world, smartphones are playing a very important role in our day to day life.  With frequent updates in technologies and numerous devices available, it becomes a very hectic task for developers and testers to check their application’s compatibility.

Tools such as TestComplete can increase test coverage and improve test effectiveness. We have some basic concepts of TestComplete in the previous tutorials.

In this tutorial, we will look into the following

What You Will Learn:

What is Android?

Android was initially developed by Android Inc. which was bought by the tech giant Google in 2005. Android is an open source (freely available) operating system, particularly used for touchscreen mobile devices such as phones, tablets, etc. Basically, Android is based on Linux kernel.

An Android application is a software which runs on the Android platform. That platform could be anything such as a mobile device, tablet, etc that supports touchscreen functionality.

Software required to automate Android application

 To being with, we will have to prepare our system and install the necessary software so as to configure TestComplete so it can create automated tests for Android applications.

You will have to install the following

Let us learn to install the above-mentioned software one by one.

Java JDK

1) Downloading and Installing Java on the computer

(Note: Click on any image for enlarged view)

 2) Configuring Java JDK in Windows

Once Java is downloaded and installed it needs to be configured for the computer and with the TestComplete tool. We will learn to configure Java on both environments.

Java JDK can be configured by setting build path. Generally, there are two ways to do that

Here we are applying permanent way to set build path:

Let’s start!!! 

1) Right click on My Computer icon on your desktop and select Properties

2) Open ‘Advanced’ system settings on the left side of the screen

3) Go to ‘Advanced’ tab

4) Click on Environment Variables button

5) Under user variables section click on ‘New’

6) In variable name type ‘path’ now Go to bin folder (C:\Program Files (x86)\Java\jdk) or the path where java is installed and copy the path of the bin folder

7) Now paste the path of bin folder in variable value

8) Click Ok button

Note: To verify if the installed and configured Java works correctly, open command prompt and type java -version in the command line. Verify if Java version is displayed on executing the command.

Why we have to set Java Class Path?

To execute Java-based programs javac and java commands are used. By specifying the path in the environment variable, we are specifying the path where these commands are located in the operating system.

Since bin folder contains all the executable binary files, we have specified the path of the bin folder in the environment variables.

Android SDK

1) Download and install Android SDK

  2) Configuring Android in Windows

To create an automated script we need to configure the Android SDK in our operating system and in TestComplete.

Note: To verify if the installed and configured Android works correctly, open command prompt and type android on the command line. Verify the SDK Manager is launched on executing the command.

Select other required packages from the SDK Manager and click on Install Packages as shown in the image



3) Configure Java JDK and Android SDK to TestComplete

By default, Android and Java will be configured to TestComplete. But in some cases, if this does not happen then we need to set path manually.

Follow steps to configure Android and Java to TestComplete

Note: If the Mobile option is not visible in Engines then you need to enable the mobile extension in TestComplete.

Follow steps to enable mobile extension

Install Google USB Drivers

Follow steps to install Google USB Drivers on Windows

  1. Connect your Android device to the computer through the USB port
  2. Right Click on My Computer and click on Manage
  3. Select and click on Device Manager in the left partition
  4. Select Portable Devices
  5. Right-click on the device name and select Update Driver Software
  6. Click on Browse my computer for driver software
  7. Browse to the following folder – C:\SDK\extras\google\usb_driver
  8. Click Next to install the driver.
  9. Thus, we have installed Google USB Drivers on our operating system.

Preparing Mobile Device for test

To run Android test with TestComplete you need to prepare your Android device for testing and we call it as “Test Ready”.

a) Enable Developer Options on Android Device

Follow steps to enable developer options on Android Device:

  1. Navigate to Settings option
  2. Go to About phone/tablet
  3. Repetitive tap Build number 7 times
  4. By doing so you will notice an extra option in your menu named “Developer Option”

Tap Developer option in Settings and enable following Options:

1) USB debugging: By enabling USB debugging you ensure that proper communications get established between the device and Android Debug Bridge also abbreviated as ADB.

2) Stay awake: By enabling Stay Awake we are preventing the device from entering the sleep mode during test execution.This feature is available on all Android devices.

b) Create Test Project for Android Application

Let us Begin with creating our first test project to automate Android application using TestComplete

1) Select File –>New –>New Project

2) Enter the name of the project. Click Next

3) On the next page of the wizard, select Android Applications. Click Next

4) On the next page of the wizard, we need to add our Android application to the project

5) To add the application to the project, click on Add and browse to the location of the application where it is saved

6) For demo purpose, we can use the application provided by SmartBear at the following location

C:\Users\Public\PublicDocuments\TestComplete12 Samples\Mobile\Android\Orders\Orders Application\bin\Orders.apk

7) Once we have selected our platform in the previous step, project, creating wizard will take us to Test visualize page, where we can enable/disable the Test Visualizer functionality. Click on Next

8) Now we need to specify the scripting language for our project-JavaScript, JScript, Python, VBScript, DelphiScript, C#Script, C++. After selecting the scripting language click Finish

Thus, our project to test an android application is ready.

About Tested Application

In this tutorial, we have used an android application provided by along with the TestComplete. This Application is for managing orders. Users can create an order, modify or delete existing purchase orders.

This application should be installed on the device which will be used for automated testing.

How to record our test in TestComplete?

Once we are done with setting up the environment and languages to automate applications then recording a test is a similar process as we had implemented for web-based applications.

To start recording below are the following steps

1) Click on Append to test, as shown in the image below

Note: Only the interactions performed on the mobile screen, displayed on the window will get recorded in the TestComplete tool.

2) A recording panel as shown in the image will be displayed, it confirms that recording of the test has started

3) On starting Recording Toolbar is collapsed and we can click to expand. As shown in the image

4) Once recording has been started, Android application will be launched automatically. Now we are all set to perform actions.

Note: If in case the tested application does not launch automatically, then to launch the application navigate to Run App | Tested Application | Orders, as shown in the image.

 5) In our installed Android application, Click on New button

6) Enter details in input parameters as shown in the image and click OK

7) A new entry gets saved at the bottom of the list. Click on that entry

8) Click edit. And edit the details displayed in the form and click OK

9) Now click on stop recording

Once clicked on stop recording button, TestComplete will display keyword editor. All the recorded commands will be displayed in the keyword editor.

10) Click on stop button as shown in the image

Analysis of Recorded Test

Once we have clicked on the stop button, TestComplete will display keyword editor where all our recorded keywords are displayed. There may be a possibility that the recorded keywords at your end may differ with the keywords displayed in the image.

Let us analyze the recorded keywords.

One of the remarkable features of TestComplete is that description is written against each generated keyword corresponding to the operation performed on the application.

Running the Test

In order to make our playback without any error, recorded test must be started with the same initial conditions as it was during the recording of the test case.

Once the test has been executed a Test log node gets generated under the project. This test log gets opened automatically once a test has been executed completely.

To run the test, simply click on the Run Test as shown in the image.

Resolving errors

In some situations, if your test fails, the following might be some causes

1) Any third party application like Google advertisement overlapped the screen of the application thus producing an error

2) The initial condition required for test preparation is not successfully put through

3) The path for Java JDK, Android SDK is not configured in the TestComplete

4) Device USB Drivers are not installed properly on the computer

5) Check the API level from the SDK manager and the Android version of the device. Any mismatch can cause errors. Proper API should be downloaded to the device

6) TestComplete supports Android 4.0.1+ versions. Make sure your device is compatible with the TestComplete

Conclusion

So, this has been a compact and useful introduction to TestComplete and how to test Android apps with it. As always, with automation, you can extend the information we provided in this space to tackle complex and composite systems and frameworks.

We hope, this TestComplete tutorial series was useful to you. Please let us know your comments and questions below.