[Q] Web Testing in Ruby

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!

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

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. :slight_smile:
Regards,

Dan

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!

* 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

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 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>" +
            "</tr>" +
            "<tr template-arity=\"*\">" +
                "<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

* 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/HowtoFunctionalTest

(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

* stevetuckner <stevetuckner@usfamily.net> [0114 22:14]:

>
>>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).

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.

You've already got further than me then :slight_smile: I installed it a while back but
never got much further than that, it's in the todo pile somewhere....
but the example on the homepage seemed to indicate it checked the site layout
too ( assert_title( 'test-1', response ) and so on). If it needs the site
to be tagged to work then it's obviously not that useful....

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.

Look forward to a release!

···

--
Rasputin :: Jack of All Trades - Master of Nuns

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/projects/wtr/

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_guide.html
Disclaimer: I'm a contributor to Watir.

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

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.

···

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_guide.html
Disclaimer: I'm a contributor to Watir.

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"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)

Jim Weirich wrote:

···

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_guide.html
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.

For a non-MS based solution, there is an OSS project by some ThoughtWorks people called Selenium. It uses JavaScript to interact with the browser, instead of COM. There is even a proof of concept Ruby interface to it, although it's all in very early stages apparently.

Best regards,
Alexey Verkhovsky

Jim Weirich wrote:
<snipped>

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.
We are looking at supporting non-IE solutions. A Ruby-based browser
skeleton sounds like a great idea.

We have been looking at making Watir be able to talk to different
browser mechanisms. The idea is to have flexibility where for example
one could use the COM for IE, another testable interface for a
different browser, or a mechanism like Selenium.

If anyone is interested in developing a Ruby-based browser skeleton,
feel free to propose it on the wtr mailing list and contribute to the
project.

-Jonathan

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.

We have plans for just this situation.

Rather than use the approach you outline, we plan to use dependency injection to allow Watir-based tests to run either using the IE/COM driver, like they do currently (Windows only), or a new driver that will use Selenium to allow the tests to run in any browser on any platform.

Selenium is sever-side test automation software that currently supports in-browser testing on IE, Mozilla and Firefox on Windows, Mac and Linux. Seriously. The tests actually run in your browser of choice using a javascript automation engine that is implanted into the browser from the server. It's not fast, but it is very accurate and convincing.

You can see this for yourself, if you point a browser of your choice at http://selenium.thoughtworks.com/demo1/TestRunner.html

This is just a very rough mock up of what we are aiming for. The version of Selenium that is currently released only works with the static test files that you see in this demo, which i think is pretty boring. But we have prototypes checked in that allow Java and Ruby scripts to execute against this very same API.

Here's what works today:

require 'selenium'

puts "Go to http://localhost:7896/selenium-driver/SeleneseRunner.html&quot;
selenium = Selenium::WebrickCommandProcessor.new.proxy

selenium.open('/test_click_page1.html')
selenium.verifyText('link', 'Click here for next page')
selenium.clickAndWait('link')
selenium.verifyLocation('/test_click_page2.html')
selenium.clickAndWait('previousPage')
selenium.verifyText("link", "This is WRONG")
selenium.verifyElementPresent("link")
selenium.testComplete()

It is truly very raw, but ThoughtWorks is putting significant effort behind this tool. Expect rapid progress.

I am actually a contributor to both the Selenium and Watir projects. Watir is just starting to knock the socks off testers and is getting them to want to learn Ruby. Selenium will have drivers in Java, Ruby, .Net, Python and other languages. But i want to make Ruby be the thing for it too and integrate it with Watir, so that the same tests can be run in either configuration.

Some of you may recall that i showed you a precursor to Watir at RubyConf 2003. It's come a long way.

Wanna help? Let me know.

Bret

Report on Open Source Web Test Tools (featuring Watir)
http://www.io.com/~wazmo/blog/archives/2005_01.html#000227

Selenium
http://selenium.thoughtworks.com/index.html
http://confluence.public.thoughtworks.org/display/SEL/Home

Watir
http://wtr.rubyforge.org/

···

At 07:15 PM 1/13/2005, Jim Weirich wrote:

_____________________
  Bret Pettichord
  www.pettichord.com

Try webunit:

     http://www.xpenguin.biz/download/webunit/index-en.html

~ Patrick

···

On Thursday, January 13, 2005, at 08:15 PM, Jim Weirich wrote:

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_guide.html
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.

I've got a simple little framework that I use for testing my web-based
application. I originally hacked it together for testing some Java
servlets, but since then it's also been used on a ruby website and is
currently testing a PHP website.

It sends HTTP requests to a server and pulls back the result, so it can
be used for testing anything served by a web server. I suspect it's rather
similar to webunit (http://www.xpenguin.biz/download/webunit/index-en.html\).

A bunch of the code I use is not in this framework itself, but is in the
abstract testcase from which my concrete testcases inherit. I don't know
how much I should move up; some if it is pretty application-specific.

But here's a not untypical test, and its support routine:

     def test_logout
         send_request('/ID0123456789abcdef0123456789abcdef') # logs in user
   assert_image("logo image", "images/logo")
         assert_page_match("user name", %r|Welcome #{user_name}|)
         assert_link('Options', 'Options', 'user_setting.php')
         assert_link('Logout', 'Logout', 'logout.php')

         click("Logout")
         assert_link('Login', 'Login', 'login.php')
         assert_link('Register', 'Register', 'page/register')
     end

     def click(link_text)
         xpath = '/html//'
         # XXX Quick hack - what made xpath unhappy about the HTML thing?
         xpath = '//'
         new_request = response.get_request_from_link(link_text, xpath)
         if (new_request.nil?)
             message = "No A tag enclosing "#{link_text}" found. Text present:"
             response.get_text(xpath + 'a').each { |text|
                 message += "n " + text
             }
             fail(make_assert_failure_message(message))
         end
         @request = new_request
         send_request
     end

You can find it as the "test-httpweb" project on rubyforge; it requires
xpath and html-parser. Not really documented or anything, but feel free
to play around with it a bit and send me e-mail if you want help.

cjs

···

On Fri, 14 Jan 2005, Jim Weirich wrote:

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.

--
Curt Sampson <cjs@cynic.net> +81 90 7737 2974 http://www.NetBSD.org
      Make up enjoying your city life...produced by BIC CAMERA

Couldn't a client-side HTTP proxy be used to remove the need for something to be installed on the server side, and thus make it possible to use Selenium for any web application, not just those for which there is server-side access? Just a thought, since Selenium sounds very intriguing, but the server-side requirement seems a bit onerous.

Nathaniel
Terralien, Inc.

<:((><

···

On Jan 14, 2005, at 00:04, Bret Pettichord wrote:

Selenium is sever-side test automation software that currently supports in-browser testing on IE, Mozilla and Firefox on Windows, Mac and Linux. Seriously. The tests actually run in your browser of choice using a javascript automation engine that is implanted into the browser from the server. It's not fast, but it is very accurate and convincing.

We've built at least one prototype for this and have been discussing other methods of doing this.

One risk is that as soon as you configure your browser to use this proxy, you know open up your system to cross-site scripting attacks.

Bret

···

At 02:59 PM 1/14/2005, Nathaniel Talbott wrote:

Couldn't a client-side HTTP proxy be used to remove the need for something to be installed on the server side, and thus make it possible to use Selenium for any web application, not just those for which there is server-side access? Just a thought, since Selenium sounds very intriguing, but the server-side requirement seems a bit onerous.

_____________________
  Bret Pettichord
  www.pettichord.com