Class: Sa11y::Analyze

Inherits:
Object
  • Object
show all
Defined in:
lib/sa11y/analyze.rb

Overview

Analyzes Current Webpage with axe™ Accessibility Tool from Deque

Constant Summary collapse

AXE_RUN_SCRIPT =
<<~AXE
  var callback = arguments[arguments.length - 1];var context = typeof arguments[0] === 'string' ?
  JSON.parse(arguments[0]) : arguments[0];context = context || document;
  var options = JSON.parse(arguments[1]);axe.run(context, options,
  function (err, results) {  {    if (err) {      throw new Error(err);    }    callback(results);  }});
AXE
IFRAME_ALLOWED_SCRIPT =
"axe.configure({ allowedOrigins: ['<unsafe_all_origins>'] });"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver, js_lib: nil, frames: true, cross_origin: false) ⇒ Analyze

Returns a new instance of Analyze.



31
32
33
34
35
36
# File 'lib/sa11y/analyze.rb', line 31

def initialize(driver, js_lib: nil, frames: true, cross_origin: false)
  @driver = driver
  @js_lib = js_lib || File.read(File.expand_path("../scripts/axe.min.js", __dir__))
  @frames = frames
  @cross_origin = cross_origin
end

Instance Attribute Details

#cross_originObject

Returns the value of attribute cross_origin.



14
15
16
# File 'lib/sa11y/analyze.rb', line 14

def cross_origin
  @cross_origin
end

#framesObject

Returns the value of attribute frames.



14
15
16
# File 'lib/sa11y/analyze.rb', line 14

def frames
  @frames
end

#js_libObject

Returns the value of attribute js_lib.



14
15
16
# File 'lib/sa11y/analyze.rb', line 14

def js_lib
  @js_lib
end

Instance Method Details

#resultsObject



38
39
40
41
42
43
44
45
46
# File 'lib/sa11y/analyze.rb', line 38

def results
  if @frames
    @driver.switch_to.default_content
    manage_frames
  else
    @driver.execute_script(@js_lib)
  end
  @driver.execute_async_script(AXE_RUN_SCRIPT, nil, "{}")
end