[rspec-users] Selenium/Watir usage along side Webrat in story testing

Joseph Wilk lists at ruby-forum.com
Mon Jun 9 06:01:15 EDT 2008


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 Wilk
http://www.joesniff.co.uk
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list