Nowadays, compatibility testing is very important and in demand
as it gives the confidence that our application is usable across multiple
platforms.
One of the most used platforms in the world is Mobile. So
the question is whether your application is usable across different Mobile
platforms?
For that matter there are many mobile devices and
platforms like android and iOS in which we can test the compatibility of our
application.
There are n number of Mobile devices available
with x resolutions having y operating systems. So practically,
it’s not feasible to have all the n*x*y number of devices to do a
compatibility test on.
There are again two different ways we look at the mobile compatibility
Using
Mobile WebDriver
As our objective is to test the web application on mobile,
we can either do it on the mobile emulators or on the actual devices.
That’s the reason Mobile simulators have come into the
picture so if I have to test my application on that many devices, I can do it
by simulating the required features.
We have android webdriver which helps us test
the application and run the tests to ensure our website working as expected
when viewed from android browser.
It supports all the core webdrive apis
and many user interactions like taps, flicks, scroll etc. To interact with the
web page android driver uses the native touch and key events.
Step 1:
Download
the android SDK here
Download the Latest ADT bundle from the below Location
System Settings :
Set the ANDROID_HOME
Ex: C:\Android\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk
Set Path variable for
the Android
Ex: % ANDROID_HOME%\platform-tools; %ANDROID_HOME%\tools;
Step
2:
Create
an Android virtual device AVD. Follow the instructions given here.
Step 3:
Download the android webdriver apk file (here)
and install on the virtual device using the command below in command prompt
Command:
adb install android-server-2.38.0.apk
Step 4:
To get the
emulators or devices connected
Command: adb devices
List
of devices attached
emulator-5554 device
Start the webdriver app install using the command below
Command:
adb -s emulator-5554
shell am start -a android.intent.action.MAIN -n
org.openqa.selenium.android.app/.MainActivity
Forward the tcp port to send the selenium commands to
emulator
Command: adb –s emulator-5554 forward tcp:8080
tcp:8080
Step 5:
Use
the eclipse and create a Java project
Create
a java class with the below code
import junit.framework.TestCase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;
public class OneTest extends TestCase {
public void testGoogle() throws Exception {
WebDriver driver = new AndroidDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Selenium Mobile Testing");
// 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();
}
}
Run the program as simple Junit test, now the application is
opened on the mobile browser and executed
Using
Selendroid WebView
Selendroid is an automation framework which drives of UI
of android native, hybrid and mobile web application tests. It uses JSON Wire
Protocol to run webdriver test scripts on emulators or devices. No modification
or need source code is required to automate application.
Step 1:
Download
the android SDK here
Step
2:
Create
an Android virtual device AVD. Follow the instructions given here.
Step 3:
Download
the Selendroid standalone server jar here
Step 4:
Start the
emulator using AVD manager and to get the emulators or devices connected
Command: adb devices
List
of devices attached
emulator-5554 device
Start the Selendroid server using the below command
Command: java -jar
selendroid-standalone-0.11.0-with-dependencies.jar
The default port the selendroid server runs in 4444. If we want
to change the port use the command
Command: java -jar
selendroid-standalone-0.11.0-with-dependencies.jar – port:5555
Step 5:
Use the eclipse and create a Java project and create a java class
with the below code and configure the build path
Sample
code:
package com.java;
import
io.selendroid.SelendroidCapabilities;
import org.junit.Test;
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 OneTest {
private WebDriver driver = null;
@Test
public void shouldSearchWithEbay() throws InterruptedException {
DesiredCapabilities
capa=DesiredCapabilities.android();
capa.setCapability(SelendroidCapabilities.EMULATOR, true);
driver = new RemoteWebDriver(capa);
// And now use this to visit ebay
driver.get("http://m.ebay.com");
// 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();
Thread.sleep(5000);
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
Result:
Object Identification:
In order to inspect and
identify the elements in the webview we can use the below url to spy on the
objects.
Note: Make sure the selendroid server and emulator or device is up
and running on the specified port. Refer here for more information.
We can even test the native android
apps using selenium. Here we need have the application kit or .apk file of the
application which we need to test
We provide hands-on training on automation tools and frameworks