I'm using story runner of RSpec now. What I'm trying to do is
initializing the @selenium before any steps of one story is executing,
and stop @selenium after any story is finished. just as @BeforeClass
and @AfterClass in jUnit
Any suggestions on this?
Thanks!!!
Bei
here is my code for
STEPS:
steps_for(:search) do
Given("user could access search page") do
@google_page = GooglePage.new(@selenium)
@google_page.open;
end
Given("user enter search test: $search_text") do |$search_text|
@google_page.search_text=$search_text
end
When("do search") do
@search_result_page = @google_page.search
end
Then("show search result") do
@search_result_page.should_not == nil
end
end
STORY:
Story: #000
As A command human
I want to get information quickly
So that I could save me time on doing real things
Scenario: could search
Given user could access search page
And user enter search test: asdfasdfasdfas
When do search
Then show search result
GLUE:
with_steps_for :search do
run ‘stories/000.story’
end
I'm using story runner of RSpec now. What I'm trying to do is
initializing the @selenium before any steps of one story is executing,
and stop @selenium after any story is finished. just as @BeforeClass
and @AfterClass in jUnit
Any suggestions on this?
There is no way built in to handle this yet. Is anybody doing this yet?
If not, you’ll have to experiment. If you’re interested, I think the
way to handle it is to register a listener like this:
Spec::Story::Runner.register_listener(listener)
The listener object should receive messages like run_started,
story_started, scenario_started and story_ended, run_ended and
scenario_failed or scenario_pending.
Be sure to implement method_missing to ignore everything else.
I'm using story runner of RSpec now. What I'm trying to do is
initializing the @selenium before any steps of one story is executing,
and stop @selenium after any story is finished. just as @BeforeClass
and @AfterClass in jUnit
Any suggestions on this?
Thanks!!!
Hi,
my helpers/selenium_helper.rb file look like that:
Alias some more ruby-like methods on SeleniumDriver, to make it play
better with rspec matchers.
module Selenium
class SeleniumDriver
alias_method :original_method_missing, :method_missing
def method_missing method_name, args
if method_name.to_s =~ /^has_.?$/
real_method = method_name.to_s.sub /has_(.*)?$/, ‘is_\1’
if respond_to? real_method
return send(real_method, args)
end
elsif respond_to?(real_method = “get_” + method_name.to_s)
return send(real_method)
end
return original_method_missing(method_name, args)
end
end
end
module StoryHelper
def selenium
$selenium_driver
end
Spec::Story::World.send :include, self
end
class SeleniumListener
include Singleton
def scenario_started(*args)
$selenium_driver = Selenium::SeleniumDriver.new(‘localhost’, 4444,
‘*firefox’,
‘http://localhost:3000/’,
15000)
$selenium_driver.start
end
def scenario_succeeded(*args)
$selenium_driver.stop
$selenium_driver = nil
end
alias :scenario_pending :scenario_succeeded
alias :scenario_failed :scenario_succeeded
end
unless $selenium_listener_added
Spec::Story::Runner.scenario_runner.add_listener(SeleniumListener.instance)
$selenium_listener_added = true
end