From 3f7b8c066b1bc80a42acfa885bd81510c5922bb0 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 13 Nov 2017 11:11:49 -0800 Subject: [PATCH] Remove deprecated Session#within_window support for a string argument --- lib/capybara/driver/base.rb | 4 -- lib/capybara/selenium/driver.rb | 22 -------- lib/capybara/session.rb | 14 +---- .../spec/session/window/within_window_spec.rb | 54 ------------------- 4 files changed, 1 insertion(+), 93 deletions(-) diff --git a/lib/capybara/driver/base.rb b/lib/capybara/driver/base.rb index f2a32935..536e3d91 100644 --- a/lib/capybara/driver/base.rb +++ b/lib/capybara/driver/base.rb @@ -98,10 +98,6 @@ class Capybara::Driver::Base raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#switch_to_window' end - def within_window(locator) - raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#within_window' - end - def no_such_window_error raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#no_such_window_error' end diff --git a/lib/capybara/selenium/driver.rb b/lib/capybara/selenium/driver.rb index 8b7839df..26a7efbc 100644 --- a/lib/capybara/selenium/driver.rb +++ b/lib/capybara/selenium/driver.rb @@ -226,11 +226,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base browser.switch_to.window handle end - def within_window(locator) - handle = find_window(locator) - browser.switch_to.window(handle) { yield } - end - def accept_modal(_type, **options) if headless_chrome? 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 - 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) prompt_response = if accept if response_text.nil? diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index 6e410ffc..afd9231c 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -506,9 +506,6 @@ module Capybara # @example # within_window(->{ page.title == 'Page title' }) { click_button 'Submit' } # @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 # @return value returned by the block @@ -541,16 +538,7 @@ module Capybara scopes.pop end else - offending_line = caller.first - 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 + raise ArgumentError("`#within_window` requires a `Capybara::Window` instance or a lambda") end end diff --git a/lib/capybara/spec/session/window/within_window_spec.rb b/lib/capybara/spec/session/window/within_window_spec.rb index a9c34e1d..69a5e450 100644 --- a/lib/capybara/spec/session/window/within_window_spec.rb +++ b/lib/capybara/spec/session/window/within_window_spec.rb @@ -155,58 +155,4 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do expect(@session.send(:scopes)).to eq([nil]) 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