Module: Locatine::ForSearch::Public

Included in:
Search
Defined in:
lib/locatine/for_search/public.rb

Overview

Public methods of the Search class

Instance Method Summary collapse

Instance Method Details

#browser=(value) ⇒ Object



134
135
136
# File 'lib/locatine/for_search/public.rb', line 134

def browser=(value)
  import_browser(value)
end

#check(*args) ⇒ Object

Find alias with zero tolerance option enforced



156
157
158
# File 'lib/locatine/for_search/public.rb', line 156

def check(*args)
  enforce({ tolerance: 0 }, *args)
end

#check_collection(*args) ⇒ Object

Collection alias with zero tolerance option enforced



162
163
164
# File 'lib/locatine/for_search/public.rb', line 162

def check_collection(*args)
  enforce({ tolerance: 0, collection: true }, *args)
end

#collect(*args) ⇒ Object

Find alias with collection option enforced



126
127
128
# File 'lib/locatine/for_search/public.rb', line 126

def collect(*args)
  enforce({ collection: true }, *args)
end

#exact(*args) ⇒ Object

Find alias with exact option on



174
175
176
# File 'lib/locatine/for_search/public.rb', line 174

def exact(*args)
  enforce({ exact: true }, *args)
end

#exact_collection(*args) ⇒ Object

Collection alias with exact option on



168
169
170
# File 'lib/locatine/for_search/public.rb', line 168

def exact_collection(*args)
  enforce({ exact: true, collection: true }, *args)
end

#find(simple_name = nil, name: nil, scope: nil, exact: false, locator: {}, vars: {}, look_in: nil, iframe: nil, return_locator: false, collection: false, tolerance: nil, no_fail: nil, trusted: nil, untrusted: nil) ⇒ Object

Looking for the element

Params:

scope is a parameter that is used to get information about the element from @data. Default is “Default”

name is a parameter that is used to get information about the element from @data. Must not be nil.

exact if true locatine will be forced to use only basic search. Default is false

locator if not empty it is used for the first attempt to find the element. Default is {}

vars hash of variables that will be used for dynamic attributes. See readme for example

look_in only elements of that kind will be used. Use Watir::Browser methods returning collections (:text_fields, :links, :divs, etc.)

iframe if provided locatine will look for elements inside of it

return_locator is to return a valid locator of the result

collection when true an array will be returned. When false - a single element

tolerance It is possible to set a custom tolerance for every find. See examples in README

no_fail if true locatine is not producing errors on element loss.

trusted array of names of attributes and element params to use in search always.

untrusted array of names of attributes and element params to use in search never.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/locatine/for_search/public.rb', line 93

def find(simple_name = nil,
         name: nil,
         scope: nil,
         exact: false,
         locator: {},
         vars: {},
         look_in: nil,
         iframe: nil,
         return_locator: false,
         collection: false,
         tolerance: nil,
         no_fail: nil,
         trusted: nil,
         untrusted: nil)
  name = set_name(simple_name, name)
  set_env_for_search(look_in, iframe, tolerance,
                     no_fail, trusted, untrusted)
  scope ||= @scope.nil? ? 'Default' : @scope
  result, attributes = full_search(name, scope, vars, locator, exact)
  return { xpath: generate_xpath(attributes, vars) } if result &&
                                                        return_locator

  to_subtype(result, collection)
end

#get_scope(name: 'Default', vars: {}) ⇒ Object

Returns an instance of the Scope class. Starts define if learn == true

Params:

name is a parameter that stores name of the scope. Default is “Default”

vars is a hash which will be used to generate dynamic attributes. See readme for explanation.



148
149
150
151
152
# File 'lib/locatine/for_search/public.rb', line 148

def get_scope(name: 'Default', vars: {})
  answer = Scope.new(name, self)
  answer.define(vars) if @learn
  answer
end

#initialize(config = {}) ⇒ Object

Creates a new instance of Search

Params:

json is the name of file to store//read data. Default => “./Locatine_files/default.json”

depth shows how many data will be stored for element.

browser is the instance of Watir::Browser. Unless provided it gonna be created with locatine-app onboard.

learn shows will locatine ask for assistance from user or will fail on error. learn is true when LEARN parameter is set in environment.

stability_limit shows max times attribute should be present and checked to consider it trusted.

scope will be used in search (if not provided) defaulkt is “Default”

tolerance Shows how similar must be an element found as alternative to the lost one. Default is 67 which means that if less than 33% of metrics of alternative elements are the same as of the lost element will not be returned

visual_search locatine will use position and style if true

no_fail if true locatine is not producing errors on element loss.

trusted array of names of attributes and element params to use in search always.

untrusted array of names of attributes and element params to use in search never.

autolearn determines will locatine study an element or not. true means locatine will always study it (slow). false means it won’t study it unless it was lost and found. If not stated locatine will turn set it true if at least one element was lost.



46
47
48
49
50
51
# File 'lib/locatine/for_search/public.rb', line 46

def initialize(config = {})
  init_config = default_init_config.merge(config)
  import_browser init_config.delete :browser
  import_file init_config.delete :json
  import_config init_config
end

#json=(value) ⇒ Object



130
131
132
# File 'lib/locatine/for_search/public.rb', line 130

def json=(value)
  import_file(value)
end

#lctr(*args) ⇒ Object

Find alias with return_locator option enforced



120
121
122
# File 'lib/locatine/for_search/public.rb', line 120

def lctr(*args)
  enforce({ return_locator: true }, *args)
end