Module: LocatorStore::ClassMethods

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

Defined Under Namespace

Classes: BadLocatorParamsError, LocatorNotSpecifiedError

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



85
86
87
# File 'lib/howitzer/utils/locator_store.rb', line 85

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



71
72
73
# File 'lib/howitzer/utils/locator_store.rb', line 71

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



57
58
59
# File 'lib/howitzer/utils/locator_store.rb', line 57

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



43
44
45
# File 'lib/howitzer/utils/locator_store.rb', line 43

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



147
148
149
# File 'lib/howitzer/utils/locator_store.rb', line 147

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



133
134
135
# File 'lib/howitzer/utils/locator_store.rb', line 133

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



121
122
123
# File 'lib/howitzer/utils/locator_store.rb', line 121

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

#find_element(name) ⇒ Object



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

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

Take link locator from LocatorStore by name

Parameters:

  • name - Locator name



109
110
111
# File 'lib/howitzer/utils/locator_store.rb', line 109

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



97
98
99
# File 'lib/howitzer/utils/locator_store.rb', line 97

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