Mobile Automation Using Selendroid (Part-I):
Considering the numerous Android applications developed, and the constant increase in their number, the task of verification becomes a challenge. This requires significant resources, such as labor and genuine devices (like mobiles), leading to time consumption. Additionally, the Android version, .apk version, and the size of the device are always changing, thus complicating the definition of test departure criteria and the precise calculation of the testing work.
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 )
The solution to device dependence has been provided through the development of emulators. They present a real-time environment for testing apps without the worry of Android versions, devices, etc. Still, testing .apk files on emulators remains manual and time-taking. This led to the birth of mobile test automation frameworks.
Selendroid is one such framework, allowing automation of Android applications via a scripting language. Other well-known automation frameworks are Appium, Robotium, and Espresso.
The guide is split into two parts:
Guide #1: An Introduction to Selendroid – Android Mobile Test Automation Framework
Guide #2: Methods to employ Selendroid framework for automating user interactions in a mobile application (coming soon)
What Will Be Covered:
What is Selendroid?
Selendroid is an influential test automation tool for Android mobile apps with numerous essential features. It supports interaction with multiple devices at once and facilitates application testing without any modifications using Selendroid.
It is also called “Selenium for Android” because it is utilized for testing native, hybrid, and mobile web apps.
Why should you use Selendroid?
- The framework is open-source (free to use)
- It supports Selenium as a scripting language
- Selendroid supports WebDriver compatible languages such as Java, C#, and Perl
- Compatible with all Android versions
- Operates on both emulators and actual devices
- Supports native, hybrid, and web-based applications
- It’s efficient for testing native and cloud-based applications as it supports Selenium Grid
- Supports object identification using object properties
- Easily implementable
- Supports hotplugging, permitting devices to be plugged or unplugged during test execution without disruption
A Basic Architecture of Selendroid
Selendroid’s architecture is made up of four main components:
- Selendroid – Client: A Java client library for sending HTTP and WebDriver requests via JSON to the Selendroid Standalone server
- Selendroid – Standalone: Manages devices and .apk files by installing the Selendroid server and the app being tested. It sends HTTP requests from the Selendroid standalone server to the device and the application under test
- Selendroid – Server: Operates on the device along with the application under test. It enables bidirectional communication between the server and the app
- AndroidDriverApp: An inbuilt Android driver and web view app for mobile web testing
Another widely-used testing framework like Selendroid is Appium. The contrast between the two is as follows:
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 applications | No | Yes |
Environmental Requirement | For Android – Mac, Linux, Windows (any version) | For iOS – Mac OSX 107 For Android – Windows 7+, Linux, Mac OSX 107 |
Requirements:
To begin, you should be familiar with 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 necessary) from here to view the emulator
- Make sure Java SDK and JRE are already installed. They can be downloaded from here
Specify the following environmental variables:
- Set the path for Android SDK:
My Computer -> Right-click -> Properties -> Advanced System Settings
Refer to this image for guidance. - Set the JAVA_HOME path:
My Computer -> Right-click -> Properties -> Advanced System Settings
Check this image for demonstration.
- Eclipse should already be installed. If not, it can be downloaded from here
- Download Selenium jar files from here
- Ensure TestNG jars are downloaded
- Download and install Android SDK from here
- Download Selendroid jar files from here
Keep in mind:
- You can use the 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 access a list of installed apps on your Android device with their original names, sizes, etc.
Setting Up the Environment
#1) Locate the APK file properly
E.g., G:Jarsselendroid-test-app-0.8.0.apk
#2) Position the application in the project directory
E.g., D:AppiumAutomationSelendroidFirst
- Connect an actual device to the PC, ensuring that USB Debugging mode is activated and allows installation of outside apps through USB connection.
Recommendations:
- For USB debugging settings for Redmi Note 3, refer here
- For activating the installation of external apps using USB for Redmi Note 3, refer here
#4) Open the command prompt in Windows
Navigate to the directory where the Selendroid standalone jar file and the downloaded apk file are located. 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
Remark: Ensure that the APK is signed and the physical device is linked to the PC with debugging enabled.
Confirm if the server started by accessing the following URL in a web browser:
E.g., http://localhost:4444/wd/hub/status
#5) APKs Inspection
- You can utilize real apps by connecting real mobile devices
- You can also employ offline APK files that are downloaded
The Selendroid Inspector tool is handy for debugging and inspecting the web components 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 being tested. The default path for this tool is:
C:Usersadminandroid-sdkstools
Note: The above path may differ depending on your Android SDK installation location.
Crafting Your First Script Using APK Files Over Genuine Devices
Purpose:
- Initiate the Selendroid server (default port is 4444)
- Establish a session
- Install the application (APK file) on the connected actual device
- Automate the entry of text in a text field
- Automatically click on a button
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); }
Wrap-up
Selendroid is a potent test automation framework tool for Android mobile applications. It supports testing native, hybrid, and mobile web apps on any Android device or emulator. It offers features like hotplugging, interaction with multiple devices, and various touch gestures.
The only complexity arises in setting up the environment accurately, which is common in most test frameworks. Once appropriately set up, scripts can be executed effortlessly.