Monday Sep 14, 2009

How to Test External Sites (Internet Sites) using Selenium

[Article by]

    Problem :

    If your testing site (ex: / is behind the proxy then selenium fails to access the site. 

    Because selenium itself acts as proxy to AUT (Application Under Test) and which fails to resolve internet sites behind proxy. site says using proxy options, while starting the server will help to resolve the external sites.

    i.e java -jar selenium-server.jar -Dhttp.proxyHost=<proxyHostName> -Dhttp.proxyPort=<proxyPort>

    But the above solution doesn't resolve the issue.

    Before jumping in to solution let us see how selenium server invokes browser and access the internal/external sites.

    When we invoke NewBrowserSession Request to selenium server (i.e selenium.start()) the following background steps are performed.

    For \*firefox/\*chrome:

    1)Extract the CustFirefoxProfile bundled with selenium server.

    2)This will make sure clean firefox session for every new browser session.

    3)Command line jvm proxy settings does not affect to the new firefox session.

    For \*iexplore:

    In case of Internet Explorer , it will simply create custom profile from the current IE instance settings.

    So, for IE simply set the browser proxy to access the internet sites and running tests on internet sites will work. We need solution only for firefox/chrome browser sessions. 


Solution :

    1) Extract the selenium-server.jar using WinRAR/7zip/Winzip archive tool.

    2) Copy "customProfileDirCUSTFF" to a new folder as "MyProxyFirefox"

    3) Under "MyProxyFirefox" folder create firefox user settings file.

       (i.e create a New Text File with Name "prefs.js" with out quotes. Extension of File Should be .js)

    4) Now copy the following properties to prefs.js file.

       user_pref("network.proxy.type", 1);

       user_pref("network.proxy.ftp", "");

user_pref("network.proxy.ftp_port", 8080);

user_pref("network.proxy.gopher", "");

user_pref("network.proxy.gopher_port", 8080);

user_pref("network.proxy.http", "");

user_pref("network.proxy.http_port", 8080);

user_pref("network.proxy.share_proxy_settings", true);

user_pref("network.proxy.socks", "");

user_pref("network.proxy.socks_port", 8080);

user_pref("network.proxy.ssl", "");

user_pref("network.proxy.ssl_port", 8080);

user_pref("network.proxy.no_proxies_on", "localhost,,");

   5) Now replace "" with your Web Proxy and also replace "8080" port with the webproxy port.

   6) For By Pass the Proxy for Internal Sites then update last property value with comma as separator.

      i.e network.proxy.no_proxies_on

   7) Now start the Selenium server with the following options.

   i.e java -jar selenium-server.jar -firefoxProfileTemplate MyProxyFirefox


Thursday Jun 18, 2009

How to setup a Test Automation Infrastructure using Selenium, JUnit, Hudson & ANT

Goal : Setting up a test infrastructure & automation solution for web application testing (functional testing)

Tools : JUnit, Hudson, Selenium RC, Ant, Xalan


  • Automation should start the tests immediately when a new build is available in the SVN repository (Hudson has scheduling capability)
  • Automation can be invoked using a browser On-Demand, whenever user needs to run tests on a build (User can trigger tests in Hudson using a browser URL)
  • Automation should be running on multiple OS machines & browsers (Hudson Master/Slave approach will solve this issue)
  • Once the automation is completed, it should send a report as an email to the team alias. Old reports also needs to be archived.
  • User should be able to run the automation as a seperate ANT task & from Netbeans IDE
  • Reports can be automatically published as a wiki page in a wiki system which the team uses for project management (Note: This solution will be covered in a seperate blog & NOT in this)


1. Install Hudson in Master / Slave mode

2. Prepare ant scripts so that it will

  • Checkout the product from SVN repository and installs it on test machine
  • Do all the pre requisite for successfully running our tests [Start selenium server and the tests]
  • After the test execution is completed, archive the old reports and save the new report and email it to the team alias.
  • Do all the necessary cleanup at the end

3. Now call these ant scripts within Hudson and schedule it to run as per your requirement

Wednesday Apr 08, 2009

KeyBoard Events in Selenium

Requirement : Need to press "Page Down" key during one of the selenium tests

Solution:  Use typeKeys(locator,value) command to generate a keystroke event.  
In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to send the keystroke events corresponding to what you just typed.

locator can be '//' in this case
value can be the ASCII value of the keyboard keys. Refer the below table for examples

8 Brower Back Button
32 SpaceBar Key (also Page Down key)
33 Shift+SpaceBar key (also Page Up key)
34 (or) 35 (or) 36 Page Down key
Up Arrow
112 Opens a new browser page
116 F5 key (Refresh Browser Page)
118 F7 key (Caret Browsing On)
122 F11 key

Sunday Mar 29, 2009

Selenium Test project based on Netbeans (for dummies)

Here is a simple Netbeans based Selenium Test project that will open Google, enter a keyword and search . You can download the entire netbeans project and then open the project from your Netbeans IDE and run it locally. Before running it, you need to satisfy the below pre-requisites: 

  • selenium-server.jar should be running (java -jar selenium-server.jar)
  • firefox should be installed in your machine


Friday Jul 25, 2008

Reverse XPath - Finding the xpath of a element using bottom up approach

Assume that we need to find the xpath of a link "Login" appearing in a webpage. Usually when we find xpath of a GUI element, we normally follow a top-down approach, meaning the xpath is recorded from the parent level to the child. But there is also a bottom up approach, where in you can begin from a inner child element and navigate all the way up till the GUI element is reached. 

Below is the corresponding xml code and various method of finding XPath of "Login" link. The bottom-up approach is explained by note (e) in the below table.

 Sample XML Code

(a) Using Top Down approach starting from a top node 

(b) Directly accessing the child node using its text value

(c) Directly accessing the child node using child's attribute value

(d) Directly accessing the child node using wildcard search. All occurences of text "Logi\*" is matched by below xpath.It will work in this example since there is only one text "Login" which has occurence "Logi" in it.

(e) Using Bottom Up approach starting from another child node and navigating to the actual node. Note: Here the DOM structure should be maintained (as it is in the xml) between the start node and end node


Monday Jul 21, 2008

Handling child window in selenium using selectWindow()

Here is a scenario which shows how to handle a child window using selenium .

Web application under Test : Liferay Portal
Browser Used : Firefox
XPath Tools  : Firebug

STEP 1: First Identify the window name of the child window which the web application calls. You can use firebug tool to inspect the GUI element to see these details. In the example below, the "select" button is going to invoke a child window "structure"., windowName, windowFeatures, replaceFlag)

STEP 2: Once you identify the child window name, then within your automation script, call the below selenium command "selectWindow" with the child window name as the parameter . Here in this example the corresponding command is browser.selectWindow("structure")

Now the focus goes to the child window. What ever you execute after the above command takes place in the child window .

STEP 3: Inorder to get the focus back to the parent window, you have to again use "selectWindow" with the parameter as null. browser.selectWindow(null)

Tuesday Jul 08, 2008

Identifying XPath of a element using XPath Query

Below are some of the common xpath query which you will need while doing your selenium automation. Using xpath query, your selenium testing much stable since the slightest change of the GUI wont break your automation.

GUI Element
Corresponding XPath
<input type="submit" value="Save"/> //input[@value="Save"] Exactly matches the text "Save"

<input type="submit" value="Save1"/>

<input type="submit" value="Save2"/>

(//input)[1]   matches the 1st input element, "Save1"

(//input)[2]   matches the 2nd input element, "Save2"

<a href="somelink">Structure</a>
Exactly matches the value within a given tag. Here the text "Structure" which is in between the <a> tag (anchor tag)
<a href="somelink">x_structure_y</a> //a[contains(text(),'structure')]
Like wildcard search, matches the input element which has the text "structure" within a given tag
<input type="button" name="ccd_ccd_81533739_removeevent"/>

//input[contains(@name,concat("ccd","_","ccd","_")) and contains(@name,"removeevent")]

Note: The above xpath can be used when the attribute value has a part which is dynamic in nature (here in this case the text in between "ccd_" and "_removeevent" '81533739" keeps on changing everytime the GUI element is accessed)

Matching multiple text(s) pattern of a attribute value
<input type="text" value="Search..."/>
//input[@type='text' and contains(@value,'Search')]
Matches based on multiple attributes of a GUI element . Here the xpath of the text box is derived  based on its 'type' and 'value' attributes

Monday Mar 03, 2008

XPath : Finding GUI element by matching multiple text(s) pattern of a attribute value

Recently i had to spend my whole day searching for ways to find a elements' XPath (a ajax based button) by matching multiple text pattern within a single attribute value. I was using Selenium IDE to automate testing of Sun Portal Server GUI which is based on Ajax.

My Requirement : Uniquely Identify a ajax based button having the below XPath



My Problem : Attribute(@id) value has both constant and dynamic texts which makes it difficult to uniquely identify the element based on its value

If you look at my ajax button's xpath , there is a numeral "81533739" which is not constant and it changes everytime but the first part(ccd_ccd_) and the second part(_removeevent) of the @id value is constant . I want to uniquely identify @id attribute based on these constant text alone

Solution:The below xpath will uniquely identify my element using concat() and contains() XPath methods

//a[contains(@id,concat("ccd","_","ccd","_")) and contains(@id,"removeevent")]


Below are few links which i found helpful for this solution:

Tuesday Oct 30, 2007

Selenium: Coding Standards for Selenium Core Test Tool

Selenium Core project has some agreed upon standards for developing your test scripts. Below is as is from their Readme.txt file


   Coding standards for Selenium Core Javascript code

  Here is a set of conventions agreed by the active Selenium Core
  developers at ThoughtWorks.  Please stick to these guidelines when
  working on the Selenium Core code-base.
  • Whitespace: we use spaces, NOT TABS.  Indent in 4-space increments.
  • Braces: we place open-braces on the same line as the associated keyword,  for example:
        if (command.isBreakpoint) {
        } else {
            window.setTimeout(this.resume.bind(this), delay);
  • Encapsulation: we prefer to encapsulate functions and variables inside objects, where possible.
  • Variable declarations: declare variables (using "var") ... even if they're "global".
  • Class definitions: we're shifting to "prototype.js" style for definition of classes, e.g.
        var MyClass = Class.create();
        Object.extend(MyClass.prototype, {
            initialize: function() {
                // ... constructor code ...
            doStuff: function() {
                // ... method body ...
  • 'Private' functions/properties: we simulate "private" properties by  prepended the name with an underscore ("_"), e.g.
        _resumeAfterDelay : function() {
            // ...etc...
  • Element addressing: use "$(id)" rather than "document.getElementById('id')".
  • Timeout functions: pass function objects to setTimeout(), rather thanstrings, e.g. window.setTimeout(this.resume.bind(this), delay);

Friday Oct 26, 2007

Building a flexible and extensible Test framework around Selenium

Here is a video from Google Test Automation Conference(GTAC) on building a flexible and extensible framework using Selenium Test Tool. Also the presentation slides can be found below

Thursday Oct 25, 2007

History of Selenium Testing Tool

<script type="text/javascript" src=""></script>

Here is a article about the evolution of Selenium Testing Tool on Google Testing Blog

Saturday Oct 20, 2007

Selenium Grid - The Next Gen Functional Testing Tool

Courtesy: Selenium @ Thoughtworks














[1] The Selenium Grid Website
[2]  Video about Selenium Grid on Google Test Automation Conference and the presentation slides


I'm a Quality Engineer at Sun Microsystems. Here in this blog, you may find information about Software Testing, Portal Server, Virtualization, Web2.0 and Misc Technical topics. The views expressed here are personal and does not reflect that of my employer


« July 2016