I hope you found the first 3 parts of the blogs on Mobile Web Application Test Automation informative and helpful.
While Part 1 provides an introduction to mobile web automation, Part 2 talks about the testing methodology and how browser simulations will work and Part 3 focuses on browser simulation tools. Continuing the sequence, in Part 4, I will provide an overview of mobile web automation implementation using selenium webdriver, especially for android web browser.
Preface:
Webdriver enables you to run your tests against the browser running on a mobile device or a device emulator rather than having to use just the desktop web browser trying to make them to behave like mobile web browser. You can run the tests against android as well as iPhone web browsers using webdriver.
Setup:
For setup, I followed the instruction provided in AndroidDriver wiki and get it worked.
How to automate:
I tried it with ISFW by setting properties for server, port and providing browser string as “androidRemoteDriver”.
selenium.server=localhost selenium.port=4444 selenium.defaultBrowser=androidRemoteDriver |
The easiest way over here is to record using selenium IDE and export to ISFW format. If the web application has User-Agent awareness and generates User-Agent specific content, for example google search page or gmail, then one can simulate Firefox for mobile User-Agent as described in Part 3 during recording phase.
Sample Code:
public class AndroidDemo extends BaseTestCase { @Test(description = “Google search”) public void tc01() { IsSelenium selenium = getSTB().getSelenium(); WaitService waitService = new WaitService(); selenium.open(“/”); waitService.waitForPageToLoad(); selenium.type(“q”, “apexon test automation framework”); selenium.submit(“q”); getSTB().assertElementPresent( “link=Apexon Selenium Test Automation Framework”, “link Apexon Test Automation Framework”); } } |
Execution:
Before run automation, you need to execute following commands from command line to create/ start avd and install/start selenium server in avd manually as described in AndroidDriver wiki.
- android create avd -n my_android -t 12 -c 100M
- emulator -avd <avdName> -no-audio -no-boot-anim
- adb -e install -r <dir>/android-server*.apk
- adb shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity
- adb forward tcp:4444 tcp:8080
Here command #1 to create AVD (Android Virtual Device) requires only one time execution. Command #3 needs to be executed once or after you wipe data. Command #4 will start selenium RC in AVD from command line so you don’t need to search and start the applications in a device/emulator. Before executing command #4, you need to wait for emulator boot status complete. Finally, run batch file to run test and that’s it…
This task can be automated using ant script including the wait for boot complete and server ready. I have also integrated it with Hudson using Android plug-in. You can find details on integration with Hudson here.
Conclusions:
- You can test your web application with a mobile emulator or with a real device.
- Lesser efforts are required in setting up this environment compared to desktop browser simulation approach. You can utilize the simulation approach for getting information about web elements during automation development phase or to record test using IDE.
- It is cost effective if you run against emulator but slower compared to real device.
- Makes it as simple as web automation for desktop browser.
- ISFW provides strength to webdriver by fulfilling automation’s common aspects (data-driven, reporting, integration with test management tools, etc)
- Here are some Pros & Cons of using webdriver.
Screenshots: