Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart browser with Capybara on every scenario?

I run tests using Cucumber in conjunction with Capybara and Selenium-Webdriver. I want restart browser after each scenario. Here is my env.rb. I can add in After section something like this:

After do |scenario|
  onError scenario if scenario.failed?
  page.driver.browser.close
end

but this kills browser after first scenario passed and all other scenarios failed with reasonable error:

Errno::ECONNREFUSED: Connection refused - connect(2) for "127.0.0.1" port 7055

Is there way to refactor my env.rb to use Before hook to start browser on every scenario?

like image 761
Denis Avatar asked Jan 25 '26 04:01

Denis


1 Answers

Simple:

Before do
  Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end
like image 117
Denis Avatar answered Jan 27 '26 22:01

Denis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!