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 +4 -4
- data/README.md +17 -7
- data/lib/sa11y/analyze.rb +20 -11
- data/lib/sa11y/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e457e53b58f1040f0598cbe44bb84ed5a6ec6c98768bdc0c5b0488037df96b6b
|
4
|
+
data.tar.gz: 60c7e99dd8574dce7988d23bdb3c4973455ad9993a60414d8d1a28ef2e689bef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.
|
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,
|
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
|
66
|
-
|
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, :
|
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
|
-
|
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
|
-
|
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
|
-
@
|
29
|
+
@frames = frames
|
30
|
+
@cross_origin = cross_origin
|
24
31
|
end
|
25
32
|
|
26
33
|
def results
|
27
|
-
@
|
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(
|
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
|
-
|
39
|
-
|
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
|
-
|
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
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.
|
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-
|
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.
|
107
|
+
rubygems_version: 3.0.3
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: The Selenium Accessibility Gem
|