sa11y 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25c2a67f3499df5c522d4e66622b1012365c50ee1b96a9f344076330bc651c3d
4
- data.tar.gz: 5aa9383902ecf14392960ffb1d289c7e0696d675ecd122c1cbe5afe3df755ce8
3
+ metadata.gz: e457e53b58f1040f0598cbe44bb84ed5a6ec6c98768bdc0c5b0488037df96b6b
4
+ data.tar.gz: 60c7e99dd8574dce7988d23bdb3c4973455ad9993a60414d8d1a28ef2e689bef
5
5
  SHA512:
6
- metadata.gz: b718733d4817c340b5540cbb8240401ba014d46b3a6dac5443c6881fcf41a7f3abce440709dc377467969265ac5a53d71feaac0212f7bab726b7aee228e8a3ae
7
- data.tar.gz: 7e9ddd0cb43d12611913fd8e3ad0ff6450d75593dc095fee8d047b0f8ef56e71a4ee76f08d651dbe5c83e77f0537f792eb5fe6eb727c5561d5ac1a75223aab98
6
+ metadata.gz: 53efed9661b3fda64a6385f36f20bdf4cccd406b86f51eed73c022eaf59c2cfb0a8d74240bc0386749de79b5eb188a28af8394bf3e4233c00a7193be966af4da
7
+ data.tar.gz: 4d1f3f9cb17489dd3ae21a4030f733405116ba8d48e67822cb6a1dc4298e8774cff43c7c677e8ac2af7f65b70e59311b1509ab5f1af9eda1b91a6efe430309bd
data/README.md CHANGED
@@ -52,18 +52,28 @@ driver = Selenium::WebDriver.for :chrome
52
52
  Sa11y::Analyze(driver).results
53
53
  ```
54
54
 
55
- If your site does not use iFrames, you can improve performance slightly by turning off iframe checks:
55
+ By default, sa11y inspects elements in all frames and iframes on the page.
56
+ If your site does not use frames, you can improve performance slightly by turning off frame checks:
56
57
  ```ruby
57
- driver = Selenium::WebDriver.for :chrome
58
- analyze = Sa11y::Analyze(driver)
59
- analyze.iframes = false
58
+ driver = Selenium::WebDriver.for :chrome
59
+ analyze = Sa11y::Analyze(driver, frames: false)
60
+ analyze.results
61
+ ```
62
+
63
+ By default, sa11y does not inspect frames from cross origins. If you need to analyze frames
64
+ originating from a different domain, you need to turn this on:
65
+ ```ruby
66
+ driver = Selenium::WebDriver.for :chrome
67
+ analyze = Sa11y::Analyze(driver, cross_origin: true)
68
+ analyze.results
60
69
  ```
61
70
 
62
- This gem comes packaged with the latest axe™ version at release. If you want to change this, specify the JS library you want to use:
71
+ This gem comes packaged with the latest axe™ version at release. If you want to change this,
72
+ specify the JS library you want to use:
63
73
  ```ruby
64
74
  driver = Selenium::WebDriver.for :chrome
65
- js_lib = File.read("path/to/axe.min.js"))
66
- Sa11y::Analyze(driver, js_lib: js_lib)
75
+ Sa11y::Analyze(driver, js_lib: File.read("path/to/axe.min.js"))
76
+ analyze.results
67
77
  ```
68
78
 
69
79
  ## Development
data/lib/sa11y/analyze.rb CHANGED
@@ -5,42 +5,51 @@ require "selenium-webdriver"
5
5
  module Sa11y
6
6
  # Analyzes Current Webpage with axe™ Accessibility Tool from Deque
7
7
  class Analyze
8
- attr_accessor :js_lib, :iframes
8
+ attr_accessor :js_lib, :frames, :cross_origin
9
9
 
10
10
  # https://github.com/dequelabs/axe-core-maven-html/blob/61447b/src/main/java/com/deque/html/axecore/selenium/
11
11
  # AxeBuilder.java#L83-L95
12
12
  # Copyright (C) 2020 Deque Systems Inc.,
13
- AXE_RESULTS = <<~AXE
13
+ AXE_RUN_SCRIPT = <<~AXE
14
14
  var callback = arguments[arguments.length - 1];var context = typeof arguments[0] === 'string' ?
15
15
  JSON.parse(arguments[0]) : arguments[0];context = context || document;
16
16
  var options = JSON.parse(arguments[1]);axe.run(context, options,
17
17
  function (err, results) { { if (err) { throw new Error(err); } callback(results); }});
18
18
  AXE
19
19
 
20
- def initialize(driver, js_lib: nil)
20
+ # https://github.com/dequelabs/axe-core-maven-html/blob/61447b/src/main/java/com/deque/html/axecore/selenium/
21
+ # AxeBuilder.java#L97
22
+ # Copyright (C) 2020 Deque Systems Inc.,
23
+ IFRAME_ALLOWED_SCRIPT = "axe.configure({ allowedOrigins: ['<unsafe_all_origins>'] });"
24
+
25
+
26
+ def initialize(driver, js_lib: nil, frames: true, cross_origin: false)
21
27
  @driver = driver
22
28
  @js_lib = js_lib || File.read(File.expand_path("../scripts/axe.min.js", __dir__))
23
- @iframes = true
29
+ @frames = frames
30
+ @cross_origin = cross_origin
24
31
  end
25
32
 
26
33
  def results
27
- @driver.execute_script(@js_lib)
28
- if iframes
34
+ if @frames
29
35
  @driver.switch_to.default_content
30
36
  manage_frames
37
+ else
38
+ @driver.execute_script(@js_lib)
31
39
  end
32
- @driver.execute_async_script(AXE_RESULTS, nil, "{}")
40
+ @driver.execute_async_script(AXE_RUN_SCRIPT, nil, "{}")
33
41
  end
34
42
 
35
43
  private
36
44
 
37
45
  def manage_frames
38
- frames = @driver.find_elements(tag_name: "iframe")
39
- return if frames.empty?
46
+ @driver.execute_script(@js_lib)
47
+ @driver.execute_script(IFRAME_ALLOWED_SCRIPT) if @cross_origin
48
+
49
+ frame_elements = @driver.find_elements(xpath: ".//*[local-name()='frame' or local-name()='iframe']")
40
50
 
41
- frames.each do |frame|
51
+ frame_elements.each do |frame|
42
52
  @driver.switch_to.frame(frame)
43
- @driver.execute_script(js_lib)
44
53
  manage_frames
45
54
  @driver.switch_to.parent_frame
46
55
  end
data/lib/sa11y/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sa11y
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sa11y
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - titusfortner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-24 00:00:00.000000000 Z
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 3.2.11
107
+ rubygems_version: 3.0.3
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: The Selenium Accessibility Gem