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:
-
Tests and rails process run as one test process (Webrat)
-
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 W.
http://www.joesniff.co.uk