Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: frenchroasted/ada_matcher
base: d6d1c151a5
...
head fork: frenchroasted/ada_matcher
compare: 6dbeccb3df
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
127 README.md
@@ -0,0 +1,127 @@
+ADA Matcher
+===========
+
+An RSpec add-on to help test for ADA compliance in web pages
+
+The [RSpec][rspecLink] library supports the addition of custom Matchers for
+use in Specifications. This Matcher, when used in a [Cucumber][cucumberLink]
+project, can check the HTML code of a page for some common web accessibility
+problems.
+
+What this code can do
+---------------------
+The Matcher will scan HTML and evaluate these ADA/accessibility points:
+* Image tags should include alt text (see Notes below)
+
+* Link tags should include explanatory titles
+
+* Links which cause new windows to open should say so (see Notes below)
+
+* Header tags should be used in proper hierarchy (a page with an H3 should have H1 and H2)
+
+* Form fields should have associated Label tags (see Notes below)
+
+What this code does not do
+--------------------------
+It will not guarantee fully ADA compliant web pages. It only scans for the tedious
+and easily forgotten small things that web developers should be in the habit of
+including in their web pages.
+
+Notes
+-----
+Full ADA compliance requires a large amount of subjective judgement, testing, and
+common sense. No automatic processor can fully grasp the usability of a particular
+layout and organization of semantic elements on a web page. The
+[quick reference guide to web accessibility][adaQuickRefLink]
+is pages and pages long and is filled with exceptions and special circumstances. For
+example:
+
+* Images which are purely decorative and carry no significant meaning for the reader
+ [should have empty alt attributes][noAltLink] (`alt = ""`). This is to avoid cluttering up the page
+ with needless descriptions of decorative pictures.
+
+* Links should warn about opening new windows, but a link may do so in a non-obvious
+ way via javascript. This Matcher makes no attempt to evaluate `onClick` and so on. It
+ only looks for a "target" attribute in the "a" tag and evaluates the text in the "title"
+ attribute.
+
+* Form fields should have Labels, but in [some cases][noLabelLink] with restricted space on the page,
+ a label can be skipped in lieu of an explanatory "title" attribute in the form field.
+
+When does a form field require a label and when not? When is an image merely decorative?
+This Matcher cannot make these judgements. That is the job of the humans writing the code.
+Likewise, humans must evaluate the page to see that the visual layout is readable to those
+users who cannot see text and other visual elements with a low contrast against the background.
+Or that the page, when stripped entirely of its visual styles and images, still reads in
+a sensible and meaningful way.
+
+Usage
+-----
+The ADA Matcher requires some page or browser object with an API like that of the [Watir web
+automator][watirLink]. Other similar libraries like [Watir-WebDriver][watirWebDriverLink],
+[Selenium][seleniumLink], and [Celerity][celerityLink]
+should work since their top-level APIs match Watir.
+
+This Matcher works most easily in a Cucumber project. The example below is for such a case.
+
+In a page definition, add:
+
+ require 'ada_matcher'
+
+In a step definition file, add something like:
+
+ Then /^the page is ADA compliant$/ do
+ @browser.should meet_ada_requirements
+ end
+
+In a feature file, you can use a scenario like:
+
+ Scenario: The page should meet ADA requirements
+ Given I am on The Page
+ Then the page is ADA compliant
+
+The page and step definition code is best placed in a "global" page/step
+file that all other page/step files inherit. This will make it clear that
+the ADA check is available to any feature page in the Cucumber project.
+
+More usage
+----------
+The execution of the matcher (`@browser.should meet_ada_requirements`) has
+some optional arguments:
+
+* (empty argument set) = run all ADA checks
+
+* `meet_ada_requirements(:all)` = run all ADA checks
+
+* `meet_ada_requirements(:some_specific_test_name])` = run just one ADA check
+
+* `meet_ada_requirements([:one_test, :another_test, :a_third_test])` = run several specific checks
+
+The supported ADA tests are:
+
+* `:image_alt`
+
+* `:link_title`
+
+* `:link_window_warning`
+
+* `:htag_hierarchy`
+
+* `:label_for`
+
+Finally, the Matcher runs on a "browser" object, but if the object supplied to the
+matcher is some other object, it will search for a "browser" property or method to
+get at the underlying browser object. This allows the Matcher to seamlessly support
+WatirPageHelper page objects, for example, like:
+
+`page.should meet_ada_requirements`.
+
+[rspecLink]: http://rspec.info/
+[cucumberLink]: http://cukes.info/
+[watirLink]: http://watir.com/
+[watirWebDriverLink]: http://watirwebdriver.com/
+[seleniumLink]: http://seleniumhq.org/
+[celerityLink]: http://celerity.rubyforge.org/
+[adaQuickRefLink]: http://www.w3.org/WAI/WCAG20/quickref/
+[noLabelLink]: http://www.w3.org/TR/2012/NOTE-WCAG20-TECHS-20120103/H65
+[noAltLink]: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#text-equiv
View
2  ada_matcher.gemspec
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
s.version = AdaMatcher::VERSION
s.authors = ["Aaron Brown"]
s.email = ["aaron@thebrownproject.com"]
- s.homepage = ""
+ s.homepage = "https://github.com/frenchroasted/ada_matcher"
s.summary = %q{Adds custom rspec matchers that test watir Page objects for ADA compliance}
s.description = %q{Adds custom rspec matchers that test watir Page objects for ADA compliance}
s.license = 'MIT'
View
15 lib/ada_matcher.rb
@@ -84,7 +84,8 @@ def parse_args(args)
def image_alt(page)
e = Array.new
page.images.each do |img|
- e << "Image tag is missing 'alt' attribute: #{img.html}" if img.alt.empty?
+ # alt="" is okay - image may be merely decorative.
+ e << "Image tag is missing 'alt' attribute: #{img.html}" unless (img.html =~ /\s+alt\s*=\s*([\'\"])\1/ || !img.alt.empty?)
end
e # return error message array
end
@@ -130,10 +131,14 @@ def label_for(page)
end
(page.text_fields.to_a + page.checkboxes.to_a + page.file_fields.to_a + page.radios.to_a + page.select_lists.to_a).each do |fld|
- if fld.id.nil? || fld.id.to_s.empty?
- e << "Form field without an ID or a corresponding Label: #{fld.html}"
- else
- e << "Form field without a corresponding Label: #{fld.html}" unless fors.has_key? fld.id.to_s.to_sym
+ # Form field with title does not necessarily require a Label
+ # http://www.w3.org/TR/2012/NOTE-WCAG20-TECHS-20120103/H65
+ if fld.title.empty?
+ if (fld.id.nil? || fld.id.to_s.empty?)
+ e << "Form field without an ID, a corresponding Label, or a Title: #{fld.html}"
+ else
+ e << "Form field without a corresponding Label or a Title: #{fld.html}" unless fors.has_key? fld.id.to_s.to_sym
+ end
end
end
View
2  lib/ada_matcher/version.rb
@@ -1,3 +1,3 @@
module AdaMatcher
- VERSION = "0.1.0"
+ VERSION = "0.1.1"
end
View
3  resources/good_page.html
@@ -31,8 +31,7 @@
<option value="1">1</option>
<option value="2">2</option>
</select> <br/>
- <label for="radioInput1">radioInput1</label>
- <input type="radio" id="radioInput1" name="radioInput"/> <br/>
+ <input type="radio" id="radioInput1" name="radioInput" title="I don't need a label"/> <br/>
<label for="radioInput2">radioInput2</label>
<input type="radio" id="radioInput2" name="radioInput"/> <br/>
</form>

No commit comments for this range

Something went wrong with that request. Please try again.