Merge pull request #1986 from teamcapybara/reset_windows

Driver reset! should close all but 1 window
This commit is contained in:
Thomas Walpole 2018-03-14 09:19:52 -07:00 committed by GitHub
commit 590793d004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -108,6 +108,8 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
# Use instance variable directly so we avoid starting the browser just to reset the session
return unless @browser
window_handles.reject { |handle| handle == current_window_handle }.each { |win| close_window(win) }
navigated = false
start_time = Capybara::Helpers.monotonic_time
begin

View File

@ -63,6 +63,24 @@ Capybara::SpecHelper.spec '#reset_session!' do
expect(@session.current_path).to eq("/")
end
it "closes extra windows", requires: [:windows] do
@session.visit('/with_html')
@session.open_new_window
@session.open_new_window
expect(@session.windows.size).to eq 3
@session.reset_session!
expect(@session.windows.size).to eq 1
end
it "closes extra windows when not on the first window", requires: [:windows] do
@session.visit('/with_html')
@session.switch_to_window(@session.open_new_window)
@session.open_new_window
expect(@session.windows.size).to eq 3
@session.reset_session!
expect(@session.windows.size).to eq 1
end
context "When reuse_server == false" do
before do
@reuse_server = Capybara.reuse_server