Module: PageObject::LocatorGenerator

Defined in:
lib/page-object/locator_generator.rb

Constant Summary collapse

BASIC_ELEMENTS =
[:abbr,
:address,
:article,
:as,
:aside,
:bdi,
:bdo,
:blockquote,
:body,
:br,
:caption,
:cite,
:code,
:col,
:colgroup,
:command,
:data,
:datalist,
:dd,
:del,
:details,
:dfn,
:dialog,
:dl,
:dt,
:em,
:embed,
:fieldset,
:figcaption,
:figure,
:footer,
:head,
:header,
:hgroup,
:hr,
:ins,
:kbd,
:keygen,
:legend,
:map,
:mark,
:menu,
:meta,
:meter,
:nav,
:noscript,
:object,
:optgroup,
:output,
:param,
:pre,
:progress,
:rp,
:rt,
:ruby,
:samp,
:section,
:small,
:strong,
:style,
:sub,
:summary,
:sup,
:time,
:title,
:track,
:var,
:wbr]
ADVANCED_ELEMENTS =
[:text_field,
:hidden_field,
:text_area,
:select_list,
:link,
:checkbox,
:radio_button,
:button,
:div,
:span,
:table,
:cell,
:row,
:image,
:form,
:list_item,
:ordered_list,
:unordered_list,
:h1,
:h2,
:h3,
:h4,
:h5,
:h6,
:paragraph,
:label,
:file_field,
:area,
:canvas,
:audio,
:video,
:b,
:svg]

Class Method Summary collapse

Class Method Details

.generate_locators(target) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/page-object/locator_generator.rb', line 108

def self.generate_locators(target)
  ADVANCED_ELEMENTS.each do |tag|
    target.send(:define_method, "#{tag.to_s}_element") do |*identifier|
      @platform.send "#{tag.to_s}_for", locator(identifier)
    end

    target.send(:define_method, "#{tag.to_s}_elements") do |*identifier|
      @platform.send("#{tag.to_s}s_for", identifier[0] ? identifier[0] : {})
    end
  end

  BASIC_ELEMENTS.each do |tag|
    target.send(:define_method, "#{tag.to_s}_element") do |*identifier|
      @platform.send :element_for, tag, locator(identifier)
    end

    target.send(:define_method, "#{tag.to_s}_elements") do |*identifier|
      @platform.send(:elements_for, tag, identifier[0] ? identifier[0] : {})
    end
  end
end