[Rspec-devel] Selenium Integration

aslak hellesoy aslak.hellesoy at gmail.com
Tue Aug 22 19:12:30 EDT 2006

On 8/23/06, Wayne Larsen <wayne at larsen.st> wrote:
> Hi All,
> In my understanding, using selenium to test your app (I'm speaking
> about rails specifically here) can be done several ways:
> 1. With the selenium_on_rails plugin.  This expands the rails test
> directory to include a directory for selenium tests.  This plugin also
> includes RSelenese, which is a ruby dsl that evals to the selenium
> table testing language.  This allows you to write something like:
> open '/admin/users'
> click "link=New User"
> wait_for_text_present "Login Fields"
> type "users_login", "Marie"
> The only structure to these tests is based on directories and files.
> Directories define a suite, and each test gets its own file.
> 2. Using selenium-rc and the given framework.  Aslak posted an example
> of this using rspec that looked something like:
> context "A running iteration" do
>   setup do
>     @sel = Selenium::SeleneseInterpreter.new("localhost", 4444,
> "*firefox", "http://localhost:3000", 5000)
>     @sel.start
>   end
>   specify "should allow finishing and tag all stages and stories" do
>     @sel.open_and_wait "http://localhost:3000/iterations/1"
>     # TODO: verify that the iteration is still 'running' (visual clue)
>     @sel.click_and_wait "link=Iteration Status"
>     @sel.click_and_wait "link=Finish this iteration"
>     # TODO: verify that the iteration is 'finished' (visual clue)
>   end
>   teardown do
>     @sel.stop
>   end
> end
> This allows you to make use of rspec's framework for running your
> Specs/Behaviours/Examples.  The downsides to this is that the language
> for writing tests is not at all like rspec's elegant language, and for
> me, I've found that the runtime overhead of selenium-rc is just not
> practical for quick iterations.
> 3. Other options, such as Rubinium (I've only briefly looked at this)
> that provides a method of compiling ruby code to selenium test's,
> using a dsl pretty much equal to selenium's.
> A better way?
> OK, given that, and the fact that I'm pretty new to both rspec and
> selenium, I would like to propose a different integration approach.
> Building off the selenium_on_rails plugin, one should be able to
> define a new type of format (say .specenese for argument) that would
> look like a normal rspec specification.  The spec would then translate
> to the selenese format that can then be executed.  So, essentially,
> combining the rselenese format with rspec, to produce something
> handwavingly like:
> context "Test create user" do
>   specify "should create a user when given valid user information" do
>     open '/admin/users' and wait
>     page.should_include "All Users"
>     click 'link=New User'

I'd prefer:
click :link => "New User"

>     fill {:users=>{:login=>'rob', :firstname=>'Rob', :lastname=>'Gordon'}}

What would this translate to in say, Selenium FIT-style HTML?

>   end
> end
> By taking advantage of rails conventions and rspec's capabilities, a
> higher level functional api could be built.  I've started looking into
> this, and believe it shouldn't be extremely difficult to do, but maybe
> I'm missing something.
> Also, with the api/dsl in place, it might be possible to switch
> between browser driven and remote control modes based on some
> configuration.
> So questions:
> Does this make sense?

As the writer of the initial rselenese and also an early selenium
contributor I should be able to tell you. But the fact is I don't
remember :-)

But it sure would be sweet with a nicer ruby API that integrates well
with RSpec.
It's fairly easy to add new helper methods such as open, click etc. to
RSpec in a spec_helper. Check out how it's done in the RSpec on Rails

> Is anyone pursuing anything like this?

Not that I know of

> Is there a better way that I haven't seen?

It's hard to say before you try it ;-)

> I might keep poking away at this if it has any merit, but in the
> meantime I need to get back to building the app in the first place, in
> which case the best option does seem to be the
> rselenese/selenium_on_rails way, which is not really tied to
> Test::Unit or rspec.

Let us know how it goes. My main gripe with all of the in-browser
tools out there (selenium, watir, sahi) is the lack of AJAX support.
There is a workaround for Selenium (google it). If that could be made
more elegant with a ruby layer it would be sweet.

> Regards,
> Wayne
> btw, pardon me for using the t word in the above.  I am new to both
> rspec and bdd -- the reason I started investigating this in the first
> place, is that it seems that it should be possible for a non technical
> user to write the functional specs in the first place, and the easier
> that can be done, the better.

You're forgiven ;-)


> _______________________________________________
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel

More information about the Rspec-devel mailing list