[rspec-users] Rspec Stories / Selenium Nightmare

Joseph Wilk lists at ruby-forum.com
Thu May 8 08:22:37 EDT 2008

I have been using Rspec stories with Webrat feeling very productive and

Then I needed to do something with Selenium (Webrat could have done what
I needed but it does not yet have the functionality).

Selenium-core as part of a rails plugin looked nice but did not seem to
fit with rspec stories. So I went the Selenium-rc route.

Since Selenium uses a separate instance of rails
I had to turn off the ActiveRecordSafetyListener used in rspec to make
sure the db writes committed.

Which in turn left me having to manually cleanup my selenium stories :(

So that required writing a new, rather gritty scenario listener which
dealt with the cleaning operation. It has to do lots of horrible things
like remove all listeners for a selenium story and then re-add them all
for the others stories.

*Code Extract*

def story_ended(title, narrative)
  case title
  when 'Edit a page'

    #We have finished the selenium story

    #Do we need to re-add some listeners
    if !@listener_reloaded

I had to duplicate a lot of the story steps since now any previous
post/gets did not work since they post to the test instance and not the
selenium rails instance.

I also needed to invoke against the selenium driver so even when the
steps would work I had to duplicate them with

This nice Given:

    Given('log in as a admin user')
      post '/admin/sessions/create', :login => @user.login, :password =>

Being duplicated with this

    Given('log in as a admin user')
      $selenium_driver.open '/admin/login'
      $selenium_driver.type 'login', 'developer'
      $selenium_driver.type 'password', 'test'
      $selenium_driver.click 'commit'

After some very painful testing and a lot of time I got my Selenium-rc
and Webrat stories working. This experience really opened my eyes to the
big void introduced by Selenium-rc running outside of the test instance.

This has made me wonder whether I should have rspec stories stepping
outside of the test rails instance to drive Selenium tests.

Has anyone managed to make this process easier?

I'm hoping I'm doing something silly which is making it all harder!

Is it feasible to bring selenium into the test rails instances?

Is it just always going to be painful?

I was skipping along having a lot of fun with stories and Webrat, now
I'm face down in a puddle of mud, dreading that Selenium moment.

Joseph Wilk
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list