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:
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.
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.
(Note: Click on any image for enlarged view)
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:
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.
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
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
Follow steps to install Google USB Drivers on Windows
To run Android test with TestComplete you need to prepare your Android device for testing and we call it as “Test Ready”.
Follow steps to enable developer options on Android Device:
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.
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
Thus, our project to test an android application is ready.
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.
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
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.
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.
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
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.
In our next article, we will discuss more on Robotium – The Most Popular Android Application UI Testing Tool.