Selendroid Setup in Eclipse Using WebDriver
Selendroid is a test automation framework used in automation of Android native and hybrid apps and the mobile web. Tests in Selendroid are written in Selenium WebDriver client API. This post covers step-by-step tutorial to perform Selendroid Setup in Eclipse IDE using WebDriver.
We will use TestNG framework in our setup and write a test on Selenium WebDriver using Java. The test will be carried out on sample Selendroid app installed in an emulator. But before we proceed further, let’s ensure we have below prerequisites met for Selendroid setup.
Prerequisites:
- Java SDK installed in the system and JAVA_HOME configured to point to JDK.
- Android SDK installed in the system and ANDROID_HOME set.
- Selendroid client and server JAR files and TestNG JAR file.
- Eclipse (with TestNG configured)
We can now start with Selendroid setup in Eclipse. Perform below steps for it.
- Start an emulator to run your test on or connect your device to the system.
- Download Selendroid server JAR file from above link. Also download Selendroid sample app from here.
- Put both downloaded files in same directory. Open Command Prompt and go to the directory where both these files are stored.
- Run below command in Command Prompt. It starts Selendroid server for the app under test.
1java -jar selendroid-standalone-0.13.0-with-dependencies.jar -app selendroid-test-app-0.13.0.apk - Selendroid server gets started on running the above command. To check if Selendroid server is running correctly, go to http://localhost:4444/wd/hub/status URL in your browser. It should show connected devices, app details etc. similar to below screenshot.
- Create a Java project in your Eclipse and reference Selendroid client, server and TestNG JAR files.
- Create a class file in your project and write below code. The app name displayed in Capabilities code is taken from ‘appId’ parameter shown in above image.
1234567891011121314151617181920212223242526272829303132333435363738package com.selendroid.test;import io.selendroid.SelendroidCapabilities;import io.selendroid.SelendroidDriver;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;public class SelendroidTest {public WebDriver driver;@BeforeSuitepublic void setUp() throws Exception {SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.12.0");driver = new SelendroidDriver(null, capa);}@Testpublic void selenTest() throws Exception {WebElement element1 = driver.findElement(By.xpath("//ImageButton[@id='buttonStartWebview']"));element1.click();WebElement element2 = driver.findElement(By.xpath("//ImageButton[@id='startUserRegistration']"));element2.click();WebElement element3 = driver.findElement(By.xpath("//Button[@id='goBack']"));element3.click();}@AfterSuitepublic void tearDown() {driver.quit();}} - Run your test using TestNG.
Important point to note here. Selendroid requires following permission for the app.
1 |
<uses-permission android:name="android.**permission.INTERNET"/> |
That means your Android application’s Manifest file needs to have the above permission.
We hope you have enjoyed the above article about Selendroid setup in Eclipse IDE. We would love to hear your inputs in comment.
Hi,
I have downloaded latest jars, I am getting compilation error for
import org.apache.commons.validator.routines.InetAddressValidator;
InetAddressValidator validator = InetAddressValidator.getInstance();
if (!validator.isValid(ipAddress) && !validator.isValidInet4Address(ipAddress) &&
!validator.isValidInet6Address(ipAddress))
throw new IllegalArgumentException(“The invalid IP address ” + ipAddress + ” is defined”);
import io.selendroid.client.SelendroidDriver;
driver = new SelendroidDriver(new SelendroidCapabilities(“io.selendroid.testapp:0.10.0”));
Please help to resolve issues, which I had posted earlier.
Thanks,
Rajesh
how to check permission
Nill, I descompill the .apk in this link http://www.javadecompilers.com/
in the file AndroidManifest.xml
this line