module PageObjectPal::Diff

Public Instance Methods

diff_page(source, elements) click to toggle source

Find page object defined methods that do not match code in the source HTML.

# File lib/page-object-pal/diff.rb, line 12
def diff_page(source, elements)
  elements.each do |e_hash|
    e_hash.each do |elem, identifier|
      scrub_source(elem, identifier, source)
    end
  end
end
failure?(match) click to toggle source
# File lib/page-object-pal/diff.rb, line 46
def failure?(match)
  match.to_a.empty?
end
scrub_source(tag, identifier, source) click to toggle source

Look for code in the source HTML matching the identifying code defined in the page object class.

# File lib/page-object-pal/diff.rb, line 24
def scrub_source(tag, identifier, source)
  identifier.each do |prop, prop_val|
    match = case prop
    when :class
      source.css("#{tag.to_s}.#{prop_val}")
    when :id
      source.css("#{tag.to_s}##{prop_val}")
    when :index
      source.css("#{tag.to_s}")[prop_val.to_i]
    when :text
      source.search("[text()*='#{prop_val}']")
    when :xpath
      source.xpath(prop_val)
    else
      raise SupportError, "PageObjectPal doesn't support elements identified by '#{prop}'... yet. Consider ", 
        "forking the project at http://github.com/jdenen/page-object-pal."
    end

    raise PageObjectInvalid, "Could not identify '#{html_to_dsl(tag)}' where :#{prop} == '#{prop_val}'" if failure? match
  end
end