Selendroid is a test automation framework for Android native
and hybrid applications (apps) and the mobile web. Tests are written using the
Selenium 2 client API - that's it!
Before we start let’s have a look at prerequisite. Here is a
list of software that needs to be downloaded.
·
Andriod
SDK
·
Java
SDK (1.6 or higher)
·
Mobile
Application APK
·
Mobile
Device with its USB Driver
·
Selendroid jar file
Let us now divide the process for setting up Selendriod on
Windows into 4 steps mentioned below.
1. Andriod SDK and Environmental
variables setup
2. Andriod mobile device setup
3. Selendroid Configuration setup
4. Mobile Test Scripting
1.
Andriod SDK and Environmental
variables setup
If you do
not have Andriod SDK on your machine please download it from the link http://developer.android.com/sdk/index.html?hl=sk . A zip file will be downloaded.
Unzip the file on your local machine. You will find a folder named sdk, and in
sdk folder you will find various folder along with folders name as ” tools” and “platform tools”. Make a note of
the paths for these 3 folders namely
sdk, tools and platform tools.
We need to configure the environment
variable for Android. To set up environment variable for Android in windows
follow the steps below.
·
Go
to control panel -> System -> Advance system settings -> Environment
variables
·
Click
on New button under user variable .
·
On
the dialogue box, enter variable name as “ANDRIOD_HOME” and variable value as
“the path for sdk folder” and save.
·
Under
system variables edit path variable, put a semicolon at the end, paste the path
for ” tools” folder under sdk , put a semicolon at the end and paste the path for ” platform tools” folder under sdk ,
put a semicolon at the end and save it.
We are now done with configuring the environment variable for
Android.
2.
Mobile Device setup
Enable Developer option in mobile device. To enable follow the
below steps.
·
Go
to Settings in your mobile device
·
Select
Developer options
·
Check
“Stay awake” checkbox.
·
Also
check “USB debugging” check box and click on OK button.
Once Developer option is enabled in mobile connect the mobile
device to the computer. To make sure the device is recognized, go to command
prompt. Type the command as “adb devices” and hit enter. The mobile device id
will be displayed. If not , then the device is not recognized.
Also make sure JAVA_HOME is set on
the machine, if not we also need to configure the environment variable for
Java. To set up environment variable for Java in windows follow the steps
below.
·
Go
to control panel -> System -> Advance system settings -> Environment
variables
·
Click
on New button under user variable.
·
On
the dialogue box, enter variable name as “JAVA_HOME” and variable value as “the
path for java jdk folder” and save.
·
Under
system variables edit path variable, put a semicolon at the end (if not), paste
the path for java jdk folder and append “\bin” to it and save.
3.
Selendroid Configuration setup
Download the selendriod jar files
from the link http://selendroid.io/ . In order to use selendriod,
selendriod server needs to be started. Follow the below steps to start the server.
·
Place
the apk file to be tested in folder where selendroid jar file is located.
·
Go
to Command prompt
·
Navigate
to the folder where selendroid jar file is located
·
Type
the command as “java –jar (name of the selendriod jar file) –app (name of the
apk file)” hit enter.
Selendriod will start on the default port 4444.
The set up part ends here for selendriod. We can start
writing test cases using Selenium 2 client API.
4.
Mobile Test Scripting
Open eclipse and configure selenium jars in the project. Add test cases
to the project. Here is a sample code.
SelendroidCapabilities caps = new
SelendroidCapabilities("io.selendroid.testapp:0.9.0");
WebDriver driver = new SelendroidDriver(caps);
WebElement inputField =
driver.findElement(By.id("my_text_field"));
Assert.assertEquals("true",
inputField.getAttribute("enabled"));
inputField.sendKeys("Selendroid");
Assert.assertEquals("Selendroid",
inputField.getText());
driver.quit();
Inspecting elements is done using Selendriod Inspector, which
comes with Selendriod. You can find it When you have started
selendroid-standalone and you have started a test session at http://localhost:4444/inspector
For displaying the html
source code of a web view please follow these steps:
·
Select
in the UI hierarchy the webview you want to inspect and press
the ctrl key (this keeps the selection of the element).
·
select
the tab Html Source
Selendroid Inspector has a simple build in test case recorder
that tries to identify the element that is clicked (on the screenshot) and
saves the locator and click command into the Java tab.
Hi,
ReplyDeleteAs per the documentation, I see that SelendroidDriver requires two arguments to be passed. I am not sure if I have got confused, but the editor is simply not allowing me to add just driver = new SelendroidDriver(capa);
When I mouse hover on the code, I see this message,
"The constructor SelendroidDriver(SelendroidCapabilities) is undefined
1 fix available
Add argument to match "SelendroidDriver(URL, capabilities"
Can you please clarify?