I am writing this post to share my personal experience with Selendroid to automate Native Android Apps on Windows platform.
About WebDriver - WebDriver is a web automation framework that allows to execute test scripts on desktop and mobile browsers.
If you are considering to test mobile apps, then the correct solution is Appium.
About Selendroid - Selendroid is a test automation framework which drives off the UI of Android native and hybrid applications (apps) and the mobile web.
About WebDriver - WebDriver is a web automation framework that allows to execute test scripts on desktop and mobile browsers.
If you are considering to test mobile apps, then the correct solution is Appium.
About Selendroid - Selendroid is a test automation framework which drives off the UI of Android native and hybrid applications (apps) and the mobile web.
Software’s Required:-
- Java JDK 1.6 or Above:- Download Link
- Android-Sdk :- Download Link
- Latest selendroid-standalone.jar :- Download Link
- Selendroid Test App :- Download Link
- Android server :- Download Link
Installation and Setting up Environment Variables
- Install Java and Set the JAVA_HOME environment variable and it should point to JDK folder. JAVA_HOME= C:\Program Files\Java\jdk7
- Extract latest Android-Sdk.
- Copy the path till sdk folder (For e.g. D:\ adt-bundle-windows-x86-20140321\adt-bundle-windows-x86-20140321\sdk)
- Go to Environment variables > User Variables and create a new Variable ANDROID_HOME= Path till SDK folder [D:\ adt-bundle-windows-x86-20140321\adt-bundle-windows-x86-20140321\sdk]
- Copy the path of sdk\platform-tools and \sdk\tools folder and Add this path in Environment Variable > System Variables > Path
Setting up Emulator
- Open SDK Manager
- Click on Menu Tools> Manage AVDs
- Go to Device Definition tab
- Select any device and click on Create AVD
- In Create AVD pop up select Skin(Any) and click on OK button
- Now the created AVD should be displayed in Android Virtual Devices tab, Select AVD and click on Start button
- Launch Android emulator pop up will appear click on launch button
- If you get the Error [PANIC: Could not open: AVD] appears than follow below steps to resolve the issue. Go to Environment variables > User Variables and create ANDROID_SDK_HOME and set it to sdk folder. For e.g. ANDROID_SDK_HOME= D:\ adt-bundle-windows-x86-20140321\adt-bundle-windows-x86-20140321\sdk
Setting up Android Device
- Enable Developers option and Enable USB Debugging option
- Plug the device to the system
- Go to \sdk\platform-tools folder and Open Command window(Press Shift and then right click and select Open Command Window here). Type below command and press enter: adb devices You will get list of devices attached with Serial number will be displayed. Copy the serial number of the device <serialId>.
- Copy android server file in the platform-tools directory. To install the application enter: adb -s <serialId> -e install -r android-server.apk
- Start the Android WebDriver application,by running this command: adb -s <serialId> shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity
- Now we need to setup the port forwarding in order to forward traffic from the host machine to the emulator. Enter the following in the terminal: adb -s <serialId> forward tcp:8080 tcp:8080
Running Scripts
- Navigate to the folder in which the selendroid-standalone.jar is present.
- Press Shift + Right Click and Select Open Command window here option
- Now type the below command to start the server
- java -jar selendroid-standalone-0.10.0-with-dependencies.jar Selendroid-standalone will start a http server on port 4444 and will scan all Android virtual devices (avd) that the user has created (~/.android/avd/). The Android target version and the screen size will be identified. If an emulator is running, it can be used since version 0.10.0. Even an emulator that has been started manually after the selendroid-standalone got started can be used. If there are Android hardware devices plugged in, they will also be added to the device store.You can check that the application(s) and the devices are recognized by opening a browser and navigating to below link in your local machine: http://localhost:4444/wd/hub/status.
Sample Script
import io.selendroid.*;
import io.selendroid.device.DeviceTargetPlatform;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class android {
public static void main(String args[]) throws InterruptedException
{
WebDriver driver = new RemoteWebDriver(DesiredCapabilities.android());
//Open URL
driver.get("http://m.ebay.de");
// Find the text input element by its id
WebElement element = driver.findElement(By.id("kw"));
// Enter something to search for
element.sendKeys("Nexus 5");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();*/
}
}
Inspecting Elements
- To inspect the elements
- Place the Break-point in the script
- Run the project on Debug Mode
- Wait till the execution reaches the break-point
- When execution reaches the break-point, Open Browser and Hit the URL http://localhost:4444/inspector
- Select in the UI hierarchy the web view you want to inspect and press the Ctrl key (this keeps the selection of the element).
- select the tab Html Source