Verify database records in functional testing

Posted by Zhimin Zhan on November 30, 2009|Comments|Read full article
Function testing, in a certain way, is verifying the data (retrieved or stored at the database) through the user interface layer. Sometimes, it might be easier to verify database records directly, some SQL skills are required though. RWebSpec provides an easy way to do so, in a easy 3 steps. # Connect to the database # Choose the table # Use easy syntax or SQL to do verification
 story "Check Mysql database" do
    connect_to_database mysql_db(:host => "localhost", :database => "lavabuild_local", :user => "root", :password => ""), true
    load_table("projects") # now can use Project.xxx for easy-to-user datbase query on this table

    Project.count.should == 1  # record count
    Project.first.name.should == "BuildMonitor"
    Project.last.name.should == "BuildMonitor"
    Project.exists?(:name => "BuildMonitor")
  end
Check out the _verify_database_spec.rb_ in demo project.

Testing complex sites

Posted by Zhimin Zhan on November 19, 2009|Comments|Read full article
We are not living in a perfect world, some web sites are created without automated testing in mind. So we have some sites with complex javascripts, elements without IDs or duplicated IDs. . Here is one, the test scripts generated from TestWise/Watir recorder won't work.
  scenario "Site with complex JavaScripts: Recorded" do
    select_option("intFrom", "Brisbane")
    click_link_with_id("toSYD")
    select_option("intDepMonthYear", "Jan 2010")
    select_option("intDepDay", "Sun 03")
    select_option("intRetMonthYear", "Feb 2010")
    select_option("intRetDay", "Wed 03")
    select_option("intAdults", "2")
    click_button("Go")
  end
1. Line 3: _click_link_with_id("toSYD")_ failed with error 'Unable to locate element, using :id, "toSYD"' *Reason:* a javascript window pops up as user enters text in destination text field, however that event is not fired when running the test scripts. *Solution:* Click the image to bring up the javascript popup window manually.
   image(:id, "toBoxPlusSign").click 
# Line 10: _click_button("Go")_ had no effect *Reason:* There are more than one button with caption 'Go' on the page
 
 
 
*Solution:* Click the specific button by using :index
    button(:text => "Go", :index => 2).click # click 2nd 'Go' button
Here is the complete test script:
  scenario "Site with complex JavaScripts:  Working version" do
    select_option("intFrom", "Brisbane")
    image(:id, "toBoxPlusSign").click # bring up the popup    
    click_link_with_id("toSYD")
    select_option("intDepMonthYear", "Jan 2010")
    select_option("intDepDay", "Sun 03")
    select_option("intRetMonthYear", "Feb 2010")
    select_option("intRetDay", "Wed 03")
    select_option("intAdults", "2")
    button(:text => "Go", :index => 2).click # click 2nd 'Go' button
  end

Work with frames

Posted by Zhimin Zhan on November 10, 2009|Comments|Read full article
TestWise Recorder does not support operations in frames yet. The work around is simple: Ues Watir syntax for operations in frames. Let's walk through with an example. Here is a sample page with an iframe embedded, its html source fragment of frames as below: