Selendroid for Mobile Automation (Part-I):
With millions of Android apps already developed and the count increasing day by day, the challenge lies in validating each and every app. This task requires dedicated resources, such as manpower and real devices (e.g., mobiles), making it time-consuming. Additionally, the Android version, .apk version, and device dimensions are constantly changing, making it difficult to define test exit criteria and estimate the testing effort accurately.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
To overcome device dependency, emulators have been developed to provide a real-time environment where apps can be tested without worrying about Android versions, devices, etc. However, testing .apk files on emulators is still a manual and time-consuming task. This has led to the evolution of mobile test automation frameworks.
One such framework is Selendroid, which enables the automation of Android-based apps using a scripting language. Other popular automation frameworks include Appium, Robotium, and Espresso.
This tutorial is divided into two parts:
Tutorial #1: Introduction to Selendroid – Android Mobile Test Automation Framework
Tutorial #2: How to use Selendroid framework to automate user interactions in a mobile app (coming soon)
What Will You Learn:
What is Selendroid?
Selendroid is a powerful Android mobile application test automation framework tool with several important features. It allows interaction with multiple devices simultaneously and enables testing of applications without any modifications or changes using Selendroid.
It is also known as “Selenium for Android” as it is used for testing native, hybrid, and mobile web apps.
Why use Selendroid?
- It is an open-source (free to use) framework
- Supports Selenium as a scripting language
- Supports web driver compatible languages like Java, C#, and Perl
- Compatible with all Android versions
- Works on both emulators and real devices
- Supports native, hybrid, and web-based applications
- Effective for testing native and cloud-based applications, as it supports Selenium Grid
- Supports object recognition using object properties
- Easy to implement
- Supports hotplugging, allowing devices to be plugged or unplugged during test execution without restarting or stopping the test
A simple architecture of Selendroid
The architecture of Selendroid consists of four main components:
- Selendroid – Client: A Java client library for sending HTTP and WebDriver requests using JSON to the Selendroid Standalone server
- Selendroid – Standalone: Manages devices and .apk files by installing the Selendroid server and the app under test. Sends HTTP requests from the Selendroid standalone server to the device and the app under test
- Selendroid – Server: Runs on the device along with the app under test. Enables two-way communication between the server and the app
- AndroidDriverApp: A built-in Android driver and web view app for testing mobile web
Another popular test framework similar to Selendroid is Appium. Here’s a comparison between the two:
Feature | Selendroid | Appium |
---|---|---|
Support for Lower android version(<4.1) | Yes | No |
Hot plugging | Yes | No |
User Agent Testing | No | Yes |
Support for iOS based application | No | Yes |
Environmental Requirement | For Android – Mac, Linux, Windows (any version) | For iOS – Mac OSX 107 For Android – Windows 7+, Linux, Mac OSX 107 |
Pre-requisites:
To get started, you should already be familiar with using Selenium, IDE tools like Eclipse, basic programming concepts (Java, C, etc.), and have knowledge of Maven and other testing tools.
- Install Intel x86 Emulator Accelerator (not mandatory) from here to view the emulator
- Ensure Java SDK and JRE are already installed. You can download them from here
Set the following environmental variables:
- Set path for Android SDK:
My Computer -> Right click -> Properties -> Advanced System Settings
Check this image for reference. -
Set JAVA_HOME path:
My Computer -> Right click -> Properties -> Advanced System Settings
Check this image for reference.
- Eclipse should already be installed. If not, you can download it from here
- Download Selenium jar files from here
- Make sure TestNG jars are downloaded
- Download and install Android SDK from here
- Download Selendroid jar files from here
Remember:
- You can use maven repository to reference the jars, or manually download and attach them to the build path in Eclipse
- Devices/Emulators: In Android, all installed apps have the .apk extension. You can use apps like APK Info to get a list of installed apps on your Android device with their actual names, sizes, etc.
Environmental Setup
#1) Keep the APK file in a proper location
E.g., G:Jarsselendroid-test-app-0.8.0.apk
#2) Keep the application in the project folder
E.g., D:AppiumAutomationSelendroidFirst
- Connect a real device to the PC, ensuring that USB Debugging mode is enabled and allowing installation of external apps through USB connection.
Tips:
- For USB debugging settings for Redmi Note 3, refer here
- For enabling installation of external apps using USB for Redmi Note 3, refer here
#4) Open the command prompt in Windows
Navigate to the folder where the Selendroid standalone jar file and the downloaded apk file are present. Use the following command:
E.g., java –jar selendroid-standalone-0.15.0-with-dependencies.jar -aut selendroid-test-app-0.8.0.apk
Or, java –jar selendroid-standalone-0.15.0-with-dependencies.jar
APK File: selendroid-test-app-0.8.0.apk
Note: Ensure that the APK is signed and the real device is connected to the PC with debugging enabled.
You can confirm if the server is started by accessing the following URL in a web browser:
E.g., http://localhost:4444/wd/hub/status
#5) Inspecting the APKs
- You can use real apps by connecting real mobile devices
- You can also use offline APK files that are downloaded
The Selendroid Inspector tool is useful for debugging and inspecting the web elements of an APK. Access it using the following URL in a web browser:
E.g., http://localhost:4444/inspector
You can also use “uiautomatorviewer” to find objects from the app under test. The default path for this tool is:
C:Usersadminandroid-sdkstools
Note: The above path may vary depending on your Android SDK installation location.
Writing First Script Using APK Files Over Real Devices
Objective:
- Start the Selendroid server (default port is 4444)
- Create a session
- Install the application (APK file) on the connected real device
- Automate text entry in a text field
- Click on a button automatically
package SelendroidFirst; import io.selendroid.client.SelendroidDriver; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import io.selendroid.common.SelendroidCapabilities; import io.selendroid.common.device.DeviceTargetPlatform; import io.selendroid.standalone.SelendroidConfiguration; import io.selendroid.standalone.SelendroidLauncher; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.remote.*; import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME; import static org.openqa.selenium.remote.CapabilityType.PLATFORM; import static org.openqa.selenium.remote.CapabilityType.VERSION; public class RealDevices{ public SelendroidLauncher selendroidServer = null; public WebDriver driver = null; public void conf() throws Exception { //**Configuration**// SelendroidConfiguration config = new SelendroidConfiguration(); config.addSupportedApp("G:Jarsselendroid-test-app-0.8.0.apk"); SelendroidLauncher selendroidServer = new SelendroidLauncher(config); selendroidServer.launchSelendroid(); //**Creating capabilities**// SelendroidCapabilities sc = new SelendroidCapabilities(); sc.setAut("io.selendroid.testapp:0.8.0"); sc.setEmulator(false); //**Instantiating new Selendroid driver**// WebDriver driver = new SelendroidDriver(sc); //**Sending data to the text field**// driver.findElement(By.id("my_text_field")).sendKeys("Selendroid Test"); //**Clicking on the button**// driver.findElement(By.id("visibleButtonTest")).click(); Thread.sleep(10000); }
Conclusion
Selendroid is a powerful test automation framework tool for Android mobile apps. It supports testing of native, hybrid, and mobile web apps on any Android device or emulator. It provides features like hotplugging, interaction with multiple devices, and various touch actions.
The only complexity lies in setting up the environment correctly, which is common in most test frameworks. Once set up properly, scripts can be run smoothly.