Comprehensive Selenium integration in Hudson with Selunit

This example tells you how to integrate Hudson with Selunit. Selunit can be used to execute Selenium tests directly from Selenium IDE in Hudson builds and using Hudson reporting capabilities provided for JUnit, where Selunit transforms Selenium reports to. The goal is to point out a comprehensive solution beginning with a convenient way creating and maintaining tests using Sel IDE, running them concerning multiple browsers/environments and finally monitoring and analyzing reports in Hudson.

All resources used in this tutorial are focused on examples for testing a travel community portal reiselichter.de (“travel lights” in English).

For more information go to http://www.selunit.org

This Article is Submitted by Michael Blank

Issues with Selenium RC and Selenium IDE typeKeys

The typeKeys doesn’t type the ‘dot’ in the text we are entering:
selenium.typeKeys(“assigned_to”, “seleniumwiki.com”);
Your output will be seleniumcom and not selenium.com. The “dot” is missing. This is happening with both Selenium RC and Selenium IDE.
Here is another issue with typeKeys
selenium.typeKeys(“id=username”, “TypeKeys”);
Your output will be “TpeKes” in the textfield. The “Y” is stripped out.
When use “typeKeys” to type “y”, it will active “file” menu in firefox.
Other characters are all OK.

This issue is now fixed when you use the WebDriverBackedSelenium class because you use WebDriver as a backend instead of Selenium Core. The merge with WebDriver for the Sel-IDE side is in progress. But I’ll see what happens in your case but it’s probably in Selenium Core where the problem occurs and not in Selenium IDE. The file concerned is htmlutils.js (function triggerKeyEvent).

How to solve the link has target ‘_blank’, which is not supported in Selenium

Here is an example¬† <a id=”ctl00_contentSection_ViewSeleniumWiki” target=”_blank” href=”http://www.seleniumwiki.com”>View Selenium Wiki</a>
If you use selenium IDE to click on the link you will get the error message : Link has target ‘_blank’, which is not supported in Selenium! Randomizing target to be:

Here is the solution

<tr>
<td>storeAttribute</td>
<td>//a[@id='ctl00_contentSection_ViewSeleniumWiki']/@href</td>
<td>href</td>
</tr>
<tr>
<td>echo</td> ' this is only optional
<td>${href}</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${href}</td>
<td></td>
</tr>

Submitted by Pavandeep Puddupakkam

How did this solution work for you? Do you have a better alternative? Feel free to share your thoughts in comments section below.

Handling Selenium error – verifyXpathCount

Here is an error that I got when I executed the following verifyXpathCount command
<tr>
<td>verifyXpathCount</td>
<td>xpath=//span[@id=’ctl00_contentSection_GoogleAFSRight’]/div/div[@class=’SingleVertical’]/a[@class=’Heading’ and @href]</td>
<td>4</td>
</tr>

Error Message
Unexpected Exception: message -> The expression cannot be converted
to return the specified type., code -> 52, INVALID_EXPRESSION_ERR
-> 51, TYPE_ERR -> 52, result -> 2153447476, name ->
NS_ERROR_DOM_TYPE_ERR, filename ->
chrome://selenium-ide/content/selenium/scripts/htmlutils.js, lineNumber
-> 1170, columnNumber -> 0, location -> JS frame ::
chrome://selenium-ide/content/selenium/scripts/htmlutils.js ::
anonymous :: line 1170, inner -> null, data -> null

I made the following change and the issue was resolved.
<tr>
<td>verifyXpathCount</td>
<td>//span[@id=’ctl00_contentSection_GoogleAFSRight’]/div/div[@class=’SingleVertical’]/a[@class=’Heading’and @href]</td>
<td>4</td>
</tr>

I removed the xpath=.

Submitted By: Pavandeep Puddupakkam

Selenium – createCookie

createCookie(nameValuePair, optionsString)
Arguments:
  • nameValuePair – name and value of the cookie in a format “name=value”
  • optionsString
    – options for the cookie. Currently supported options include ‘path’,
    ‘max_age’ and ‘domain’. the optionsString’s format is “path=/path/,
    max_age=60, domain=.foo.com”. The order of options are irrelevant, the
    unit of the value of ‘max_age’ is second. Note that specifying a domain
    that isn’t a subset of the current domain will usually fail.
Create a new cookie whose path and domain are same with those of current page under test,  unless you specified a path for this cookie explicitly.
http://www.cloudtesting.com/blog/2009/08/24/howto-cookie-manipulation-with-selenium-and-cloud-testing/