spec/watirspec/window_switching_spec.rb in watir-6.14.0 vs spec/watirspec/window_switching_spec.rb in watir-6.15.0
- old
+ new
@@ -224,12 +224,23 @@
it 'returns false if closed window is referenced' do
browser.window(title: 'closeable window').use
browser.a(id: 'close').click
Watir::Wait.until { browser.windows.size == 1 }
- expect(browser.window).to_not be_present
+ expect(browser.window).to_not exist
end
+
+ it 'returns false if window closes during iteration' do
+ browser.window(title: 'closeable window').use
+ original_handle = browser.original_window.instance_variable_get('@handle')
+ handles = browser.windows.map { |w| w.instance_variable_get('@handle') }
+
+ browser.a(id: 'close').click
+ Watir::Wait.until { browser.windows.size == 1 }
+ allow(browser.wd).to receive(:window_handles).and_return(handles, [original_handle])
+ expect(browser.window(title: 'closeable window')).to_not exist
+ end
end
end
end
describe '#current?' do
@@ -266,9 +277,51 @@
it 'raises NoMatchingWindowFoundException error when attempting to use the current window if it is closed' do
browser.window(title: 'closeable window').use
browser.a(id: 'close').click
Watir::Wait.until { browser.windows.size == 1 }
expect { browser.window.use }.to raise_no_matching_window_exception
+ end
+ end
+ end
+ end
+
+ it 'raises an exception when using an element on a closed window' do
+ window = browser.window(title: 'closeable window')
+ window.use
+ browser.a(id: 'close').click
+ msg = 'browser window was closed'
+ expect { browser.a.text }.to raise_exception(Watir::Exception::NoMatchingWindowFoundException, msg)
+ end
+
+ it 'raises an exception when locating a closed window' do
+ browser.window(title: 'closeable window').use
+ handles = browser.windows.map(&:handle)
+ browser.a(id: 'close').click
+ allow(browser.wd).to receive(:window_handles).and_return(handles, [browser.original_window.handle])
+ expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
+ end
+
+ it 'raises an exception when locating a window closed during lookup' do
+ browser.window(title: 'closeable window').use
+ browser.a(id: 'close-delay').click
+
+ begin
+ module Watir
+ class Browser
+ alias title_old title
+
+ def title
+ sleep 0.5
+ title_old
+ end
+ end
+ end
+
+ expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
+ ensure
+ module Watir
+ class Browser
+ alias title title_old
end
end
end
end
end