[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[Q] Web Testing in Ruby

Laurent Julliard

1/13/2005 9:02:00 PM

Sorry if this question has already been asked 200 times... I'm trying
to find a Ruvby package that would allow us to test a web based
application directly through the Web interface. The idea here is that
the Ruby testing application would basically behave like a web browser
: GET/POST requests, manipulate HTML forms received as objects so
that it is easy to fill them out and send them back to the server

Any pointer or suggestions would be really helpful

Thanks!


18 Answers

djberg96

1/13/2005 9:19:00 PM

0

Laurent Julliard wrote:
> Sorry if this question has already been asked 200 times... I'm trying

> to find a Ruvby package that would allow us to test a web based
> application directly through the Web interface. The idea here is that

> the Ruby testing application would basically behave like a web
browser
> : GET/POST requests, manipulate HTML forms received as objects so
> that it is easy to fill them out and send them back to the server
>
> Any pointer or suggestions would be really helpful
>
> Thanks!

It sounds like you're asking for something that's more or less like
Perl's LWP and/or WWW::Mechanize modules

I think there's a package or two on the RAA that might help -
http-access2 perhaps. If not, there's an idea for the Code Grant. :)
Regards,

Dan

Alexey Verkhovsky

1/13/2005 9:20:00 PM

0

Laurent Julliard wrote:

> Sorry if this question has already been asked 200 times... I'm trying
> to find a Ruvby package that would allow us to test a web based
> application directly through the Web interface. The idea here is that
> the Ruby testing application would basically behave like a web browser
> : GET/POST requests, manipulate HTML forms received as objects so
> that it is easy to fill them out and send them back to the server
>
> Any pointer or suggestions would be really helpful
>
> Thanks!


First of all, there is Net::HTTP library in the Ruby standard library
that lets you do the basic stuff - get, post, etc. Combining it with
test/unit (also a standard library in Ruby) you can come up with a
decent test suite, provided that your app doesn't rely on any browser
scripting (like Javascript or applets).

Then there is WATIR - this is something that "talks" to an Internet
Explorer via COM interface. Much more complex and fragile, but the only
way to go if you want to behaviors implemented by browser-side scripting.

Alex


stevetuckner

1/13/2005 9:25:00 PM

0

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.

If you would like I could send you what I have and we could collaborate
if nothing currently exists.

Steve Tuckner

> Sorry if this question has already been asked 200 times... I'm trying
> to find a Ruvby package that would allow us to test a web based
> application directly through the Web interface. The idea here is that
> the Ruby testing application would basically behave like a web browser
> : GET/POST requests, manipulate HTML forms received as objects so
> that it is easy to fill them out and send them back to the server
>
> Any pointer or suggestions would be really helpful
>
> Thanks!
>
>




Dick Davies

1/13/2005 9:40:00 PM

0

* stevetuckner <stevetuckner@usfamily.net> [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....


--
'Yeah, life is hilariously cruel.'
-- Bender
Rasputin :: Jack of All Trades - Master of Nuns


Alexey Verkhovsky

1/13/2005 9:51:00 PM

0

Dick Davies wrote:

>* stevetuckner <stevetuckner@usfamily.net> [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....
>
>
To clarify: the test framework available in Rails is very
Rails-specific, and it's just for unit-testing the controller layer of a
Rails app. I.e., a totally different beast.

Best regards,
Alex


Dick Davies

1/13/2005 9:56:00 PM

0

* Alexey Verkhovsky <alex@verk.info> [0151 21:51]:
> Dick Davies wrote:

> >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....
> >
> >
> To clarify: the test framework available in Rails is very
> Rails-specific, and it's just for unit-testing the controller layer of a
> Rails app. I.e., a totally different beast.

Does this not do what i think it does then?

http://wiki.rubyonrails.com/rails/show/HowtoFunc...

(quite possibly not, I've had very little sleep).

--
'Everybody's a jerk. You, me, this jerk.'
-- Bender
Rasputin :: Jack of All Trades - Master of Nuns


kohljonathan

1/13/2005 10:09:00 PM

0

There is Chris Morris' IEC and the new Watir library. Currently both
utilize the Internet Explorer "automation" interface (referred to as
COM, OLE, ActiveX, etc.) using WIN32OLE. IEC works more with form
submits, while Watir manipulates objects on a web page by sending
messages to the,. Both IEC and Watir can be downloaded from Rubyforge:
http://rubyforge.org/pro...

Watir just had a version 1.0 release last week, and plans are underway
to make it drive other web browsers than just Internet Explorer. To get
an idea of how Watir works, the first version of user guide is here:
http://wtr.rubyforge.org/watir_user_...
Disclaimer: I'm a contributor to Watir.

stevetuckner

1/13/2005 10:14:00 PM

0

Dick Davies wrote:

>* stevetuckner <stevetuckner@usfamily.net> [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 = "<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::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 =
"<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::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

kohljonathan

1/13/2005 10:16:00 PM

0

Typo: this sentence should read: "Watir manipulates objects on a web
page by sending messages to objects."

Jim Weirich

1/14/2005 1:16:00 AM

0

On Thursday 13 January 2005 05:11 pm, JonathanKohl wrote:
> Watir just had a version 1.0 release last week, and plans are underway
> to make it drive other web browsers than just Internet Explorer. To get
> an idea of how Watir works, the first version of user guide is here:
> http://wtr.rubyforge.org/watir_user_...
> Disclaimer: I'm a contributor to Watir.

I just stumbled across watir from a posting on Brian Maricks blog and am
considering using it at work where having IE available isn't an issue.

But I'm running Linux at home and a non-IE solution would be great. Have you
considered writing a ruby-based browser skeleton? Just enough browser to
request web pages and give information to your browser controller software.
Actually rendering wouldn't be necessary (I think). It would be quite useful.

--
-- Jim Weirich jim@weirichhouse.org http://onest...
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)