[rspec-users] UI testing framework? (w/o selenium)

aslak hellesoy aslak.hellesoy at gmail.com
Thu May 10 06:39:57 EDT 2007

On 5/9/07, Tim Tischler <tischler at purplecoffeecup.com> wrote:
> Hey all,
> I am currently working on coming up w/ an easy to use, developer-centric web
> testing framework to test a J2EE app with. (I have 3 rails apps in
> production, love rspec, and am currently at a java shop).

One of the biggest projects in my company (BEKK Consulting) is using
RSpec to drive Watir, and we have about 400 examples (it blocks).

At the core of this we're using Spec::Ui, which is an RSpec extension
specially designed for Watir and Selenium-RC. Spec::Ui extends the
standard RSpec HTML report with:

* screenshot at the time of failure
* HTML source code of the browser at the time of failure

These detailed reports is something the teams have become completely
dependent upon. It really kicks ass.

Spec::Ui also has custom RSpec matchers Watir (I haven't made any for
Selenium-RC yet, but we're accepting patches). These matchers allow
you to do things like this:

@ie.should have_link(:url, "http://rspec.rubyforge.org")
@ie.should_not have_button(:name, "delete")

etc. All of Watir's "element lookup" methods have a corresponding have_* method.

Spec::Ui has been in RSpec's trunk for several months (trunk/spec_ui),
but I have deliberately kept mostly quiet about it because it has been
somewhat immature. However, it has stabilised a lot lately, and I
encourage you to take a look at it. There are examples both for Watir
and Selenium-RC. See separate email releasing RSpec 0.9.4.

> I've looked at selenium, and it just doesn't seem like it is ready for prime
> time, and the target audience is developers.

Do you think Selenium is more developer-targeted than Watir? Have you
seen the FIT-style markup for Selenium?

> So, having said that, does
> the rspec community want a "functional" test framework?  Are you happy w/
> selenium, and is it working?

I hope Spec::Ui is what you're looking for.

Both Watir and Selenium-RC are working great with RSpec/Spec::Ui.
There are some minor caveats with Selenium-RC on OS X though (see
README.txt in the selenium example).

> Unless someone convinces me of selenium, I'm planning on taking the basics
> and concepts of rspec, and focus it more towards testing web applications,
> and am happy to contribute.  My company is totally cool with contributing to
> open source projects if it makes sense.
> Any thoughts or suggestions?  Here is a sketch of what I think I'd like:
> server " http://localhost:8080" do
>    test '/' do
>     page.status.should_be "200"
>      page.should_have :image, "logo.gif"
>      page.should_have :string, "Copyright 2006-Present SomeCo, Inc. All
> rights reserved."
>      page.should_have :div, :id => 'copyright'
>      page.should_include :css, 'default.css'
>     page.should_have.no_broken_links
>     page.should_have.at_least.3 :div, :class => "bbxBody"
>      page.should_have.at_most.6 :div, :class => "someClassName"
>     # page.[name_of_form]_form.
>      page.search_form.submit :name => "California" do
>       result.status.should_be :success
>        result.should_have :image, "logo.gif"
>       result.url.should_contain "some_page.html"
>     end
>     page.should_have :div, :class => 'something else'
>      page.should_have :div, :id => 'foo', :class => 'bar'
>      page.should_have '/div[1]/div[2]/td'
>   end
>   test '/some/url.html?id=35' do
>      page.should_redirect :to => '/foobar.html'
>   end
>  end

This is quite similar to what Spec::Ui us doing today. The syntax is a
little different for Watir and Selenium-RC, but I hope we can unify it
with custom RSpec matchers with similar APIs. This should make it
easier to switch transparently(ish) between Selenium-RC and Watir.

I second Bob's recommendation to not use this API extensively in your
own specs though, but rather implement your own domain-specific API
around it and use that instead. We have also done this at the project
I mentioned above, and it makes for much more readable and
maintainable specs.


> --
> Tim Tischler
> ttischler at homeaway.com
> tischler at purplecoffeecup.com
> 512-565-4750
> AIM:tjtischler512
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list