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.

Thursday, 12 April 2012

robots.txt file of web sites

Have you ever wondered how the search engines such as and retrieve the web sites when we provide search queries?

Every search engines has a web robots (spider bots), which crawl over the internet and indexes various web sites based on the complex logic. From these indexed set of pages, search engines would retrieve the pages appropriate to our search query.

These spider bots retrieve a web site and traverses across every hyperlink that the website would have and indexes the site content. For example, spider bot of is googlebot and the spider bot of is bingbot.

These spider bots interacts with the robots.txt file of the website and determine the website pages that are not to be indexed.

Robots.txt file contains the information about various pages of the web sites and specifies the following details:

1. Specifies the robots that web site owner do not/want to index his/her website
2. Specifies the web pages that the user does not want the spider to index

You can access the robots.txt file of various leading websites by as below:

For example:

If you go through the above robots.txt file, you can observe that these websites specifically block certain spider bots and allows only certain advertisement related bots.

For more information, you can refer the below mentioned website:

Tuesday, 10 April 2012

Key combinations in Selenium 1 & 2

In this article, I would like to share my learning related to emulation of key combination press actions in Selenium 1 & 2. In our day to day activities, we would use the modifier keys number of times while working with the application. We would use ‘Alt+F4’ key to close the window, ‘Ctrl+C’ to copy the contents and several other key combinations for various activities.

In the aforesaid key combination (say for example-Ctrl+C), first part (Ctrl) of the combination is called as modifier key – as this key modifies the intended function of the second part of the key combination.

In the leading commercial test automation tools such as QTP and Silktest – required combination of key strokes can be easily achieved with the use of designated methods such as ‘type’ method and by using the appropriate constant that corresponds to the individual keys.

But in Selenium, using these key combination requires some better understanding about the intricacies of Selenium. So, in this article – I would explain about how to use these key combinations in ‘Selenium 1 & 2’.

In Selenium 1 – we can simulate the key combination action in a relatively simple way by using the following methods: KeyPress, KeyUp and KeyDown.

We just need to use the above mentioned methods in the instance of ‘DefaultSelenium’ object, with the appropriate ascii value of the key.

In case of more than 2 key combinations, such as ‘Shift+Alt+T’ - we can use the KeyDown and KeyUp methods to achieve the required key combinations, as below:

DefaultSelenium.KeyDown(<asciivalue of the key1>);
DefaultSelenium.KeyDown(<asciivalue of the key2>);
DefaultSelenium.KeyPress(<asciivalue of the key3>);

You can refer the below mentioned link to find the ascii value of various keys:

In Selenium 2 – to simulate the above mentioned key combinations, we would be required to use the ‘Actions’ class of Selenium Webdriver as below:

FirefoxDriver driver = new FirefoxDriver();           
Actions kpress = new Actions(driver);
kpress.keyDown(driver.findElement("name")), Keys.ALT).perform();
kpress.keyDown(driver.findElement("name")), Keys.SHIFT).perform();
kpress.sendKeys(driver.findElement("name")), "T").perform();
kpress.keyUp(driver.findElement("name")),Keys.SHIFT).perform();              kpress.keyUp(driver.findElement("name")),Keys.SHIFT).perform();

Here the objective is to simulate the press action of the key combination ‘Alt+Shift+T’. To perform this action, we are using the keyDown and SendKeys method of Selenium Action class.

I would post another article about F4 keys usage and action builder quite soon. If you have any questions in the above mentioned concepts, please let me know.

Monday, 9 April 2012

Do Events - Visual Basic for Applications

This was one of my first learnings in test automation. It is around 3 years back when I started to learn test automation technique that I came across this method called 'Do Events'.

At that time, I was trying to write keyword driven framework for the tool 'eTester', which has a scripting language of 'Visual Basic for Application' (VBA). During the framework development, there was a requirement for for loop and I wrote the code for it.

Code was written in such a way that it would click my application's button and would get in to the for loop and then would perform some action in the screen resulting because of the click performed previously.

Strangely, when I executed this code - I found that my application did not proceed further after clicking on the button. But the code worked perfectly fine when I ran the same code in 'Debug' mode.

I was wondering what could be the reason and was going over the internet search engines to discover the root cause. Unfortunately, I could not find what is the exact cause. Then I discovered that the root cause of the issue is the loop function that I had written in VBA.

I came to know that VBA has a peculiar behavior of hogging the system resources big time whenever it executes For statements/While loops. VBA would not free the resources to the events present in OS message queues until the loop is complete.

To allow the processor to executing the pending events in parallel with the loop statements, VBA requires 'Do Events' statement to be placed within the loops.

You can find more about 'Do Events' definition and usage in the below links:

Please let me know if you have any further queries on this.