Reputation: 2565
I have a situation when I'm using (using :selenium driver) multiple browsers with Capybara to test my front-end. How can I close some of them using Capybara, when they are not needed?
Upvotes: 14
Views: 10976
Reputation: 1725
If you want to close each window after each test finishes rather than closing all the windows at the end of your test suit, try:
after do
Capybara.current_session.driver.quit
end
Upvotes: 8
Reputation: 10195
Also:
page.driver.browser.close
Definitely works for Selenium, though it looks like possibly not for capybara-webkit.
Upvotes: 8
Reputation: 71
Inside the env.rb file insert this code
After do |scenario|
print "OZONEEEEE"
page.execute_script "window.close();"
# restart Selenium driver
Capybara.send(:session_pool).delete_if { |key, value| key =~ /selenium/i }
end
Upvotes: 1
Reputation: 14720
If the tabs/windows are opened using JavaScript, then JavaScript is allowed to close them. You can execute JS in Capybara test using page.execute_script
.
page.execute_script "window.close();"
Upvotes: 8