Selenium/Watir usage along side Webrat in story testing

This is related to Selenium/Watir usage along side webrat in story
testing.

MHS_Testing and Rspec-ui provide some great help for testing through
frameworks like Selenium/Watir.

But there is something missing, Webrat has changed the landscape
somewhat with Acceptance Tests/Story Driven development.

Now I have a choice:

  1. Tests and rails process run as one test process (Webrat)

  2. Use framework accesses a separate test process than the one driving
    the
    tests. (Selenium)

Option 1 is super fast but cannot run complex JavaScript/advanced UI
actions (mouse over, etc.)

So I use a mixture of both based on the test I have to write.

So there are two syntaxes I have to use. When I have common Givens
like login I have to duplicate the Given, one for Selenium one for
Webrat.

So I was thinking of ways to avoid this duplication:

Create two classes (this is already what MHS_testing has done for
Selenium)


class RailsSeleniumStory < RailsStory
class RailsWebratStory < RailsStory

Create a common interface for all shared functionailty.

(I suspect Webrat represents the smallest set of functionality -
Selenium can do everything Webrat can do but not the other way around).
The different UI testing frameworks implement such interface giving
Selenium/Webrat/Other UI adapters.

You choose which adapter to use by the story class.

Example

#Webrat syntax
steps_for(:login) do
Given(‘I’m logged in’) do
visits ‘/login’
fills_in ‘username’ ‘test’
fills_in ‘password’ ‘password’
clicks ‘login’
end
end

#Make webrat syntax work with selenium
with_steps_for(:login) do
run ‘/example/story’, {:type => RailsSeleniumStory}
end

#Use Webrat
with_steps_for(:login) do
run ‘/example/story’, {:type => RailsWebratStory} #Could just be
RailsStory
end

class RailsSeleniumStory < RailsStory

#Map webrats visit to seleniums open
def visits(url)
browser.open(url)
browser.wait_for_page_to_load “30000”
end

end


I’m not sure what direction MHS_testing or Rspec-ui are going, whether
they will merge? I’m looking at this problem now and want to start
contributing to whatever project is going to be the best fit. So I’m
interested to hear:

*Feedback/discussion about this direction
*Any better ideas of solving the problem
*Any other frameworks out there were people have started to look at this
problem.


Joseph W.
http://www.joesniff.co.uk

Joseph W. wrote:

(I suspect Webrat represents the smallest set of functionality -
contributing to whatever project is going to be the best fit. So I’m

Hey Joseph,
Have you looked at webrat in github lately?

Bryan is abstracting webrat so that different adapters can be plugged
into it… Meaning, the same wrappers/syntax can be used to drive rails,
merb, mechanize, etc… I think a selenium or watir adapter for webrat
would be awesome. I’m not too experienced with selenium but it doesn’t
strike me as being too hard to do. You make a good point in that webrat
is a small subset of what the other JS aware frameworks can do but I
think what webrat currently has would handle a lot of the use cases.
One could then perhaps create an extension of webrat’s language to form
a uniform way of expressing JS/AJAX behaviour.

The mechanize adapter idea is neat too, because you could then use it to
test any website no matter what the implementation is. I know that part
of Bryan’s motivation behind the mechanize spike is to eventually use
the stories to do performance testing as well.

This is a problem I’m also interested in but I haven’t yet needed to use
selenium enough to make me want to do anything about it. :slight_smile: I think the
selenuim adapter for webrat approach would be a great way to approach
this problem though. What do you think?

-Ben

If Bryan wraps the webrat API around the Watir API, it can also be
used against the new kid on the block: http://celerity.rubyforge.org,
which implements the Watir API backed by JRuby and HTMLUnit - orders
of magnitudes faster than Watir - and agnostic of webapp architecture
(http based). This means webrat could be used against e.g. Java webapps.

I’m planning on adding native webrat support to Cucumber (on Github)
and you can see it in action in Ba (on Gitorious).

Aslak.

Sent from my iPhone

Joseph W. wrote:

Sounds like a good idea. I guessing you mean some friendly wrapper to
The whole JS/AJAX behavior missing from Webrat has been making me look

Very cool. Keep me posted on your progress. I would love to jump in and
help but I don’t have the bandwidth to do so quite yet… soon though.
The post you linked to at the bottom talking about HTTPUnit is
interesting. The project that Aslak mentioned is basically a JRuby
wrapper for HTTPUnit using the watir API… So, as Aslak suggested if we
had a webrat adapter for watir then we would not only get waitir support
but HTTPUnit capabilities! That would be three wrappers!

I’m a little confused by the JS capabilities of HTTPUnit… on the
bottom of that post the author made a comment:
" anything (not just Javascript) which manipulates the DOM after the
page has been served will require in-browser testing – either manual or
automated."

Does anyone have experience with HTTPUnit? My understanding of HTTPUnit
is that it will process the JS after the page loaded (and there FAQ
seems to suggest this as well.) Most of my sites use unobtrusive JS,
meaning it all works without JS but then JS is used to add additional
user interfaced niceties (AJAX, effects, etc…) So will HTTPUnit process
the JS and update the DOM accordingly? This is probably the wrong
mailing list to answer this, but if anyone has had experience with
HTTPUnit please share.

-Ben

My mind was stuck in Rspec but looking at this as an adapter for Webrat
is a great idea.

I’ve had a play with Webrat and a test Selenium adapter ala the
Mechanize one. Things start to get a little tricky around having to have
the domain defined first in the Selenium. Meaning in Selenium its hard
to do:

  1. visits(‘http://www.google.co.uk’)
  2. visits(‘http://www.monkeys.co.uk’)

Status codes are also not great fun
(http://clearspace.openqa.org/message/8115#8115). I’ll continue playing
with this and see how easy it will be to squeeze Selenium into the
Webrat box.

One could then perhaps create an extension of webrat’s language to form
a uniform way of expressing JS/AJAX behavior.

Sounds like a good idea. I guessing you mean some friendly wrapper to
something like: ‘xml_http_request’ in
ActionController::Integration::Session
http://api.rubyonrails.com/classes/ActionController/Integration/Session.html#M000251

Aswell as just Ajax/JS stuff as an ability to perform more advanced
interrogations (but always optional to keep the wonderful simplicity of
Webrat’s usage) would be a nice addition to Webrat. Something similar to
Selenium’s xpath like expressions. I’m not sure if Watir has something
similar.

The whole JS/AJAX behavior missing from Webrat has been making me look
at the introduction of Server-side JS. Things like:
Jaxer(http://www.aptana.com/jaxer) &
Rhino(http://www.mozilla.org/rhino/). Whether its possible to push
forward what JS Webrat can handle (be it that its never going to be a
real browser).
The real browser testing makes a lot of sense when examining different
browsers JS/CSS processing but there are a lot of use-cases where simple
DOM manipulation is good enough.
Selenium rocks – and you don’t need it | magpiebrain


Joseph W.
http://www.joesniff.co.uk

Ben M. wrote:

Joseph W. wrote:

(I suspect Webrat represents the smallest set of functionality -
contributing to whatever project is going to be the best fit. So I’m

Hey Joseph,
Have you looked at webrat in github lately?
GitHub - brynary/webrat: Webrat - Ruby Acceptance Testing for Web applications
Bryan is abstracting webrat so that different adapters can be plugged
into it… Meaning, the same wrappers/syntax can be used to drive rails,
merb, mechanize, etc… I think a selenium or watir adapter for webrat
would be awesome. I’m not too experienced with selenium but it doesn’t
strike me as being too hard to do. You make a good point in that webrat
is a small subset of what the other JS aware frameworks can do but I
think what webrat currently has would handle a lot of the use cases.
One could then perhaps create an extension of webrat’s language to form
a uniform way of expressing JS/AJAX behaviour.

The mechanize adapter idea is neat too, because you could then use it to
test any website no matter what the implementation is. I know that part
of Bryan’s motivation behind the mechanize spike is to eventually use
the stories to do performance testing as well.

This is a problem I’m also interested in but I haven’t yet needed to use
selenium enough to make me want to do anything about it. :slight_smile: I think the
selenuim adapter for webrat approach would be a great way to approach
this problem though. What do you think?

-Ben

Hi Ben,

I’m a little confused by the JS capabilities of HTTPUnit…

You’re confusing HTTPUnit with HtmlUnit. We chose HtmlUnit for Celerity
partly because they seem to care a lot about JavaScript support.

Here’s a comparison of the two (by a HtmlUnit committer, but still :wink:

http://daniel.gredler.net/2007/10/04/htmlunit-vs-httpunit/

A Watir adapter for WebRat sounds like a great idea.

Jari

[email protected] wrote:

http://rubyforge.org/mailman/listinfo/rspec-users

Ahh… I see. Thanks for the link. Those names are easily confused…

-Ben