module PageObjectPal::Elements
Public Instance Methods
dsl_to_html(anchor)
click to toggle source
Convert non-HTML anchor_tags from the PageObject::DSL to HTML.
# File lib/page-object-pal/elements.rb, line 56 def dsl_to_html(anchor) case anchor when "image" then :img when "link" then :a when "list_item" then :li when "ordered_list" then :ol when "paragraph" then :p when "radio_button" then :radio when "text_area" then :input when "text_field" then :input when "unordered_list" then :ul else anchor.to_sym end end
element_tag(string)
click to toggle source
Convert method defining string for PageObject::Accessors#element method.
# File lib/page-object-pal/elements.rb, line 37 def element_tag(string) tag = string[/,:(\w+)/].gsub(",:","") sym = string[/:class|:id|:index|:text|:xpath/].gsub(":","").to_sym (sym == :index) ? val = string[/\d+/] : val = string[/"(.+)"/].gsub("\"","") { tag => { sym => val } } end
html_to_dsl(anchor)
click to toggle source
Convert HTML to PageObject::DSL where the two are not identical.
# File lib/page-object-pal/elements.rb, line 74 def html_to_dsl(anchor) case anchor when :img then "image" when :a then "link" when :li then "list_item" when :ol then "ordered_list" when :p then "paragraph" when :radio then "radio_button" when :input then "text_field/text_area" when :ul then "unordered_list" else anchor.to_s end end
parse_element(string)
click to toggle source
Convert method defining string to hash containing anchor_tag, identifying_property, and property_value.
# File lib/page-object-pal/elements.rb, line 24 def parse_element(string) string.gsub!(/(,\s+)/, ",") tag = dsl_to_html(string[/^(\w+)/]) case tag when :element then element_tag(string) else standard_tag(tag, string) end end
parse_methods(methods, path)
click to toggle source
Find lines in the page object class file that define the non-super instance methods.
# File lib/page-object-pal/elements.rb, line 8 def parse_methods(methods, path) elements = [] methods.each do |meth| File.open(path).read.each_line do |line| next unless line.include? meth.to_s next unless line.lstrip.start_with? "div", "element", "image", "link", "list_item", "ordered_list", "paragraph", "radio_button", "span", "text_area", "text_field", "unordered_list" elements << parse_element(line.lstrip) end end elements end
standard_tag(tag, string)
click to toggle source
Convert method defining string for standard PageObject::Accessors methods.
# File lib/page-object-pal/elements.rb, line 47 def standard_tag(tag, string) sym = string[/:class|:id|:index|:text|:xpath/].gsub(":","").to_sym (sym == :index) ? val = string[/\d+/] : val = string[/"(.+)"/].gsub("\"","") { tag => { sym => val } } end