我正在尝试这个
require 'rspec'
require 'selenium-webdriver'
RSpec.describe 'New test' do
before :each do
@driver = Selenium::WebDriver.for (:firefox)
end
after :all do
@driver.quit
end
it 'should signup and create a new user' do
p 'testing'
end
end
这是我得到的错误
rspec test.rb [13:04:18]
"testing"
.
An error occurred in an `after(:context)` hook.
Failure/Error: @driver.quit
NoMethodError:
undefined method `quit' for nil:NilClass
# ./test.rb:11:in `block (2 levels) in <top (required)>'
Finished in 4.61 seconds (files took 0.17828 seconds to load)
1 example, 0 failures
我确信这是一件我想念的小事但却找不到任何帮助。
这是FF版还是硒版?
我使用的是FF 45和selenium 2.53以及rspec 3.5.4。
答案 0 :(得分:1)
这是一个RSpec问题。 before / after(:all)钩子只能访问在其作用域或外部作用域级别中定义的实例变量,但不能访问在当前运行的规范中声明的实例变量。 after(:each)钩子可以访问当前规范中声明的实例变量。
before :all do
@a = 2
end
context "blah" do
before :all do
@b = 3
end
it "blah blah" do
@c = 4
# @a,@b,@c all accessible here
end
after :each do
#@a, @b, @c accessible here
end
after :all do
# @a,@b accessible here
end
end
after :all do
#can access @a
end