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 is Android?
- Software required to automate Android application.
- Downloading and Installing 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.
- Preparing Mobile Device for a test.
- Create Test Project for Android Application.
- About Tested Application.
- How to record our test in TestComplete?
- Analysis of Recorded Test.
- Running the Test.
- Resolving errors.
What You Will Learn:
- What is Android?
- Software required to automate Android application
- Preparing Mobile Device for test
- About Tested Application
- How to record our test in TestComplete?
- Analysis of Recorded Test
- Running the Test
- Resolving errors
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
- Java JDK
- Android SDK
- Device USB Drivers
- Android Agent
- TestComplete Mobile Plugins
Let us learn to install the above-mentioned software one by one.
1) Downloading and Installing Java on the computer
- To download Java JDK to your system, click here
- Click “Download” Button as shown in the image
(Note: Click on any image for 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 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.
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 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 in 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 setting on the left side of the screen
- Navigate to Advanced tab
- Select 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 user variable section and add following parameters as displayed in the image
- Click Ok button
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.
- Navigate to the root SDK directory and double click on SDK Manger.exe to launch SDK Manager
- In the SDK Manager, select following items
- API version corresponding to the device used for testing
- Google USB Drivers
- Android SDK platform tools.
- Android SDK Build-tools.
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
- 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 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 steps to install Google USB Drivers on Windows
- Connect your Android device to the computer through the USB port
- Right Click on My Computer and click on Manage
- Select and click on Device Manager in 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.
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:
- Navigate to Settings option
- Go to About phone/tablet
- Repetitive tap Build number 7 times
- 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
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.
- Select Device: This keyword specifies to the mobile device on which test will be carried out. All the operations like edit, delete modification in our Android app will be carried on this device
- Run Tested App: Second keyword is Run Tested App. Tested application (in our case 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 orders 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 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.
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.