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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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();"
回答2:
Also:
page.driver.browser.close
Definitely works for Selenium, though it looks like possibly not for capybara-webkit.
回答3:
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
回答4:
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