我正在尝试这个
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 还是 selenium 版本问题?
我正在使用 FF 45 和 selenium 2.53 以及 rspec 3.5.4。
最佳答案
这是一个 RSpec 问题。 before/after(:all) Hook 只能访问在其范围或外部范围级别定义的实例变量,但不能访问在当前运行的规范中声明的实例变量。 after(:each) 钩子(Hook)确实可以访问当前规范中声明的实例变量。
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
关于ruby - 面对这个问题@driver.quit 在之后给出错误(:context ) in rspec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42828055/