Sha256: 17c82216c37011c51286fffce37559f5786a033a2f86905bee72fbe8ddcf5939

Contents?: true

Size: 1.66 KB

Versions: 45

Compression:

Stored size: 1.66 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"

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

45 entries across 45 versions & 1 rubygems

Version Path
axe-core-api-4.7.0.pre.3fef592 lib/axe/core.rb
axe-core-api-4.7.0.pre.5cb81f7 lib/axe/core.rb
axe-core-api-4.6.1.pre.efd9226 lib/axe/core.rb
axe-core-api-4.7.0 lib/axe/core.rb
axe-core-api-4.6.1.pre.bb0471d lib/axe/core.rb
axe-core-api-4.6.1.pre.74de72f lib/axe/core.rb
axe-core-api-4.6.1.pre.311e4da lib/axe/core.rb
axe-core-api-4.6.1.pre.c43ee49 lib/axe/core.rb
axe-core-api-4.6.1.pre.81ca285 lib/axe/core.rb
axe-core-api-4.6.1.pre.4dbab74 lib/axe/core.rb
axe-core-api-4.6.1.pre.6f8a176 lib/axe/core.rb
axe-core-api-4.6.1 lib/axe/core.rb
axe-core-api-4.6.0.pre.47f4589 lib/axe/core.rb
axe-core-api-4.6.0.pre.761c828 lib/axe/core.rb
axe-core-api-4.6.0.pre.094e546 lib/axe/core.rb
axe-core-api-4.6.0 lib/axe/core.rb
axe-core-api-4.5.1.pre.9e72a1b lib/axe/core.rb
axe-core-api-4.5.1.pre.9dea670 lib/axe/core.rb
axe-core-api-4.5.1.pre.e6f7e3f lib/axe/core.rb
axe-core-api-4.5.1.pre.4e009be lib/axe/core.rb