I would put the code to iterate the hash inside your test_* function.
Simply make the first statement load your data ...
then iterate over a child method.
class MultiAddressTest < Test::Unit::Testcase
def setup
@testSite = "http://www.mapquest.com"
@ie = IE.new @testSite
# default behavior, not necessary =>@ie.set_fast_speed
# wrap in one call to IE.new => @ie.goto(@testSite)
end
def teardown
@ie.close
sleep 5
end
def validate_direct( street, zip )
@ie.text_field( :name, "address" ).set street
@ie.text_field( :name, "zipcode" ).set zip
@ie.button( :value, "Get Directions" ).click
# Do Assertions to validate assumptions about web page displayed after click
end
def test_directions
load "input.rb"
$plan.each { |curr|
validate_direct curr[ "street" ], curr[ "zip" ]
end
end
end
... should work. I took out your heavy use of global variables ...
not necessary and generally considered "error prone".
j.
On 10/17/05, Terry Peppers <[EMAIL PROTECTED]> wrote:
> I tried posting this to the mailing list last night to no avail, so if this
> does show up as a double post I apologize in advance.
>
> I've been using Watir for the past couple of weeks with great success. My
> company has been able to stay a bit more agile when it comes to releases
> because of the unit tests for the code and because of the Watir tests for
> the interfaces we've been building. It's made for some less stressful
> releases - so I'm very thankful to the Watir community for this.
>
> I've been chewing on a problem for the past couple of weeks and getting no
> success. I don't think it's a problem with Watir as much as it's my
> inexperience with Ruby.
>
> My problem is this: What if I want to run a unit test multiple times but
> with different data each time through the test?
>
> For example, let's say I have the following unit test - I'm using MapQuest
> here as an example. My real world example does deal with addresses - and
> MapQuest is a good example, I think.
>
> Here's some sample code:
>
> *** begin code ***
>
> require 'watir'
> require 'test/unit'
> include Watir
>
> class MultipleAddressTest < Test::Unit::TestCase
>
> def setup
> $testSite = "http://www.mapquest.com"
> $street = "123 Foo"
> $zip = "90210"
> $ie = IE.new
> $ie.set_fast_speed
> $ie.goto($testSite)
> $ie.wait
> end
>
> def test_directions
> $ie.text_field(:name, "address").set($street)
> $ie.text_field(:name, "zipcode").set($zip)
> $ie.button(:value, "Get Directions").click
> sleep 7
> $ie.close
> end
>
> end
>
> *** end code ***
>
> My problem is this - how can I run this same unit test multiple times for
> different addresses. My object orientation isn't so good, and I'm not really
> familiar with Unit Tests outside of what's in Watir's limited documentation.
> Anyway, I digress.
>
> Let's say I have a hash that I can iterate through:
>
> *** begin pseduo code ***
>
> $plans = {
> "1181" => {
> "street" => "36 Dearborn Street",
> "zip" => "01979"
> },
> "1183" => {
> "street" => "940 10th Street",
> "zip" => "80302"
> },
> "1184" => {
> "street" => "14030 Biscayne Blvd",
> "zip" => "33181"
> },
> "1185" => {
> "street" => "807 Reilly Ct",
> "zip" => "95747"
> },
> "1187" => {
> "street" => "21388 West Lane",
> "zip" => "19958"
> },
> "1188" => {
> "street" => "7877 Forest Blvd",
> "zip" => "55125"
> },
> "1189" => {
> "street" => "10 River Walk Plaza",
> "zip" => "55107"
> }
> }
>
> $plans.each_value do |plan|
> street = plan['street']
> zip = plan['zip']
> puts street, zip
> end
>
> *** end pseudo code ***
>
> How do I link up the ability to iterate through this hash for each pair of
> addresses and zip codes with the Unit Test that takes address and zip as
> inputs? I'd rather not write multiple tests that do the same thing - seems
> repetitive work for a task that should be easy to accomplish with an
> iterator.
>
> I hope I'm being clear - can anyone help me? I'm sure it's a very easy fix.
>
> Thanks.
>
> t.
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
>
>
>
--
"http://ruby-lang.org -- do you ruby?"
Jeff Wood
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general