Talking testing, automation... and anything else.



23
Jan 13

Watir-Webdriver Sort Test

watir.logoWhile convalescing this past weekend from some kinda cold/funk that’s been making the rounds, I spent some time playing with Watir-Webdriver. I really like Watir and have heard good things about Webdriver, so I wanted to see for myself. As an exercise, I decided to port my Sahi sort test from a previous post… here’s what I came up with.

# ~ sort test...

require 'rubygems'
require 'watir-webdriver'

browser = Watir::Browser.start 'http://www.javascriptkit.com/script/script2/sorttable.shtml', :chrome

# initial sort... 
browser.link(:text => 'Name').click

# collect table column elements in an array... 
app_sorted_values = Array.new
# itterate through each row (skip the 1st)... 
browser.table(:id, 'table0').rows.each.drop(1).each do |row|
	app_sorted_values << row.cell.text
 end 

# sort with ruby case-insensitive... 
ruby_sorted_values = app_sorted_values.sort {|a,b| a.upcase <=> b.upcase}

puts "App sort: #{app_sorted_values} \nRuby sort: #{ruby_sorted_values}"

browser.close

Do feel free to comment and/or make suggestions!