我正在尝试为我们的每个 rspec 测试启动一个新的 Capybara 会话,但无法弄清楚如何在完成后正确退出/关闭会话。
这是我的 spec_helper.rb 文件。
RSpec.configure do |config|
config.include Capybara::DSL
config.before :each do
@session = Capybara::Session.new(:selenium)
end
config.after :each do
@session.driver.browser.quit
end
end
@session.driver.browser.quit 语句正确关闭了浏览器,但对于最后运行的测试,我收到一条错误消息:
/Users/lpc/.rvm/gems/ruby-1.9.3-p448@capybara/gems/selenium-webdriver-2.37.0/lib/selenium/webdriver/common/file_reaper.rb:32:in `reap': file not added for reaping: "/var/folders/5l/kw4vv8bj7rvc4xv6yfyspkwh0000gn/T/webdriver-profile20131107-96496-cx4x5r" (Selenium::WebDriver::Error::WebDriverError)
from /Users/lpc/.rvm/gems/ruby-1.9.3-p448@capybara/gems/selenium-webdriver-2.37.0/lib/selenium/webdriver/firefox/launcher.rb:45:in `quit'
from /Users/lpc/.rvm/gems/ruby-1.9.3-p448@capybara/gems/selenium-webdriver-2.37.0/lib/selenium/webdriver/firefox/bridge.rb:58:in `ensure in quit'
from /Users/lpc/.rvm/gems/ruby-1.9.3-p448@capybara/gems/selenium-webdriver-2.37.0/lib/selenium/webdriver/firefox/bridge.rb:58:in `quit'
from /Users/lpc/.rvm/gems/ruby-1.9.3-p448@capybara/gems/selenium-webdriver-2.37.0/lib/selenium/webdriver/common/driver.rb:168:in `quit'
from /Users/lpc/.rvm/gems/ruby-1.9.3-p448@capybara/gems/capybara-2.1.0/lib/capybara/selenium/driver.rb:140:in `quit'
from /Users/lpc/.rvm/gems/ruby-1.9.3-p448@capybara/gems/capybara-2.1.0/lib/capybara/selenium/driver.rb:17:in `block in browser'
我相信问题是因为 Capybara 在所有测试结束时也退出了浏览器。有谁知道执行此操作的正确方法以及如何使此错误消息静音?谢谢你的帮助。
====更新=====
为了结束这个循环,我发布到 Capybara 谷歌组,我的问题已修复并合并到 master 中。
https://groups.google.com/forum/#!topic/ruby-capybara/tZi2F306Fvo