I would like gently to suggest that your inexperience as a
developer isn't the problem here. This is a fundamental question about
test automation in general. You're not alone; I'm not convinced that very
many people have thought particularly hard about it. I think enough time
has gone by that people now understand that a debugger will neither find nor fix
your bugs. In a similar kind of way, WATIR will not use or test your
application; YOU will. WATIR will help you to do that by pressing
keys or performing mouse clicks, scanning the screen and reacting to patterns
that you've told it about, and doing all that really quickly. So: if
Store 2 requires you to answer some questions, what would those questions
be? If Store 2 requires you to behave differently, what are the
differences? At what point do they diverge from the behaviours for
Store 1?
The fundamental problem is: what do you mean by "a
generic test"? For me to answer this question in a way that would help
you, I would have to know what you would do manually and
cognitively if you didn't have WATIR available. Then solving the
programming problem is relatively straightforward. Relatively. And I
don't think you'll need our help as much as you might think you
do.
One way you can do some of the things that you're doing
below is to take the "do some assertions" part, and wrap those into a method
that /isn't/ a test_something method, and to take the stuff where you enter data
and do something similar, such that we might see
def test_store_1
login_to_store_1
order_some_product
fill_in_some_data
click_submit
logout
end
def_test_store_2
login_to_store_2
order_some_product
fill_in_some_data
click_submit
logout
end
def login_to_store_1
enter_user_name_and_password
end
def login_to_store_2
enter_user_name_and_password
enter_credit_card_info
answer_some_questions
end
def fill_in_some_data
@ie.text_field(:name,
"fname").set("Terry")
@ie.text_field(:name, "lname").set("Peppers")
@ie.text_field(:name, "address").set("123 Foo")
@ie.text_field(:name, "zip").set("90210")
@ie.text_field(:name, "city").set("Foobar")
@ie.text_field(:name, "state").set("FO")
end
@ie.text_field(:name, "lname").set("Peppers")
@ie.text_field(:name, "address").set("123 Foo")
@ie.text_field(:name, "zip").set("90210")
@ie.text_field(:name, "city").set("Foobar")
@ie.text_field(:name, "state").set("FO")
end
def click_submit
@ie.button(:name, "submit").click
end
On the other hand, if the stores themselves don't behave
generically, then the tests will have to incorporate behaviour that's
appropriate to the differences:
def_test_store_2
login_to_store_2
jump_through_extra_store_2_hoops
order_some_product
fill_in_some_generic_data
fill_in_other_stuff_specific_to_store_2
click_submit
logout
end
You see?
---Michael
B.
From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Terry Peppers
Sent: January 11, 2006 11:32 AM
To: [email protected]
Subject: [Wtr-general] Design Problems
Sent: January 11, 2006 11:32 AM
To: [email protected]
Subject: [Wtr-general] Design Problems
I'm kind of @ a crossroads right now and I think my inexperience as a developer is beginning to shine pretty hard. Here's my general problem: I'm trying to compose a generic test that I can use to test many different sites - however, each site behaves slightly different then the other sites. So I'm @ a bit of a design quandry.
An example:
class OrderTest < Test::Unit::TestCase
def setup
@ie = IE.new
@ie.goto("http://www.store1.com")
@ie.wait
end
def order_something
# pick a product
@ie.link(:name, "some_product).click
# do some assertions
# ...
# click
@ie.button(:name, "done").click
# fill in some data
# do some assertions
# ...
@ie.text_field(:name, "fname").set("Terry")
@ie.text_field(:name, "lname").set("Peppers")
@ie.text_field(:name, "address").set("123 Foo")
@ie.text_field(:name, "zip").set("90210")
@ie.text_field(:name, "city").set("Foobar")
@ie.text_field(:name, "state").set("FO")
# click
@ie.button(:name, "submit").click
# do some assertions
# ...
end
def teardown
@ie.close
end
end
So this example works great for 'store1' but what happens if I want to test 'store2.' 'Store2' requires a credit card and wants to ask you some questions.
Right now I'm cluttering up my test case with a lot of conditionals/case statements so that it can react accordingly, but that doesn't seem really elegant to me. Does anyone know of a better way to do this? I was chewing on possibly creating a 'order_something' object that could insert the proper steps and assertions based on the 'store' that it's testing - but to be honest I'm not even sure how to do that. Also, maybe this is a place where exceptions should be used - I don't think so, but I don't know. Any ideas?
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
