I am having some issues in Jenkins. After test execution completes, the browser session is still alive, which is creating some other issue in the pipeline. So I want to quit the browser session after execution completed in my Test Suite. I am using Cucumber>Capybara>SitePrism>Ruby.
How I can do that? I want something like below which will execute after very end of my test suite:
RSpec.configure do |config|
config.after(:suite) do
puts 'Destroy Driver'
end
end
This answer is for folks coming here from their internet searches.
Use the
quit
instance method defined by Capybara::Session.I found two ways to hit this:
Capybara::DSL
directly (e.g. in a plain ruby script like I am),current_scope.session.quit
does the trick.Capybara.current_session.quit
is probably what you need in an RSpec hook since theCapybara::Session
methods won't be mixed in there.Note: The original question seems a bit like an XY problem. I've never had to manually close Capybara sessions after tests and it makes me think there's some other configuration error or other problem getting in the way. Considering the OP is 5 years old however, this is a moot point, although I figured I'd mention it for completeness' sake.