Thursday, 19 April 2012

Selenium Android User Actions

In this article, I would describe about how to emulate the various user actions such as doubletap, singletap, flick etc using Selenium in Android Mobile Browser.

Before getting into the technical details, as most of us know, Selenium is the leading test automation tool for web application and it works using the inbuild javascript support of the browsers. As almost all the browsers support javascripts, selenium can be used to automate web applications in virtually any browsers. Same applies to the browsers in mobile devices as well.

Android devices as an inbuild browser called ‘Android Browser’, and Selenium has a separate module that can be used to automate ‘Android Browser’.

Details about how to use ‘Selenium Android Package’ for mobile automation can be found in this link:

Above web page has the detailed description about how to automate Android using Selenium (ofcourse we need patience during the initial setup, as we would commit some inadvertent mistakes while setting up).  So, I would give you a code snippet that performs user actions such as doubletap, singletap,flick using Selenium in this article.

AndroidDriver driver = new AndroidDriver();
WebElement elem = driver.findelement(“name”));
      Action TchAct = new TouchActions(driver).doubleTap(elem).build();
TchAct = new TouchActions(driver).singleTap(elem).build();
                TchAct = new TouchActions(driver) .flick(element,0,-400,FlickAction.SPEED_NORMAL).build();

Here we are using ‘Action’ and ‘TouchActions’ classes of Selenium to emulate the user actions. And these actions emulates the user behavior as expected. As mentioned above, Selenium supports other user actions such as longpress, scroll, up, down etc.

Please let me know if you have any clarifications on this article.

No comments:

Post a Comment