lib/howitzer/web/capybara_methods_proxy.rb in howitzer-2.2.0 vs lib/howitzer/web/capybara_methods_proxy.rb in howitzer-2.3.0

- old
+ new

@@ -1,21 +1,21 @@ require 'capybara' require 'active_support' require 'active_support/core_ext' # Remove this monkey patch after fixing the bugs in selenium-webdriver / capybara -#:nocov: +# :nocov: class Capybara::Selenium::Driver # rubocop:disable Style/ClassAndModuleChildren # # https://github.com/teamcapybara/capybara/issues/1845 def title return browser.title unless within_frame? find_xpath('/html/head/title').map { |n| n[:text] }.first.to_s end - # Known issue, works differently for phantomjs and real browsers + # Known issue, works differently for real browsers # https://github.com/seleniumhq/selenium/issues/1727 def current_url return browser.current_url unless within_frame? execute_script('return document.location.href') @@ -25,24 +25,30 @@ def within_frame? !(@frame_handles.blank? || @frame_handles[browser.window_handle].blank?) end end -#:nocov: +# :nocov: module Howitzer module Web # This module proxies required original capybara methods to recipient module CapybaraMethodsProxy - PROXIED_CAPYBARA_METHODS = Capybara::Session::SESSION_METHODS + #:nodoc: + PROXIED_CAPYBARA_METHODS = Capybara::Session::SESSION_METHODS + # :nodoc: Capybara::Session::MODAL_METHODS + %i[driver text] # Capybara form dsl methods are not compatible with page object pattern and Howitzer gem. # Instead of including Capybara::DSL module, we proxy most interesting Capybara methods and # prevent using extra methods which can potentially broke main principles and framework concept PROXIED_CAPYBARA_METHODS.each do |method| - define_method(method) { |*args, &block| Capybara.current_session.send(method, *args, &block) } + define_method(method) do |*args, **options, &block| + if options.present? + Capybara.current_session.send(method, *args, **options, &block) + else + Capybara.current_session.send(method, *args, &block) + end + end end # Accepts or declines JS alert box by given flag # @param flag [Boolean] Determines accept or decline alert box