“Before you speak, listen. Before you write, think. Before you spend, earn. Before you invest, investigate. Before you criticize, wait. Before you pray, forgive. Before you quit, try. Before you retire, save. Before you die, give.”

Thursday, September 2, 2010

Automating functional testing

So here is the drill : You need to wear the testing hat and verify the bugs .
You need to test a huge application and see if some bugs are reproduced.
Typically each bug requires about 3 page navigation and 20 clicks and you need to be able to reproduce it without issues and show it to a co-worker.
My attention span in the open plan office is not that big .. I always click some button I shouldn't have clicked and then have to start all over. Anyway bugs need to be fixed and issues need to be found. You also need to find new bugs and regressions.
Here is the solution: Automate functional testing.
What I used so far and can fully recommend:
1)Selenium IDE - first step is to record the tests and generate the required Java/Ruby Code
2) Use Selenium Java (or Ruby) driver and write the tests in the IDE
3) Start Selenium Server.
4) Run Selenium code from the IDE ( or a C.I. machine like Hudson,CruiseControl)

Here is how I test a simple login , search and logout(Ruby version) :

require "test/unit"
require "rubygems"
gem "selenium-client"
require "selenium/client"

class WorldFredomTest < verification_errors =" []" selenium =" Selenium::Client::Driver.new" host =""> "localhost",
:port => 4444,
:browser => "*chrome",
:url => "http://localhost:8080/",
:timeout_in_second => 60


def teardown
assert_equal [], @verification_errors

def test_login
@selenium.open "/WorldFreedom-war/mainPanel.htm"
@selenium.type "j_username","mihai"
@selenium.type "j_password","freewilly"

@selenium.click "login_button"
@selenium.wait_for_page_to_load "5000"

@selenium.click "searchFreedomsTab_lbl"
@selenium.click "j_id102:searchButton"
@selenium.wait_for_page_to_load "5000"
@selenium.click "logout"


Of course no warranty is provided for the code above. It just works on my PC.
Coding the functional tests should be done by a functional testing team (no connection to the actual development team) and bugs should be reproduced by means of running these tests.
Of course in an agile environment these tests are also used as acceptance tests.
Setting the speed of the tests is also good since making them run too fast will reveal performance problems with the application.

There is a catch here : No test will ever catch a cosmetic bug , a colour which is wrongly used or a table that is creating a horizontal scrollbar. You need a human for that .. and that human tester will be required for the foreseeable future.

No comments:

Post a Comment