Sha256: 2debc64c16c3244913815799c282a93872d3a8322db6db142685fd7d0ad28ee9

Contents?: true

Size: 1.68 KB

Versions: 20

Compression:

Stored size: 1.68 KB

Contents

require_relative "../webdriver_script_adapter/execute_async_script_adapter"
require_relative "../webdriver_script_adapter/frame_adapter"
require_relative "../webdriver_script_adapter/query_selector_adapter"
require_relative "../loader"
require_relative "./configuration"
require 'timeout'

module Axe
  class Core
    JS_NAME = "axe"

    def initialize(page)
      @page = wrap_driver page
      load_axe_core Axe::Configuration.instance.jslib
    end

    def call(callable)
      if use_run_partial
        callable.analyze_post_43x @page, self
      else
        callable.call @page
      end
    end

    def call_verbatim(callable)
      callable.call @page
    end

    def self.has_run_partial?(page)
      page.evaluate_script <<-JS
          typeof window.axe.runPartial === 'function'
      JS
    end

    private

    def use_run_partial
      Core.has_run_partial?(@page) and not Axe::Configuration.instance.legacy_mode
    end

    def load_axe_core(source)
      return if already_loaded?
      loader = Common::Loader.new(@page, self)
      loader.load_top_level source
      return if use_run_partial

      loader.call source
    end

    def already_loaded?
      @page.evaluate_script <<-JS
        window.#{JS_NAME} &&
        typeof #{JS_NAME}.run === 'function'
      JS
    end

    def wrap_driver(driver)
      driver = driver.driver if driver.respond_to? :driver
      ::WebDriverScriptAdapter::QuerySelectorAdapter.wrap(
        ::WebDriverScriptAdapter::FrameAdapter.wrap(
          ::WebDriverScriptAdapter::ExecuteAsyncScriptAdapter.wrap(
            ::WebDriverScriptAdapter::ExecEvalScriptAdapter.wrap(
              driver
            )
          )
        )
      )
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

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