--------------030007050300070001020000
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Dick said:
did you find webunit? it's designed to allow unit testing of webapps, but
i'm not sure if it's maintained (and the docs were a bit scanty).
Might give you some ideas though?
Also I have a vague recollection of something coming out of rails that let
you test the frontend, but istr it worked by having the View generate xhtml
and parsing that....
After downloading webunit and taking a quick look (thus all my
impressions could be wrong -- please correct me if it is) at it, I think
that I am taking a different approach than it. First of all, it doesn't
seem to check non-form data. Also, my approach relies on parts of the
displayable text (not hidden form values) to check for values on the
page. This is so the tests are more readable without having to modify
the system under test at all.
Below is a simple test using my framework
SIMPLE_PAGE_1 = "<p>Value: 5</p>"
SIMPLE_TEMPLATE_1 = "<p>$(Value)$k$: $(\\d+)$vi$</p>"
def test_simple_page_1
$TRACE.set_level 0 do
page = HTMLController:
age.new(SIMPLE_PAGE_1)
elements = page.parse(SIMPLE_TEMPLATE_1)
assert_equal(5, elements["Value"])
end
end
Or a test with a table:
TABLE_PAGE_1 =
"<h1>Modem 1</h1>" +
"<table>" +
"<tr>" +
"<td>Field 1</td>" +
"<td>Field 2</td>" +
"</tr>" +
"<tr>" +
"<td>Value 1.1</td>" +
"<td>Value 1.2</td>" +
"</tr>" +
"<tr>" +
"<td>Value 2.1</td>" +
"<td>Value 2.2</td>" +
"</tr>" +
"</table>"
TABLE_TEMPLATE_1 =
"<h1>$(Modem 1)$t$</h1>" +
"<table>" +
"<tr>" +
"<td>$([\\w\\s.]+)$th$</td>" +
"<td>$([\\w\\s.]+)$th$</td>" +
"</tr>" +
"<tr template-arity=\"*\">" +
"<td>$([\\w\\s.]+)$tv$</td>" +
"<td>$([\\w\\s.]+)$tv$</td>" +
"</tr>" +
"</table>"
def test_simple_table
$TRACE.set_level 0 do
page = HTMLController:
age.new(TABLE_PAGE_1)
elements = page.parse(TABLE_TEMPLATE_1)
assert_equal(2, elements["Modem 1"].size)
assert_equal("Value 1.1", elements["Modem 1"][0]["Field 1"])
assert_equal("Value 1.2", elements["Modem 1"][0]["Field 2"])
assert_equal("Value 2.1", elements["Modem 1"][1]["Field 1"])
assert_equal("Value 2.2", elements["Modem 1"][1]["Field 2"])
end
end
My form stuff is still under development. My long-term hope is that it
can be used to automatically drive sites that have no other automation
interface.
Steve Tuckner
--------------030007050300070001020000--