仍在Ruby中完成我的第一步(同时处理一些编写的代码)。每次运行spec
(按原样列出)时,我都会收到以下警告:
Problem while setting context on example startundefined local variable or method `selenium_driver' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f2d2cd840e0>
(编辑:分成两行,它说)
Problem while setting context on example start
undefined local variable or method `selenium_driver' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f2d2cd840e0>
虽然grep
- 通过Ruby代码 - 可以找到以下内容:
/home/user/.rvm/gems/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
以下是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
请告知我如何解决(潜在)问题。
更新:此grep
也可能有用:
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
更新N2:
我的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"
我的selenium_helper.rb
文件:
require 'selenium/client'
require "selenium/rspec/spec_helper"
...
答案 0 :(得分:1)
问题是selenium-client
gem希望您为驱动程序对象命名'selenium_driver'
并从规范中显示它。
例如,如果你像这样初始化selenium:
before(:all) do
@driver = create_driver($hub_url, $hub_port, $browser)
@driver.start_new_browser_session
end
您需要将其更改为:
attr_reader :selenium_driver
before(:all) do
@selenium_driver = create_driver($hub_url, $hub_port, $browser)
@selenium_driver.start_new_browser_session
end
基本上它是相同的代码只是不同的变量名称。 selenium-client使用该约定将上下文信息应用于测试。
答案 1 :(得分:0)
它说无法找到变量selenium_driver
。
Problem while setting context on example startundefined local variable or method `selenium_driver' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f2d2cd840e0>
由字符串"Problem while setting context on example start"
加上
e
生成的内容)组成
"undefined local variable or method `selenium_driver' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f2d2cd840e0>"`.
答案 2 :(得分:0)
添加
gem "selenium-client"
到 Gemfile (不要忘记运行$ bundle install
)
并在 spec / spec_helper.rb
中添加以下内容require "selenium/client"
require "selenium/rspec/spec_helper"