Sunday, January 4, 2009

Selenium Vs Watir

Selenium and Watir the best front end based web application testing frameworks at present. Even though there are other frameworks out there, like webtest, they cannot scale up to the web 2.0 style client heavy web applications. They are not good with XHRs are Javascripts. Both selenium and watir supports test suites in Java or Ruby and you can replay them subsequently.

Selenium has a firefox based recorder tool also, that can capture browser actions and create test cases in multiple languages like Java and Ruby.

Best way to start on Selenium is by watching the tutorial they have on their website. Setup and running it is as easy as they tell us in this tutorial.

The IDE can show you Java/Ruby code for the recorded test case. Copy that and run as java test case with selenium apis in classpath.

This is for simple scenario testing. For a larger, concurrent load testing, use Selenuim RC framework. This is capable of running tests in parallel threads.

Even though Selenium is cool, my personal favorite is Watir. There is only one factor that makes Watir the winner, according to me that is, and that factor makes all the difference. It is the philosophy with which these tools have been made. Watir is a tool that is made by testers and for testers, by focusing on what really should be the focus point for the person who uses it.

A simple scenario discussion will prove this. In Selenium, after a request submit is done by the script, it doesn't know how to detect the arrival of response. So, technically it waits for a specified amount of time and then assumes the page has been loaded with response content. In test suites, it comes as a line like this one-selenium.waitForPageToLoad("30000");Defining this wait period becomes the script writer's (tester) responsibility. Should they be?

If you have a process to run test cases on multiple environment's, it can worsen the scenario so quickly.

Also, your load testing results are not accurate when you have ambiguous wait periods defined all over request submissions.

In my experience, i have seen the recorded tests not functioning properly because the way page elements are automatically detected may not be the way you want it to be. You will understand this if you write a test case to login to your gmail account and read a mail or study the recorded test case source in detail.

Watir, on the other hand works embedded within the browser in a way. This means, it can detect when the server response comes back. Tester can focus on what the response value should be rather figuring out what the approximate wait period on each page should be. Watir is also tested to be better for Ajax based testing.

Watir has the full API set support from Ruby, which makes it much more powerful than Selenium. For load generation and parallel threads, one needs to write Ruby scripts for test cases. All that is covered in their test case.

On the cons side, Watir doesn't have a matured recorder tool. Watir is a Ruby framework and knowledge of Ruby is mandatory. But hey, if you are of the learner type Ruby is a cool place to hang around. So, if you are in the mood, jump on to Watir::IE.new.goto "Watir website"


Trivia: Ruby is really good when it comes to utility frameworks like Watir, BuildR, some report generation with the good regex support or quick prototyping. You can always build small applications with Ruby and Rails. But will it ever be on par with an enterprise platform like Java? Not at the moment, i guess. Had that been the case, we would never have had to come up with J2EE; programmers would have been happily coding in C and Perl. Ruby guys need to talk more about scalability, transaction managements and other enterprise application attributes if they want Ruby to be anything more than what it is currently.

No comments:

Post a Comment