Skip to main content


Showing posts from September, 2008

QTP vs Seleium vs Other tools

I had a chance to look at this comparison and do not agree with few claims. (Not because I am dedicated to selenium but since I have found few of these working my self.) They are just mentioned as mere Yes or No with out any associated reasoning. I have tried to contradict few of these claims below - Ability to identify objects using multiple parameters: Selenium does indeed support multiple ways for identifying object like - id, name, Xpath, css, dom etc. Ability to run multiple scripts consistantly in a Batch mode: This can be easily achieved using frameworks like JUnit, TestNG etc, Object Oriented Scripting Support: Selenium has a long list of supported client drivers and if Java, C# are not object oriented then which language is object oriented? Integration with External libraries: What are libraries like TestNG, Fest, Ant which I have integrated with Selenium for my test effort Object parametrization: Can be achieved using TestNG Integrated Data Driven Test framework

Testing HTML object using DOM and selenium

DOM is w3c standard for navigating through the objects of a structured doc, Same can be used for exercising HTML/XML docs. In HTML, each element is referred as an object hence text box, dropdown, radio button etc are objects. These objects have properties (like max length in case of text box etc) and methods. Herein properties of objects can be collected in selenium through evaluation of java script and then these can be compared against expected values. For example one can collect max length and size properties of text box by evaluating java script through getEval function as following - selenium.getEval("var property = new Array(); property[0] = window.document.getElementsByName('empNumber')[0].maxLength;" + "property[1] = window.document.getElementsByName('empNumber')[0].size; property.toString();"); /**** I have explained evaluation of js in issue - 9211 ****/ Now individual properties can be collected in an string array as following - String[] T

Execute java script from selenium

getEval method can be used to evaluate java script from selenium. Remember to use window object in case of dom expressions as by default selenium window is referred and not the test window. Hence a sample code will look as following - selenium.getEval("window.document.images.length;"); This will return total number of images in a web page. Same result can be retrieved using only "document.images.length;" string IF selenium is run in proxy injection mode. (As selenium runner will not appear in the test window). BUT To be on safer side irrespective of mode selenium is run always use 'window' object of java script. If evaluated expression is to return multiple values then use it as following - This will return all the image links available on a page. This can be collected in a string and individual links can be found by using split method. Now to execute java script using Selenium IDE. lets type a random number on a text box -     type    

Disadvantage of using isTextPresent method and possible work around

Default Selenium class has a method called 'isTextPresent' which can be used to verify presence of text on a page. Disadvantage of using this method is - It checks for presence of text in entire page, hence even if text is present at a different location test would pass and no error would be reported. A better approach would be to find text on the basis of it's position in page. If text which is to be validated is part of table then 'getTable' method can be used. 'getText' method can also be used BUT element locator should be taken as dom so that presence of text is validated at a certain position. Ex - Consider presence of text "Employee Number1 :*" is to validated on a page. It can be done as following using getText method - verifyEquals("Asserstion Failed for getText.", "Employee Number1 :*", selenium.getText("document.getElementsByTagName('table')[0]. getElementsByTagName('tr')[0].getElementsByTagName(&

Mouse over DOM

Mouse Over Dom can be used to analyze element in a web page. This would be useful for the applications which are to be automated but do not support Firefox Browser (Hence Selenium IDE or Firebug can not be used to analyze elements). Browser which are currently supported are - Firefox, Mozilla, Netscape 8, Opera 7.5+ and MSIE6+

Selenium Tutorial: Capture screenshot on selenium test failure using TestNG and Fest

There is a method in DefaultSelenium class called CaptureScreenshot()which can be used to capture screen shot in general. But this is not effective when screen shot is to be taken only during failures. To achieve capturing screen shot on failure FEST can be used ( ) Regardless of how the FEST-Swing takes a screenshot, it needs to know which tests should be considered "GUI tests." In order to do so, one needs to add the annotation @GUITest. This annotation can be placed at class or method level, and it is inherited by subclasses of annotated classes. Hence in case of selenium it should be added on the class which is extended by other test classes Once downloaded Fest, add these jar files in library of Intellij - fest-swing-1.2.jar fest-swing-testng-1.2.jar fest-util-1.1.2.jar fest-reflect-1.2.jar Same should be added in the library folder of project and property of ANT so that ANT could access these. Now import the GUI test in SelTestCas

Setting up selenium with .NET Framework

Prequisites - 1. Visual Studio Team System - VSTS (preferably 2005) 2. Selenium .NET Client Driver { /selenium-remote-control/1.0-beta-1/ } On unzipping the package one folder dotnet will be found.) 3. NUnit (2.4.7){ > download NUnit-2.4.7-net-1.1.msi} Steps - 1. Launch VSTS > File > New > Project. 2. Select Visual C# > Test > Test Project > Click Ok 3. This will open AuthorisingTest.txt and UnitTest1.cs files. 4. Click on UnitTest1.cs file and replace the existing code with following - **************************************************************** This is a simple test over google where Search is performed over "Selenium OpenQA" string and search results are verified. **************************************************************** 5. On the RHS under Solution Explorer right click on References > A

Implementing soft assertion with selenium

Soft Assertion is a check which doesn't abort tests if assertion fails. (Same way there is Hard Assertion which aborts tests if assertion fails.) Selenium API has verify.* methods for this but their are draw backs of these methods - 1. Verification methods do not take string arg hence if multiple verifications fail in a method then there is no way to point as to which assertion failed. 2. To check verification errors checkForVerificationErrors method is called. But if there is any verification error this method doesn't clear the verification errors after having caught it. Hence no subsequent verification errors would be checked. These limitation are described here - These methods are part of Java-Client-Driver of selenium. I have modified checkForVerificationErrors method like this - Here Reporter is the class in TestNG using which I get the message printed in TestNG Report. If Selenium is to b

Steps to bypass the NT authentication in windows

Below is the excerpt from my friend Poornima over the steps to be carried out to stop NT log in window to appear. STEP 1: Start regedit . Go to: HKEY _LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\ FeatureControl \FEATURE_HTTP_ USERNAME _PASSWORD_DISABLE to re-enable it for the entire machine. Or go to: HKEY _CURRENT_USER\Software\Microsoft\Internet Explorer\Main\ FeatureControl \FEATURE_HTTP_ USERNAME _PASSWORD_DISABLE to re-enable it for the logged in user. STEP 2: Now create iexplore . exe and explorer. exe DWORD values and set their value data to 0. STEP 3: Now the URL should be used as – http:// @www.

How to over come "Failed to start: SocketListener0@"

This is the most common error which is encountered while starting the selenium server. The origin of this error is the fact that selenium server always tries to listen at port 4444 by default so when following is written at command prompt - java -jar selenium-server.jar The server starts running on port 4444 but if this post is already occupied then server will fail to listen at this port and following error will be encountered - Failed to start: SocketListener0@ To over come this one can force server to listen at port any other port while starting the selenium server as following - java -jar selenium-server.jar -port 5555 and this will start server as following - 10:55:14.440 INFO - Java: Sun Microsystems Inc. 1.5.0_05-b05 10:55:14.440 INFO - OS: Windows XP 5.1 x86 10:55:14.456 INFO - v1.0-SNAPSHOT [1123], with Core v1.0-SNAPSHOT [2101] 10:55:14.549 INFO - Version Jetty/5.1.x 10:55:14.549 INFO - Started HttpContext[/,/] 10:55:14.549 INFO - Started Http

Selenium or Badboy

This is my first blog and first thing which comes on my mind is test automation. So far I have worked with two test automation tools Badboy and Selenium . Out of these Badboy was the first tool I used and then migrated to Selenium for various reasons like - One can code in multiple languages in Selenium (i.e. Java, C#, Perl, Python etc) Though there is no out of box support for data base testing but it can be achieved using client language like - java, c# There are many more such reasons which prompted me to use Selenium. I will describe them in detail when at leisure. With this I come to end for my first blog.