Learn how to automate Android Applications using TestComplete (Part-III) in this tutorial:
In the last two TestComplete tutorials, we learned 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 to technology and numerous devices available, it becomes a very hectic task for developers and testers to consistently check their application’s compatibility.
Tools such as TestComplete can increase test coverage and improve test effectiveness. We have seen some basic concepts for TestComplete previously. Take a look at the tool in detail below:
Table of Contents:
Automate Android Applications Using TestComplete Tool
In this tutorial, we will look into the following
- What is Android?
- Software required to automate Android applications.
- Download and Install Java on the computer.
- Configuring Java JDK in Windows.
- Download and Installing Android SDK.
- Configuring Android in Windows.
- Configure Java JDK and Android SDK to TestComplete.
- Install Google USB Drivers.
- Prepare Mobile Devices for testing.
- Create Test Projects for Android Applications.
- About the Tested Application.
- How do we record our tests in TestComplete?
- Analysis of Recorded Tests.
- Run the Test.
- Resolving errors.
What is Android
Android was initially developed by Android Inc. and was bought by 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. The platform could be anything such as a mobile device, tablet, etc that supports touchscreen functionality.
Software required to automate Android applications
To do this, 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
- Java JDK
- Android SDK
- Device USB Drivers
- Android Agent
- TestComplete Mobile Plugins
Let us learn to install the above-mentioned software one by one.
Java JDK
1) Download and Install Java on the computer
- To download Java JDK to your system, click here
- Click the “Download” Button as shown in the image
(Note: Click on any image for an enlarged view)
- Scroll to the latest version of the kit
- Accept the license agreement and click the Download button
- Once the kit is downloaded, double-click on it to open
- Follow the wizard to install Java JDK on the system
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 in both environments.
Java JDK can be configured by setting the build path. Generally, there are two ways to do that
- Temporary
- Permanent
Here is a permanent way we are applying to set up the build path:
Let’s begin!!!
1) Right click on the My Computer icon on your desktop and select Properties
2) Open the “Advanced” system settings on the left side of the screen
3) Go to the “Advanced” tab
4) Click on the Environment Variables button
5) Under the 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 the Ok button
Note: To verify if the installed and configured Java works correctly, open the command prompt and type java-version in the command line. Verify if the Java version is displayed upon executing the command.
Why do 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 the 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
- Navigate to this URL
- Scroll to the bottom of the page
- Click on the link as shown in the image
- Select the Terms and Conditions and click the Download button
2) Configuring Android in Windows
To create an automated script we need to configure the Android SDK in our operating system and in TestComplete.
- Once downloaded, you can extract the folder and copy the extracted files from your Local C drive
- Open the folder; navigate to SDK-> program tools
- Copy the path of the folder
- Right click on My Computer and select Properties
- Open Advanced System Settings on the left side of the screen
- Navigate to the Advanced tab
- Select the Environment Variables button
- Under the system variable section, scroll down to the ‘path’ and click on Edit
- In the text box of variables value, move to the end of an already written path, place a semicolon and paste the path of the folder program tools (which we had copied)
- Click New under the user variable section and add the following parameters as displayed in the image
- Click the Ok button
Note: To verify if the installed and configured Android works correctly, open the command prompt and type android on the command line. Verify that the SDK Manager is launched upon executing the command.
- Navigate to the root SDK directory and double click on SDK Manager.exe to launch SDK Manager
- In the SDK Manager, select the following items
- API version corresponding to the device used for testing
- Google USB Drivers
- Android SDK platform tools.
- Android SDK Build-tools.
Select any 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 the path manually.
Follow the steps to configure Android and Java to TestComplete
- Navigate to Tools | Options
- Go to Engines |Mobile | Android
- Specify the path of Android SDK and Java as shown in the image
Note: If the Mobile option is not visible in Engines then you need to enable the mobile extension in TestComplete.
Follow these steps to enable mobile extension
- Go to File | Install Extension
- An Install Extension dialog box will open
- Select the required plugins to enable as shown in the image
Install Google USB Drivers
Follow the steps given below to install Google USB Drivers on Windows
- Connect your Android device to the computer through a USB port
- Right Click on My Computer and click on Manage
- Select and click on Device Manager on the left partition
- Select Portable Devices
- Right-click on the device name and select Update Driver Software
- Click on Browse My Computer for driver software
- Browse to the following folder – C:\SDK\extras\google\usb_driver
- Click Next to install the driver.
- Thus, we have installed Google USB Drivers on our operating system.
Prepare Mobile Devices for testing
To run Android tests with TestComplete you need to prepare your Android device for testing and we call it “Test Ready”.
a) Enable Developer Options on Android Device
Follow these steps to enable developer options on Android Devices:
- Navigate to the Settings option
- Go to About phone/tablet
- Repetitively, tap Build number 7 times
- By doing so you will notice an extra option in your menu named “Developer Option”
Tap the Developer option in Settings and enable the 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 sleep mode during test execution. This feature is available on all Android devices.
b) Create Test Projects for Android Applications
Let us begin by creating our first test project to automate Android applications 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 purposes, 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 Applications
In this tutorial, we have used an android application provided by along with the TestComplete. This Application is for managing orders. Users can create orders, modify or delete existing purchase orders.
This application should be installed on the device which will be used for automated testing.
How do we record our tests in the TestComplete tool
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 interactions performed on the mobile screen displayed in the window will get recorded in the TestComplete tool.
2) A recording panel as shown in the image will be displayed, it confirms that the recording of the test has started
3) Upon starting the Recording Toolbar has collapsed and we can click to expand. As shown in the image
4) Once the recording has been started, the Android application will be launched automatically. We are now 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 the New button
6) Enter details to 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. Then edit the details displayed in the form and click OK
9) Now click on stop recording
Once clicked on the Stop Recording button, TestComplete will display the keyword editor. All recorded commands will be displayed in the keyword editor.
10) Click on stop button as shown in the image
Analysis of Recorded Test
Once you have clicked on the stop button, TestComplete will display the keyword editor where all our recorded keywords are displayed. There may be a possibility that the recorded keywords on your end may differ from the keywords displayed in the image.
Let us analyze the recorded keywords.
- Select Device: This keyword specifies the mobile device on which the test will be carried out. All operations like editing and deleting modifications in our Android app will be carried out on this device
- Run Tested App: Second keyword is Run Tested App. Tested application (in our case it is Orders.apk) is launched by TestComplete through this command
- ListView_listView1: This command is used to invoke touch operation on the list of the orders. As shown in the image
- Button_Edit: Operation involving clicking on the edit button in the order application has resulted in the generation of the Button_Edit keyword
- EditText_cust_name: Operation executed in editing the customer name is recorded as the following keyword
- Button_Ok: When we have clicked on the Ok button in the order application, that operation has generated this keyword
One of the remarkable features of TestComplete is that the description is written against each generated keyword corresponding to the operation performed on the application.
Running the Test
In order to enable our playback without any errors, recorded tests must start with the same initial conditions as they were during the recording of the test case.
Once the test has been executed a Test log node gets generated under the project. The 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 was not successfully put through
3) The path for Java JDK and Android SDK is not configured in 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 TestComplete
Conclusion
This is a compact and useful introduction to TestComplete and how to test Android apps with it. We have included key concepts that will be beneficial to you while using the tool. As always, with automation, you can extend the information we provide in this space to tackle complex and composite systems and frameworks.
We hope this TestComplete tutorial series was useful to you. Please share your feedback with us in the comments section below. We would love to hear from you.
In our next article, we will discuss more on Robotium – The Most Popular Android Application UI Testing Tool.
Very useful tutorial.
This is good. Thanks for the series.
Very useful.