From: stevetuckner Date: 2005-01-14T07:13:48+09:00 Subject: Re: [Q] Web Testing in Ruby --------------030007050300070001020000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Dick Davies wrote: >* stevetuckner [0124 21:24]: > > >>Laurent Julliard wrote: >>I am currently working on one (when time permits). My idea is to use a >>template of the web page under test to allow the checking of values both >>in a form and just within plain HTML. It parses the HTML so that can >>check for identical structure (though not identical white space). It >>also can handle differences in the number sub-elements (like multiple >>rows in a table). After parsing and comparing with the template, it >>returns a nested hash/array structure to allow the checking of values. >>Parts not done include the modifiying of form values and their resubmission. >> >> > >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 = "

Value: 5

" SIMPLE_TEMPLATE_1 = "

$(Value)$k$: $(\\d+)$vi$

" def test_simple_page_1 $TRACE.set_level 0 do page = HTMLController::Page.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 = "

Modem 1

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
Field 1Field 2
Value 1.1Value 1.2
Value 2.1Value 2.2
" TABLE_TEMPLATE_1 = "

$(Modem 1)$t$

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
$([\\w\\s.]+)$th$$([\\w\\s.]+)$th$
$([\\w\\s.]+)$tv$$([\\w\\s.]+)$tv$
" def test_simple_table $TRACE.set_level 0 do page = HTMLController::Page.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--