Module: LocatorStore::ClassMethods

Defined in:
lib/howitzer/utils/locator_store.rb

Constant Summary collapse

LOCATOR_TYPES =
[:base, :link, :field, :button]

Instance Method Summary collapse

Instance Method Details

#add_button_locator(name, params) ⇒ Object

Add locator for button into LocatorStore. Button can be found by: id, name, value Capybara methods that can work with this locator type are: click_button, find_button

Parameters:

  • name - Locator name

  • params - Name, ID or value


83
84
85
# File 'lib/howitzer/utils/locator_store.rb', line 83

def add_button_locator(name, params)
  add_locator_by_type(:button, name, params)
end

#add_field_locator(name, params) ⇒ Object

Adds locator for field into LocatorStore. Field can be found by: name, id, text Capybara methods that can work with this locator type are: find_field, fill_in

Parameters:

  • name - Locator name

  • params - Name, ID or text of field


69
70
71
# File 'lib/howitzer/utils/locator_store.rb', line 69

def add_field_locator(name, params)
  add_locator_by_type(:field, name, params)
end

Adds locator for link into LocatorStore. Link can be found by: id, text Capybara methods that can work with this locator type are: click_link, find_link

Parameters:

  • name - Locator name

  • params - ID or text of link


55
56
57
# File 'lib/howitzer/utils/locator_store.rb', line 55

def add_link_locator(name, params)
  add_locator_by_type(:link, name, params)
end

#add_locator(name, params) ⇒ Object

Adds css or xpath locator into LocatorStore. Also locator can be set by lambda expression. For example: lambda{|name|{xpath: “.//a”}}

Parameters:

  • name - Locator name

  • params - String for css locator or hash with :xpath key and string value for xpath locator


41
42
43
# File 'lib/howitzer/utils/locator_store.rb', line 41

def add_locator(name, params)
  add_locator_by_type(:base, name, params)
end

#apply(locator, *values) ⇒ Object

Get locator set by lambda. For example: find(apply(locator(:locator_name), 'register')).click

Parameters:

  • locator - Locator set with lambda expression

  • values - Arguments that should be matched lambda expression params


145
146
147
# File 'lib/howitzer/utils/locator_store.rb', line 145

def apply(locator, *values)
  locator.call(*values).to_a.flatten
end

#button_locator(name) ⇒ Object

Take button locator from LocatorStore be name

Parameters:

  • name - Locator name


131
132
133
# File 'lib/howitzer/utils/locator_store.rb', line 131

def button_locator(name)
  locator_by_type(:button, name)
end

#field_locator(name) ⇒ Object

Take field locator from LocatorStore by name

Parameters:

  • name - Locator name


119
120
121
# File 'lib/howitzer/utils/locator_store.rb', line 119

def field_locator(name)
  locator_by_type(:field, name)
end

#find_element(name) ⇒ Object


149
150
151
152
153
154
155
156
# File 'lib/howitzer/utils/locator_store.rb', line 149

def find_element(name)
  type, locator = find_locator(name)
  if type == :base
    send :find, locator
  else
    send "find_#{type}", locator
  end
end

#first_element(name) ⇒ Object


158
159
160
161
162
163
164
165
# File 'lib/howitzer/utils/locator_store.rb', line 158

def first_element(name)
  type, locator = find_locator(name)
  if type == :base
    send :first, locator
  else
    send :first, type, locator
  end
end

Take link locator from LocatorStore by name

Parameters:

  • name - Locator name


107
108
109
# File 'lib/howitzer/utils/locator_store.rb', line 107

def link_locator(name)
  locator_by_type(:link, name)
end

#locator(name) ⇒ Object

Takes css or xpath locator from LocatorStore by name

Parameters:

  • name - Locator name


95
96
97
# File 'lib/howitzer/utils/locator_store.rb', line 95

def locator(name)
  locator_by_type(:base, name)
end