Talking testing, automation... and anything else.

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 '', :chrome

# initial sort... => 'Name').click

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

# 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}"


Do feel free to comment and/or make suggestions!

Leave a Reply