Anusha
Anusha

Reputation: 21

How to Close a Browser with capybara?

In my code i am opening a browser as follow :-

Capybara.current_driver = :selenium
include Capybara::DSL
describe 'Auro' do
specify "OMX Manual Order" do
visit 'https://omx.ordermotion.com/en/console.asp'
end

How can i close this browser?

Have Tried following ,but no luck:-

  1. Capybara.current_session.driver.reset!

  2. page.execute_script "window.close();"

Upvotes: 2

Views: 2936

Answers (3)

parad1gm
parad1gm

Reputation: 470

If you're only using selenium, then the following should work:

page.driver.quit

However, if you ever want to switch between different webdrivers, then you might want to add a condition or two. This is what I use:

page.driver.quit unless (Capybara.current_driver == :webkit || Capybara.current_driver == :sauce)

:webkit refers to the headless capybara-webkit and :sauce refers to Sauce Labs, but you can use that code for whichever webdrivers you want to use.

Hope that helps!

Upvotes: 4

Phil
Phil

Reputation: 916

Try some of these

page.driver.browser.close

or

window = page.current_window
window.close

Keep in mind that if you have no other windows to switch to, an error will be raised

Upvotes: 2

Matt
Matt

Reputation: 21

Try giving this a shot:

page.execute_script "window.close();"

Upvotes: 0

Related Questions