Class: AxeCuprite::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/axe/cuprite/runner.rb

Overview

Framework-agnostic entry point. No RSpec required.

results = AxeCuprite::Runner.new(page).run(
  context: "#main",
  options: { runOnly: { type: "rule", values: ["color-contrast"] } }
)
results.violations  # => [AxeCuprite::Violation, ...]

‘page` is a Capybara session (e.g. the `page` in a Capybara test).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, configuration: AxeCuprite.configuration) ⇒ Runner

Returns a new instance of Runner.



18
19
20
21
22
# File 'lib/axe/cuprite/runner.rb', line 18

def initialize(page, configuration: AxeCuprite.configuration)
  @page = page
  @configuration = configuration
  @injector = Injector.new(page, configuration)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



16
17
18
# File 'lib/axe/cuprite/runner.rb', line 16

def configuration
  @configuration
end

#pageObject (readonly)

Returns the value of attribute page.



16
17
18
# File 'lib/axe/cuprite/runner.rb', line 16

def page
  @page
end

Instance Method Details

#inject!(force: false) ⇒ Object

Force or ensure axe is injected (idempotent unless force: true). Useful when auto_inject is disabled, or to re-inject after a navigation.



39
40
41
# File 'lib/axe/cuprite/runner.rb', line 39

def inject!(force: false)
  @injector.ensure_injected!(force: force)
end

#injected?Boolean

Is axe-core present on the current page?

Returns:

  • (Boolean)


44
45
46
# File 'lib/axe/cuprite/runner.rb', line 44

def injected?
  @injector.injected?
end

#run(context: nil, options: {}, timeout: nil) ⇒ Object

Inject axe if not already present, run axe.run(context, options) via the async path, and return an AxeCuprite::Results.

  • context: axe context arg — a CSS selector String, or a Hash with :include / :exclude, or nil for the whole document.

  • options: axe run options Hash (runOnly, rules, resultTypes, …). Deep-merged on top of the configured default_options.

  • timeout: override the configured axe timeout (seconds) for this run.



32
33
34
35
# File 'lib/axe/cuprite/runner.rb', line 32

def run(context: nil, options: {}, timeout: nil)
  merged = merge_options(options)
  @injector.run(context: normalize_context(context), options: merged, timeout: timeout)
end