Starting a new capybara session for each test

I am trying to start a new Capybara session for each of our rspec tests and cannot figure out how to correctly end / close the session at the end.

Here is my spec_helper.rb file.

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 

The @ session.driver.browser.quit statement correctly closes the browser, but for the last test that starts, an error message appears:

 /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' 

I believe the problem is that Capybara also exits the browser upon completion of all tests. Does anyone know the correct way to do this and how can I silence this error message? Thanks for any help.

==== ===== UPDATE

To close the loop, I sent my problem to the Google Capybara group, and it was fixed and combined with the wizard.

https://groups.google.com/forum/#!topic/ruby-capybara/tZi2F306Fvo

+6
source share
3 answers

Try using Capybara.reset_session.

 feature "my test" do before do my logic end after { Capybara.reset_sessions! } scenario "my test" do blablabla end end 
+5
source

Maybe there is a sauce method that you can use for a recording clip, and instead name it instead of after ?

Instead of leaving after each test, perhaps you could leave before each of them? If you get an error message trying to exit before it executes, is there perhaps a way to verify that it is already running? If not, you can make a terrible, nasty hack: set the global variable to after , which will let you know that there is a driver that you can leave behind.

0
source

Old question, but I ran into this problem. If you have Capybara :: Session, the browser remains open after each SPEC, which leads to multiple browsers when multiple SPEC files are launched. There is no Capybara: Session quit method, so first you need to get the driver object, and then exit. I usually add this at the end of each SPEC file:

 after :all do @capybara_session.driver.quit() end 

where @capybara_session is the Capybara :: Session object.

0
source

Source: https://habr.com/ru/post/957646/


All Articles