module AdaMatcher

Constants

VERSION

Public Instance Methods

get_page_browser(page) click to toggle source
# File lib/ada_matcher.rb, line 48
def get_page_browser(page)
  # "page" may be a browser object or, for example, a watir_page_helper object
  # with a "browser" object embedded within it. Find the nested browser object
  # and return it so we can continue in a consistent manner.
  return page.browser if page.respond_to?(:browser)
  return page.browser if page.instance_variable_defined?(:@browser)
  return page.browser if page.instance_variable_defined?(:browser)
  page
end
htag_hierarchy(page) click to toggle source

Currently, no method exists to collect all Heading tags (H1 - H6). We scan all tags on the page and evaluate their order for proper hierarchical sequencing.

# File lib/ada_matcher.rb, line 114
def htag_hierarchy(page)
  e = Array.new
  page_tags = page.elements.to_a.collect {|elem| elem.tag_name}

  last_htag_num = 0
  for i in 0..(page_tags.size - 1)
    if hMatch = /^h([1-6])$/.match(page_tags[i])
      headingIdx = hMatch[1].to_i
      if (last_htag_num > 0) && (headingIdx > (last_htag_num + 1))
        e << "H#{headingIdx} tag found, but prior Heading tag was H#{last_htag_num}."
      elsif headingIdx > (last_htag_num + 1)
        e << "H#{headingIdx} tag found, but no prior higher level Heading tag was found."
      else
        last_htag_num = headingIdx
      end
    end
  end

  e  # return error message array
end
image_alt(page) click to toggle source
# File lib/ada_matcher.rb, line 84
def image_alt(page)
  e = Array.new
  page.images.each do |img|
    # 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
is_browser?(browser) click to toggle source

We don’t care what kind of web driver gave us “page” as long as it responds to all the API calls we need

# File lib/ada_matcher.rb, line 60
def is_browser?(browser)
  browser.respond_to?(:images) && 
    browser.respond_to?(:links) && 
    browser.respond_to?(:h1s) &&
    browser.respond_to?(:h2s) &&
    browser.respond_to?(:h3s) &&
    browser.respond_to?(:h4s) &&
    browser.respond_to?(:labels) &&
    browser.respond_to?(:text_fields) &&
    browser.respond_to?(:checkboxes) &&
    browser.respond_to?(:file_fields) &&
    browser.respond_to?(:radios) &&
    browser.respond_to?(:select_lists)
end
label_for(page) click to toggle source
# File lib/ada_matcher.rb, line 135
def label_for(page)
  e = Array.new
  fors = {}
  page.labels.each do |label|
    fors[label.for.to_s.to_sym] = 1 unless label.for.nil? || label.for.empty?
  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|
    # 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

  e  # return error message array
end
parse_args(args) click to toggle source
# File lib/ada_matcher.rb, line 75
def parse_args(args)
  return [] if args.nil?
  if args.respond_to? :to_a
    args.to_a
  else
    [args]
  end
end