开发者

How can I get rid of the following warning: Problem while setting context on example startundefined local variable or method `selenium_driver'

Still making my first steps in Ruby (while dealing with some written code). I am getting the following warning each time I run spec (listed as is):

Problem while setting context on example startundefined local variable or method `selenium_driver' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f2d2cd840e0>

(Edit: Split into two lines, it says)

Problem while setting context on example start
undefined local variable or method `selenium_driver' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f2d2cd840e0>

While grep-ing through Ruby code - could find the following:

/home/user/.rvm/gem开发者_运维问答s/ruby-1.8.7-p334@frontend/gems/selenium-client-1.2.18/lib/selenium/rspec/spec_helper.rb:      STDERR.puts "Problem while setting context on example start" + e

So here is the excerpt from the source code of spec_helper.rb:

  config.append_before(:each) do
    begin
      if selenium_driver && selenium_driver.session_started?
        selenium_driver.set_context "Starting example '#{self.description}'"
      end
    rescue Exception => e
      STDERR.puts "Problem while setting context on example start" + e
    end
  end

Kindly advise how can I solve the (potential) problem.

Update: This grep might be helpful as well:

user@vm-ubuntu:~/dev/branch/tests$
grep selenium_driver *
my_module.rb:   @selenium_driver = driver
my_module.rb:   ['TERM', 'INT'].each {|s| Signal.trap(s) { @selenium_driver.stop && Process.exit(1) } }
my_module.rb:   return @selenium_driver

Update N2:

My Gemfile:

source "http://rubygems.org"            # Default source

gem "hpricot", "~>0.8.4"
gem "json", "~>1.5.1"
gem "rspec", "~>1.3.2"
gem "selenium-client", "~>1.2.18"

My selenium_helper.rb file:

require 'selenium/client'
require "selenium/rspec/spec_helper"
...


The problem is that selenium-client gem expects that you name your driver object 'selenium_driver' and make it visible from the spec.

For example if you initialize selenium like this:

before(:all) do
  @driver = create_driver($hub_url, $hub_port, $browser) 
  @driver.start_new_browser_session
end

You need to change it to look like this:

attr_reader :selenium_driver

before(:all) do
  @selenium_driver = create_driver($hub_url, $hub_port, $browser) 
  @selenium_driver.start_new_browser_session
end

Basically it's same code just different variable name. The selenium-client uses that convention to apply context information to the tests.


It's saying it can't find the variable selenium_driver.

Problem while setting context on example startundefined local variable or method `selenium_driver' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f2d2cd840e0>

is made up of the string "Problem while setting context on example start" plus the exception error message (what's produced by e) of

"undefined local variable or method `selenium_driver' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f2d2cd840e0>"`.


Add

gem "selenium-client"

to your Gemfile (don't forget to run $ bundle install)

And add following to spec/spec_helper.rb

require "selenium/client"
require "selenium/rspec/spec_helper"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜