From: Esteban Chan on
We're testing. This script below will go through the list of url's, and
on each url, write out the results of the script to a file. These
results are a) the last 3 digits of the url string
b) the 1st href on the page
c) the 3rd href on the page
a,b,c are seperated by a tab. each url result array is on a separate
line.

We run the following ruby-watir test script
require 'rubygems'
require 'hpricot'
require 'watir'
browser = Watir::Browser.new
[
('http://www.example.com/add1.htm?prod=123'),('http://www.example.com/add1.htm?prod=124'),('http://www.example.com/add1.htm?prod=125)].each
{|url|
browser.goto url
sleep 4
browser.link(:index, 1).href
browser.link(:index, 3).href
target=url.slice(-3..-1)+"\t"+browser.link(:index,
1).href+"\t"+browser.link(:index, 3).href
outfile = File.new("test.txt", "a")
outfile.puts target
}
browser.close

################################
if the javascript on the targeted url page loads slowly, or not at all,
ruby throws an exception
Watir::Exception::UnknownObjectException, since the 1st or 3rd link
aren't there.

we used "sleep 4" to slow down the script, but would rather have the
test run as fast as it can.

since I am a newbie to ruby, my exception handling block code attempts
aren't working - so my syntax is off. I've gone through more than a few
hours of trying various ways of handling the exception with 'rescue
Exception => e'

The exception handling should simply put an "unknown" as the values for
the missing links, and then go to the next url in the array.

This is our first ruby attempt. On another note, we landed on
ruby/watir/hpricot because we didn't locate any testing tools that will
run in FreeBSD's command line. This test script requires the browser to
process the javascript on the targeted url.

Does anyone know of a nix solution to testing instead?
--
Posted via http://www.ruby-forum.com/.