[rspec-users] Rspec Stories / Selenium Nightmare
David Chelimsky
dchelimsky at gmail.com
Thu May 8 11:15:28 EDT 2008
Just an FYI - spec-ui, an rspec extension that supports integration
with selenium and watir, has been under some discussion lately and
should see some new life soon.
On May 8, 2008, at 10:10 AM, Zach Dennis wrote:
> I've had really iffy luck with Selenium plugins in the past
> (selenium-on-rails, seleniumfu_rc, selenium_rc, etc.) so I've
> started to write a RailsSeleniumStory. I also had to remove the
> ActiveRecordSafetyListener in my efforts.
>
> The RailsSeleniumStory is a part of the mhs_testing plugin [0] and
> it provides higher level helpers. For example I love how form-test-
> helper is used to select and submit forms:
>
> # option 1
> form = select_form 'expense_form'
> form.expense.amount = 12.99
> form.submit
>
> # option 2
> submit_form 'expense_form' do |form|
> form.expense.amount = 12.99
> form.expense.category_id = 2
> form.expense.comments = "map for trip"
> end
>
> You can use this same syntax within RailsSeleniumStories. Right now
> you can also use "have_tag" and "with_tag" matchers with Selenium.
> It supports basic matching (I wouldn't get to crazy with nesting or
> lots of assert-select/have-tag options), but it will be supporting
> more options shortly.
>
> So your login example could just look like:
>
> Given('log in as a admin user')
> open "/admin/login"
> submit_form "login_form" do |form|
> form.login = 'developer'
> form.password = 'test'
> end
> end
>
> Which IMO I really like because if you need variations of that you
> can pull out a helper method like:
>
> def submit_login_form(user, password='test')
> submit_form "login_form" do |form|
> form.login = user.login
> form.password = passsword
> end
> end
>
> And you could push your open into a helper as well:
> def go_to_login_page
> open "/admin/login"
> end
>
> And now your Given could look like:
> Given('log in as a admin user')
> go_to_login_page
> submit_login_form @user, 'test'
> end
>
> Now granted submit_form and select_form both take a form's id, so
> each of your forms need to have one.
>
> If you are interested and have the time please check it out. Granted
> it's in its infancy and there's not a whole lot of docs right now
> (there is a README.Selenium for instructions on how-to setup in your
> project), but you can find me on GTalk or in irc.freenode.net
> (zdennis) and of course right here on the rspec ML. I am have 33
> scenarios using the RailsSeleniumStory,
>
> ttyl,
>
> Zach
>
> 0 - http://github.com/mvanholstyn/mhs_testing/tree/master
>
>
>
> On Thu, May 8, 2008 at 8:22 AM, Joseph Wilk <lists at ruby-forum.com>
> wrote:
> I have been using Rspec stories with Webrat feeling very productive
> and
> happy.
>
> 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
> (http://www.nabble.com/stories-with-selenium-and-the-db-td16190686.html
> )
> 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
> $selenium_driver.stop
>
> #Do we need to re-add some listeners
> if !@listener_reloaded
>
> Spec
> ::Story
> ::Runner
> .scenario_runner.add_listener(ActiveRecordSafetyListener.instance)
> @listener_reloaded=true
> end
> end
> 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
> $selenium_driver.do_something()
>
>
> This nice Given:
>
> Given('log in as a admin user')
> post '/admin/sessions/create', :login => @user.login, :password
> =>
> @user.password
> end
>
> 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.
>
> --
> Joseph Wilk
> http://www.joesniff.co.uk
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
>
> --
> Zach Dennis
> http://www.continuousthinking.com
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080508/df4ef82c/attachment.html>
More information about the rspec-users
mailing list