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.
def story_ended(title, narrative)
when ‘Edit a page’
#We have finished the selenium story $selenium_driver.stop #Do we need to re-add some listeners if [email protected]_reloaded Spec::Story::Runner.scenario_runner.add_listener(ActiveRecordSafetyListener.instance) @listener_reloaded=true end
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' end
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.