Sha256: b727bb6da7398305a2cdf8ec3aaf7b02a530aec78b57b317cafb5fd3a02cea0f

Contents?: true

Size: 1.64 KB

Versions: 21

Compression:

Stored size: 1.64 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

    private

    def use_run_partial
      has_run_partial? 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 has_run_partial?
      @page.evaluate_script <<-JS
          typeof window.axe.runPartial === 'function'
      JS
    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

21 entries across 21 versions & 1 rubygems

Version Path
axe-core-api-4.4.1 lib/axe/core.rb
axe-core-api-4.4.0.pre.f437c8e lib/axe/core.rb
axe-core-api-4.4.0 lib/axe/core.rb
axe-core-api-4.3.2.pre.9952248 lib/axe/core.rb
axe-core-api-4.3.2.pre.17fb7c9 lib/axe/core.rb
axe-core-api-4.3.2.pre.2e32f26 lib/axe/core.rb
axe-core-api-4.3.2.pre.dc71aca lib/axe/core.rb
axe-core-api-4.3.2 lib/axe/core.rb
axe-core-api-4.3.1.pre.75130b0 lib/axe/core.rb
axe-core-api-4.3.1.pre.8005df2 lib/axe/core.rb
axe-core-api-4.3.1 lib/axe/core.rb
axe-core-api-4.3.0.pre.a04c46c lib/axe/core.rb
axe-core-api-4.3.0.pre.99d4475 lib/axe/core.rb
axe-core-api-4.3.0.pre.5d6d4c3 lib/axe/core.rb
axe-core-api-4.3.0.pre.4296492 lib/axe/core.rb
axe-core-api-4.3.0 lib/axe/core.rb
axe-core-api-4.2.1.pre.ea3a33f lib/axe/core.rb
axe-core-api-4.2.1.pre.d87a85a lib/axe/core.rb
axe-core-api-4.2.1.pre.1329c45 lib/axe/core.rb
axe-core-api-4.2.0.pre.33afee3 lib/axe/core.rb