1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Remove deprecated Session#within_window support for a string argument

This commit is contained in:
Thomas Walpole 2017-11-13 11:11:49 -08:00
parent 0a314baa45
commit 3f7b8c066b
4 changed files with 1 additions and 93 deletions

View file

@ -98,10 +98,6 @@ class Capybara::Driver::Base
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#switch_to_window' raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#switch_to_window'
end end
def within_window(locator)
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#within_window'
end
def no_such_window_error def no_such_window_error
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#no_such_window_error' raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#no_such_window_error'
end end

View file

@ -226,11 +226,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
browser.switch_to.window handle browser.switch_to.window handle
end end
def within_window(locator)
handle = find_window(locator)
browser.switch_to.window(handle) { yield }
end
def accept_modal(_type, **options) def accept_modal(_type, **options)
if headless_chrome? if headless_chrome?
raise ArgumentError, "Block that triggers the system modal is missing" unless block_given? raise ArgumentError, "Block that triggers the system modal is missing" unless block_given?
@ -335,23 +330,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
end end
end end
def find_window(locator)
handles = browser.window_handles
return locator if handles.include? locator
original_handle = browser.window_handle
handles.each do |handle|
switch_to_window(handle)
if (locator == browser.execute_script("return window.name") ||
browser.title.include?(locator) ||
browser.current_url.include?(locator))
switch_to_window(original_handle)
return handle
end
end
raise Capybara::ElementNotFound, "Could not find a window identified by #{locator}"
end
def insert_modal_handlers(accept, response_text) def insert_modal_handlers(accept, response_text)
prompt_response = if accept prompt_response = if accept
if response_text.nil? if response_text.nil?

View file

@ -506,9 +506,6 @@ module Capybara
# @example # @example
# within_window(->{ page.title == 'Page title' }) { click_button 'Submit' } # within_window(->{ page.title == 'Page title' }) { click_button 'Submit' }
# @raise [Capybara::WindowError] if no window matching lambda was found # @raise [Capybara::WindowError] if no window matching lambda was found
# @overload within_window(string) { do_something }
# @deprecated Pass window or lambda instead
# @param [String] handle, name, url or title of the window
# #
# @raise [Capybara::ScopeError] if this method is invoked inside `within_frame` method # @raise [Capybara::ScopeError] if this method is invoked inside `within_frame` method
# @return value returned by the block # @return value returned by the block
@ -541,16 +538,7 @@ module Capybara
scopes.pop scopes.pop
end end
else else
offending_line = caller.first raise ArgumentError("`#within_window` requires a `Capybara::Window` instance or a lambda")
file_line = offending_line.match(/^(.+?):(\d+)/)[0]
warn "DEPRECATION WARNING: Passing string argument to #within_window is deprecated. "\
"Pass window object or lambda. (called from #{file_line})"
begin
scopes << nil
driver.within_window(window_or_handle) { yield }
ensure
scopes.pop
end
end end
end end

View file

@ -155,58 +155,4 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
expect(@session.send(:scopes)).to eq([nil]) expect(@session.send(:scopes)).to eq([nil])
end end
end end
context "with string" do
it "should warn" do
expect(@session).to receive(:warn).with(/DEPRECATION WARNING/).and_call_original
@session.within_window('firstPopup') {}
end
it "should find window by handle" do
window = (@session.windows - [@window]).first
@session.within_window window.handle do
expect(@session).to have_title(/Title of the first popup|Title of popup two/)
end
end
it "should find the div in firstPopup" do
@session.within_window("firstPopup") do
expect(@session.find("//*[@id='divInPopupOne']").text).to eq 'This is the text of divInPopupOne'
end
end
it "should find the div in secondPopup" do
@session.within_window("secondPopup") do
expect(@session.find("//*[@id='divInPopupTwo']").text).to eq 'This is the text of divInPopupTwo'
end
end
it "should find the divs in both popups" do
@session.within_window("secondPopup") do
expect(@session.find("//*[@id='divInPopupTwo']").text).to eq 'This is the text of divInPopupTwo'
end
@session.within_window("firstPopup") do
expect(@session.find("//*[@id='divInPopupOne']").text).to eq 'This is the text of divInPopupOne'
end
end
it "should find the div in the main window after finding a div in a popup" do
@session.within_window("secondPopup") do
expect(@session.find("//*[@id='divInPopupTwo']").text).to eq 'This is the text of divInPopupTwo'
end
expect(@session.find("//*[@id='doesNotOpenWindows']").text).to eq 'Does not open windows'
end
it "should reset scope when switching windows" do
@session.within(:css, '#doesNotOpenWindows') do
@session.within_window("secondPopup") do
expect(@session.find("//*[@id='divInPopupTwo']").text).to eq 'This is the text of divInPopupTwo'
end
end
end
it "should switch back if exception was raised inside block" do
expect do
@session.within_window('secondPopup') do
raise 'some error'
end
end.to raise_error(StandardError, 'some error')
expect(@session.current_window).to eq(@window)
end
end
end end