Sha256: af6d498f10102ce59acb73c30826650cc350bc21d7dc17e7da2dfff6600688c7

Contents?: true

Size: 1.19 KB

Versions: 121

Compression:

Stored size: 1.19 KB

Contents

require 'dumb_delegator'

module WebDriverScriptAdapter
  # Capybara distinguishes eval from exec
  # (eval is a query, exec is a command)
  # this decorator makes webdriver act like capybara
  class ExecEvalScriptAdapter < ::DumbDelegator
    def self.wrap(driver)
      raise WebDriverError, "WebDriver must respond to #execute_script" unless driver.respond_to? :execute_script

      driver.respond_to?(:evaluate_script) ? ExecEvalScriptAdapter2.new(driver) : new(driver)
    end

    # executes script without returning result
    def execute_script(script)
      super
      nil
    end

    # returns result of executing script
    def evaluate_script(script)
      __getobj__.execute_script "return #{script}"
    end

    def execute_script_fixed(script, *args)
      page = __getobj__
      page.execute_script(script, *args)
    end
  end
  class ExecEvalScriptAdapter2 < ::DumbDelegator
    def execute_script_fixed(script, *args)
      page = __getobj__
      page = page.driver if page.respond_to?("driver")
      page = page.browser if page.respond_to?("browser") and not page.browser.is_a?(::Symbol)
      page.execute_script(script, *args)
    end
  end

  class WebDriverError < TypeError; end
end

Version data entries

121 entries across 121 versions & 1 rubygems

Version Path
axe-core-api-4.10.1.pre.5294583 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.2 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.2.pre.2cca230 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.1.pre.46a0052 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.1.pre.7e72b19 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.1.pre.5e15f96 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.2.pre.5bd4e5c lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.1.pre.7bf959f lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.1 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.0.pre.53569f6 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.1.pre.7a3723a lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.0.pre.d102edb lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.9.1.pre.7a03090 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.9.1.pre.1a5838a lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.0 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.10.0.pre.5d7eac5 lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.9.1.pre.f16172e lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.9.1.pre.09e659e lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.9.1.pre.a80eeee lib/webdriver_script_adapter/exec_eval_script_adapter.rb
axe-core-api-4.9.0.pre.a02013a lib/webdriver_script_adapter/exec_eval_script_adapter.rb