A browser application test tool you should not work without.

Selenium: A free Firefox extension that can handle all of your repetitive functional testing requirements for your browser application. Sound like a browser activity recorder? Selenium can handle error alerts, ajax updates, and dynamically generated HTML, which most activity recorders fail miserably with. I cannot get enough of this application, it has already saved me countless hours.


With Selenium, I can make a host of bug fixes in an application, and instead of poking manually through the application to test the change, and look for downstream unintended errors, I can simply run a pre-recorded test. With the project I am working on, it took about 45 minutes to click on every button, test the updating of every field, and trigger every validation event, but after I recorded the session all subsequent tests take about 4 minutes. Yet the activity recording is the easy stuff. Since Selenium saves its tests as HTML files, they are easy to edit, and even easier to write before the functionality is in place to record.

Enough words, I’ll just throw some screenshots together to show you how it works.

So being a Firefox extension, you just need to click Tools >> Selenium IDE to start. The IDE is a separate FF window that pops up and is very basic in appearance. When you open the IDE it defaults to Record mode and you can toggle the record mode with the red dot icon in the upper right. You can see some other typical icons to “Play” a recorded test, Pause a test, and even “Step” through a test. At the bottom of the IDE is the log window where any errors will be displayed.

So a very basic primer would leave the IDE in record mode, and in Firefox open your test site. In my example, my login page contains two fields for the user to enter the last six digits of their social security number, a field for their last name, a field for their first name, and three fields to enter their birth date. Then they would click the “Login” button that will take them to a details page.

At the detail page the user would click a button that brings up a modal dialog box (YUI Dialog) where the user can make a change to their address. When they click the “Save” button on the dialog box, an AJAX call posts the information back to the server, and the server returns some javascript to be evaluated which updates the static text on the details page. I then want to verify that the DIV id that contains the address information that was changed now has the new value.

For this test I am done, so I click “Sign Out” and finish the test. We are left with a list of all the actions that I took (second image on the left). Most of these commands are pretty basic like “open”, “type”, and “click” since these are staples of activity recorders. But in the highlighted action, I told Selenium to wait until it sees the correct value inside the “…lblAddress2″ DIV id. So if the AJAX call, or the returned javascript fail, the test will fail and that line in the action list turns red.

An example of some of the commands that you can apply to a test are listed in the third image on the right. To bring up the context-sensitive commands, highlight the value or field you want to evaluate, and right click. You can assert a value somewhere, verify a DIV value, a field value, and even the value inside a table cell. You can also store a value for use later in the script. In addition, you can use the IDE to select a command, and that list is ALOT longer. Basically, any event that you can capture or monitor in Javascript is available, even custom conditionals where you can write a custom Javascript function to be called by Selenium.

The capabilities of this little extension are phenomenal and I probably run my full function test 2-3 times a day for every little change I make in the back end. Even when I changed the spelling of one of my alert boxes, the Selenium test failed. You can even verify the presence of an image, like a validation error image, that only shows when there is an error. Someone could write a small book on this.

Now if you have some commercial software that you use for testing, Selenium may not be able to replace it, but anyone who had a company that is too cheap to buy that kind of software, you should not live without more Selenium in your day.

2 Responses to “A browser application test tool you should not work without.”

  1. Sushant Says:

    Can you please send some sample code about verifying the contents present in the tag?

  2. Murali Says:

    I’m new to bloggong & My blog is about basics of Software Testing,Manual Testing,SDLC,Testing Techniques,Levels of Testing,Types of Testing,Test Planning,Test Execution,Test Development,Bug Tracking,Result Analysis,Test Design Techniques and QTP. so I write about that which I know.Give it a visit if you get a chance..
    feel to free to visit:http://softwaretesting-guide.blogspot.com/
    Regards,
    Murali

Leave a Reply