def switch_to_window(window = nil, **options, &window_locator)
      raise ArgumentError, '`switch_to_window` can take either a block or a window, not both' if window && block_given?
      raise ArgumentError, '`switch_to_window`: either window or block should be provided' if !window && !block_given?

      unless scopes.last.nil?
        raise Capybara::ScopeError, '`switch_to_window` is not supposed to be invoked from '\
                                    '`within` or `within_frame` blocks.'
      end

      _switch_to_window(window, options, &window_locator)
    end
def switch_to_window(window = nil, **options, &window_locator)
      raise ArgumentError, '`switch_to_window` can take either a block or a window, not both' if window && block_given?
      raise ArgumentError, '`switch_to_window`: either window or block should be provided' if !window && !block_given?

      unless scopes.last.nil?
        raise Capybara::ScopeError, '`switch_to_window` is not supposed to be invoked from '\
                                    '`within` or `within_frame` blocks.'
      end

      _switch_to_window(window, options, &window_locator)
    end
@overload switch_to_window(&block)
   Switches to the first window for which given block returns a value other than false or nil.
   If window that matches block can't be found, the window will be switched back and `WindowError` will be raised.
   @example
     window = switch_to_window { title == 'Page title' }
   @raise [Capybara::WindowError]     if no window matches given block
 @overload switch_to_window(window)
   @param window [Capybara::Window]   window that should be switched to
   @raise [Capybara::Driver::Base#no_such_window_error] if nonexistent (e.g. closed) window was passed

 @return [Capybara::Window]         window that has been switched to
 @raise [Capybara::ScopeError]        if this method is invoked inside `within` or
   `within_frame` methods
 @raise [ArgumentError]               if both or neither arguments were provided