UI Testing

Hello, I’m just wondering if there are some
suggestions/docs/tutorials/frameworks on testing the UI in Rails. These
days, with all the AJAX and DOM manipulation and whatnot, it seems
increasingly important to have some tests in place. TDD would be the
ideal, but what are others doing?

Thanks,
Cliffe

Hodgkinson, Cliffe wrote:

Hello, I’m just wondering if there are some
suggestions/docs/tutorials/frameworks on testing the UI in Rails. These
days, with all the AJAX and DOM manipulation and whatnot, it seems
increasingly important to have some tests in place. TDD would be the
ideal, but what are others doing?

The closest native solution are Rails’ functional tests (also called
acceptance tests). With them you can test the HTTP response of a
controller action, what instance, session, cookie and flash variables
were set, what view was rendered and it even lets you do “tag-based”
assertions.

While I’ve not played with the tag assertions, from what I understand
they check the DOM of the rendered view to make sure that a particular
tag exists.

The Rails manual book on testing:
http://manuals.rubyonrails.com/read/book/5

Controller tests start on chapter 9.

Thibaut Barrère wrote:

you may want to have a look at Watir http://wtr.rubyforge.org/

That looks interesting. I wonder if it’s worth the effort to learn
another testing framework, especially if it only works in IE. I also
wonder what benefits it yields over functional tests in Rails.

Check out the testing tool we’ve developed that covers Watir, called
Systir:

http://atomicobject.com/systir.page

Very simple to set up and use, written in Ruby, though only useable in
this
case in Windows and IE, as Watir can only control IE right now.

Jason

Hello, I’m just wondering if there are some
suggestions/docs/tutorials/frameworks on testing the UI in Rails. These
days, with all the AJAX and DOM manipulation and whatnot, it seems
increasingly important to have some tests in place. TDD would be the
ideal, but what are others doing?

you may want to have a look at Watir http://wtr.rubyforge.org/

cheers

Thibaut

Daniel, the problem here is testing RJS / Ajax code, which Rails
Integration
tests just cannot do. If you’ve never tried, you’ll very quickly find
that
all you get back is the javascript, and no more DOM to test. Thus most
of
the time your stuck with posting certain actions, refreshing the page,
and
asserting that the new stuff is there.

To test actual Ajax (like the opening / closing of an Add form), you
need
some testing library that runs a browser. Systir combined with Watir
very
quickly and efficiently allows this ability of testing (I’ve never
touched
Selenium, but I know there’s a good bit of configuration to it, that
isn’t
needed with Systir). So you can actually click on a link and then check
the
DOM, as Watir only cares about what IE thinks the DOM now is, not what
the
last call was.

Watir also has the side effect of ‘physically’ driving the browser, so
you
can choose to watch the test run, checking for yourself whether effects
are
happening or not, and if certain actions are just taking too long.

Jason

I’ve written a plugin to allow tighter integration of Selenium testing
with
Rails. It uses Selenium-RC to directly control the browser and check the
results. I’d class it as alpha level at the moment. It should work
alright,
but it needs some more work. If anyone wants to try it out and let me
know
the result that would be great.

http://svn.viney.net.nz/things/rails/plugins/selenium_jelly

There should be enough documentation to get started.

-Jonathan.

@Jason:

Selenium actually doesn’t require any setup if you just use the
Selenium-IDE
plugin for Firefox. You can build your tests by recording movements on
the
page and it writes the scripts for you. When you play them back, it
takes
control of the browser.

It can get more sophisticated if you use the Selenium-RC stuff… but
the
Selenium-IDE will let you save your tests (which are actually ruby
files!)

+1 to WATIR. What got me into Ruby. It owns.
Unit testing of GUIs, DOM based and the test scripts are very
robust if written properly (using ids etc.)

Extremely easy to get up to speed with, and straightforward
to teach to non-coders.

If Firefox is your poison, theres FireWatir but its not as mature.

(note to self to check out systir)

I haven’t tried Selenium, but my hearsay tells me that it is not
a functional overlap of Watir, so between both tools you have
very powerful testing capability.

Not strictly about UI testing, but something in that direction: my
RailsConf Europe presentation will be about (unit) testing JavaScript
(with unittest.js of script.aculo.us, which is also used for the
Prototype unit tests). I’ll put up the slides of the presentation
after the talk (so, later this week, maybe Friday or so).

In my experience, for interface and interaction testing itself you’ll
have to do manual tests. For example, all browsers known to man have
rendering errors in some situations that you can’t really capture
with automated tools-- and while you can tricky with stuff like
screenshot comparisions, this will quickly become extremely tiresome
in this world of quickly changing apps.

The route I’d recommend is: have sane amount of coverage for unit and
functional tests for the Rails app, unit tests for your JavaScript
libs, and try to have frequent releases. It’s imperative that you
check all vital functionality of your app in all supported browsers
manually.

Best,
Thomas

Am 07.09.2006 um 20:18 schrieb Hodgkinson, Cliffe:

On 12/09/06, Thomas F. [email protected] wrote:

Hello, I’m just wondering if there are some
suggestions/docs/tutorials/frameworks on testing the UI in Rails.
These
days, with all the AJAX and DOM manipulation and whatnot, it seems
increasingly important to have some tests in place. TDD would be the
ideal, but what are others doing?

You should take a look at Adam Connors’ and Joe Walnes’ excellent talk
“Does
my button look big in this? Building Testable AJAX Applications” which
they
presented at the Google London Test Automation Conference last week. It
should be coming out on Google Video any day now. I’ll post it to my
blog as
soon as it comes out.

James.

Jason R. wrote:

Daniel, the problem here is testing RJS / Ajax code, which Rails
Integration tests just cannot do…

Ah, I see. Okies. Thanks for the lesson in testing. =)