Module: PageObjectPal::Diff

Includes:
Elements
Included in:
PageObjectPal
Defined in:
lib/page-object-pal/diff.rb

Instance Method Summary collapse

Methods included from Elements

#dsl_to_html, #element_tag, #html_to_dsl, #parse_element, #parse_methods, #standard_tag

Instance Method Details

#diff_page(source, elements) ⇒ Object

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



12
13
14
15
16
17
18
# 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) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/page-object-pal/diff.rb', line 46

def failure?(match)
  match.to_a.empty?
end

#scrub_source(tag, identifier, source) ⇒ Object

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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 PageObjectOutdated, "Could not identify '#{html_to_dsl(tag)}' where :#{prop} == '#{prop_val}'" if failure? match
  end
end