Tuesday, October 26, 2010

Selenium IDE : Different examples on input

Using the excellent FireFox add-on Firebug and the ubiquitous Google search page, we get this HTML for the "Google Search" button.

There are many ways to code the IDE for this button e.g.

click btnG

click //input[@value='Google Search']

click //input[@type='submit']

click //html/body/span/center/span/center/form/table/tbody/tr/td[2]/span/span/input

The latter ones are examples of XPath and XPath knowledge is VERY useful when coding the IDE scripts.

To get the XPath construct inside Firebug, right click on the HTML segment and then select "Copy XPath".

To check your script without having to run it, load the Click command that you want to test and then select the "Find" button to the right of "Target". The "Google Search" button will be highlighted with a green border if the script works otherwise an error message will be displayed.


Selenium RC : Importing a script from Selenium IDE

As a quick start to get up and running with Selenium RC, you can get Selenium IDE to capture the session. Here's the IDE script to search Google for "Selenium RC".


New Test
open /
type q selenium rc
clickAndWait //input[@value='Google Search']


Then Options / Format / Java (JUnit)

This produces the following code:

package com.example.tests;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

public class Untitled extends SeleneseTestCase
public void setUp() throws Exception
setUp("http://change-this-to-the-site-you-are-testing/", "*chrome");

public void testUntitled() throws Exception
selenium.type("q", "selenium rc");
selenium.click("//input[@value='Google Search']");

You can download Selenium RC from here.

Unzip the file and then start Selenium RC from a command prompt.

...\selenium-server-1.0.3>java -jar selenium-server.jar

I run JUnit inside Netbeans.

After a bit of massaging, the code above becomes:

import com.thoughtworks.selenium.*;

public class GoogleSearch extends SeleneseTestCase

Selenium browser = null;

public void setUp() throws Exception


public void testGoogleSearch() throws Exception

browser = new DefaultSelenium("localhost", 4444,


browser.type("q", "selenium rc");
browser.click("//input[@value='Google Search']");

verifyEquals("selenium rc - Google Search", browser.getTitle());


This is invoked by a JUnit test:

public void testGoogleSearch() throws Exception
GoogleSearch instance = new GoogleSearch();


Friday, October 22, 2010

Blogger : Image messes up text

Wrote a new post and then decided to add an image using Blogger's image tool.

I use the Left / Large image options.

The text that was supposed to be below the image now turned up at the right hand side of the image about half way down.

Tried br and /br and a few other things but no go.

Mr. Google to the rescue.

Between the image and the following text insert:

Now the text is below the image, just as it should be.


IE : Fixing the "Do you want to view only the web page content" popup

The most annoying part of Internet Explorer (IE) 8 is the "Do you want to view only the webpage content that was delivered securely?" popup that forces you to continually click "No".

Maybe it's useful when doing Internet banking but I get it every time I open up Blogger. Why wouldn't I want to see the whole page?

The solution is simple:

Tools / Internet Options / Security / Custom level / Miscellaneous / Display mixed content

and change the option from "Prompt" to "Enable".

Reply "Yes" to the "Do you want to change this option?" question and OK out.

Problem solved.


Thursday, October 21, 2010

Netbeans : jQuery code complete / auto complete

Need to do some jQuery work and it's a lot easier with auto complete / code complete.

See my SO answer here.


Wednesday, October 20, 2010

JMeter : Reading variables from a file

Done a lot of load testing with JMeter.

Quite often, I need to try load testing for lots of user logins. To do this you can't hard code the value in the form - you have to somehow read it from a file.

Enter JMeter's String From File

"The StringFromFile function can be used to read strings from a text file. This is useful for running tests that require lots of variable data. For example when testing a banking application, 100s or 1000s of different account numbers might be required."

For a field called userId, enter something like the following in the Value column:

${__StringFromFile(x:\Path to csv file.csv,userId,,)}

It would look something like this:

The csv file is a simple one column list of user Ids.


Thursday, October 14, 2010

Stackoverflow : Flair

Playing around with my StackExchange "flair"


profile for nzpcmad on Stack Exchange, a network of free, community-driven Q&A sites


profile for nzpcmad at Stack Overflow, Q&A for professional and enthusiast programmers

Meta Stackoverflow

profile for nzpcmad at Meta Stack Overflow, Q&A about the Stack Exchange engine powering these sites


profile for nzpcmad at Programmers, Q&A site for expert programmers interested in subjective discussions on software development


profile for nzpcmad at Server Fault, Q&A for system administrators and IT professionals

Food and Cooking

profile for nzpcmad at Cooking, Q&A for professional and amateur chefs


profile for nzpcmad at Super User, Q&A for computer enthusiasts and power users


Selenium RC : Using a spreadsheet with Selenium

Quite a lot of the work I've done with Selenium is very repetitive e.g. navigating to an application, logging in, doing some test and logging out.

It made sense to put this in some kind of spreadsheet where each line would have the application URL, login credentials (user field name, user name, password field name, password) and the name of the "Submit" button. Then do some application work perhaps and then logout.

The program could go through the spreadsheet row by row populating the values and then posting the page.

I put all the data into a csv file so I could use opencsv to read the rows.

The code looks something like:

CSVReader reader = new CSVReader(new FileReader("x.csv"));

while ((nextLine = reader.readNext()) != null)

if (!csvURL.equals("Exit"))
selenium = new DefaultSelenium( "localhost",



selenium.type(csvUserText, csvUser);
selenium.type(csvPasswordText, csvPassword);


The code runs through the spreadsheet until it finds an "Exit" in the URL field.

populateParams looks like:

public void populateParams (String nextLine[])
csvURL = nextLine[1];
csvUserText = nextLine[2];
csvUser = nextLine[3];
csvPasswordText = nextLine[4];
csvPassword = nextLine[5];
csvSubmit = nextLine[6];


JMeter : Setting up a HTTP Proxy to capture traffic

You can build up a JMeter test plan yourself but it's much easier to set up a proxy and let JMeter do all the grunt work for you.

There are some JMeter proxy Step-by-step instructions here.

If your environment has a proxy you need to tell JMeter about it via the command line e.g.

jakarta-jmeter-2.4\bin>jmeter -H yourProxy.co.nz -P yourProxyPort

The basic idea is that you change your browser settings to point to the JMeter HTTP Proxy and then the JMeter proxy forwards the packets to the real proxy configured in the command line.

To setup the JMeter proxy after you have started up JMeter, right click:


Add / Non-Test Elements / HTTP Proxy Server

Choose a spare port (in this case 9090) and configure in the Port box.

Now you need to change your browser settings. Use

Tools / Internet Options / Connections / LAN Settings / Proxy Server

Set the proxy server to localhost (or and the port number to 9090.

In JMeter, right click Test Plan / Add / Threads / Thread Group.

Doing this forces the proxy to capture the traffic inside of the plan.

Now click on HTTP Proxy Server and click Start at the bottom.

Now open your browser and browse to the URL you want to test.

In JMeter, you should see something like:

Note that it's a good idea to add a HTTP Cookie Manager as well as this enables cookies to pass between pages.


Wednesday, October 13, 2010

Selenium IDE : Input too "early"

I've seen this behavior a number of times.

You run a Selenium IDE script where you have a

type - token - text

scenario and Selenium will complain that the field "token" does not exist.

But it does - at this point, you are staring at it in the browser.

What sometimes seems to happen is that the page loads, Selenium sees the title and moves to the next line of the script but the actual fields haven't loaded yet and so can't be found.

The way around this is to look for a bit of text near the input field and then do a


That way the input field is there when the script requires it.


Selenium RC : Setting up a Firefox proxy

The normal way to use Selenium RC if your environment has a proxy installed is to use the command line e.g.

java -jar selenium-server.jar -Dhttp.proxyHost=xxxproxy.company.nz -Dhttp.proxyPort=8082

I could never quite get this to work.

I use the Firefox Profile Manager.

The command line is:

firefox -P

You need to do this from wherever Firefox is installed on your PC e.g.

x:\Program Files\Mozilla Firefox

When the "User Profile" box pops up, choose "Create Profile" and follow the wizard.

Run the command line again and select the new profile and then select "Start Firefox"

Configure Firefox to use a manual proxy:

Tools / Options / Advanced / Network / Settings

Configure the manual proxy to point to the proxy in your environment.

The Selenium RC command line you need to use this is:

java -jar selenium-server.jar -firefoxProfileTemplate "Path to profile created above"

GOTCHA: Remember to run the Profile manager again and select "default" to return to your normal profile otherwise any new changes will be mode to the wrong profile.