locatine 0.00463 → 0.00506
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locatine/search.rb +22 -7
- data/lib/locatine/version.rb +1 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a068a134bc0e30eb40d642214352c806cf81fed
|
4
|
+
data.tar.gz: 4b666c9a61e5f2d0e48e559d3559a71493ae3a4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 648e56d5ce390bf5b08a1da6631d5b9dfaf51f356fea9b7ffd0759cd8108332cd513d4a0e90d6ae78cd6f4abf73e5d20375b0de3c3a87b82ebc909d723c4140a
|
7
|
+
data.tar.gz: 4d92abdb0b900b2fb456bcd230564bd051b0ca8e15c08f198a7eb3ecb0409f0a76a122068ef272b3db642486977d79dccac5802a8f84e451998b9b81e790e4c5
|
data/lib/locatine/search.rb
CHANGED
@@ -9,20 +9,25 @@ module Locatine
|
|
9
9
|
##
|
10
10
|
# Search is the main class of the Locatine
|
11
11
|
#
|
12
|
-
# Locatine can
|
12
|
+
# Locatine can search.
|
13
13
|
class Search
|
14
14
|
|
15
15
|
attr_accessor :data, :depth, :browser, :learn, :json, :stability_limit, :scope
|
16
16
|
|
17
17
|
##
|
18
|
-
# Creates a new instance of
|
18
|
+
# Creates a new instance of Search
|
19
19
|
#
|
20
20
|
# Params:
|
21
21
|
# +json+ is the name of file to store//read data. Default => "./Locatine_files/default.json"
|
22
|
+
#
|
22
23
|
# +depth+ is the value that shows how many data will be stored for element.
|
24
|
+
#
|
23
25
|
# +browser+ is the instance of Watir::Browser. Unless provided it gonna be created with locatine-app onboard.
|
26
|
+
#
|
24
27
|
# +learn+ shows will locatine ask for assistance from user or will fail on error. learn is true when LEARN parameter is set in environment.
|
28
|
+
#
|
25
29
|
# +stability_limit+ shows max times attribute should be present to consider it trusted.
|
30
|
+
#
|
26
31
|
# +scope+ will be used in search (if not provided) defaulkt is "Default"
|
27
32
|
def initialize(json: "./Locatine_files/default.json",
|
28
33
|
depth: 3,
|
@@ -49,12 +54,19 @@ module Locatine
|
|
49
54
|
# Looking for the element
|
50
55
|
#
|
51
56
|
# Params:
|
57
|
+
#
|
52
58
|
# +scope+ is a parameter that is used to get information about the element from @data. Default is "Default"
|
59
|
+
#
|
53
60
|
# +name+ is a parameter that is used to get information about the element from @data. Must not be nil.
|
61
|
+
#
|
54
62
|
# +exact+ if true locatine will be forced to use only basic search. Default is false
|
63
|
+
#
|
55
64
|
# +locator+ if not empty it is used for the first attempt to find the element. Default is {}
|
65
|
+
#
|
56
66
|
# +vars+ hash of variables that will be used for dynamic attributes. See readme for example
|
67
|
+
#
|
57
68
|
# +look_in+ only elements of that kind will be used. Use Watir::Browser methods returning collections (:text_fields, :links, :divs, etc.)
|
69
|
+
#
|
58
70
|
# +iframe+ if provided locatine will look for elements inside of it
|
59
71
|
def find(simple_name = nil, name: nil, scope: nil, exact: false, locator: {}, vars: {}, look_in: nil, iframe: nil, return_locator: false)
|
60
72
|
name ||= simple_name
|
@@ -82,7 +94,7 @@ module Locatine
|
|
82
94
|
end
|
83
95
|
|
84
96
|
##
|
85
|
-
# Find alias with return_locator enforced
|
97
|
+
# Find alias with return_locator option enforced
|
86
98
|
def lctr(*args)
|
87
99
|
if args.last.class == Hash
|
88
100
|
args.last[:return_locator] = true
|
@@ -160,7 +172,8 @@ module Locatine
|
|
160
172
|
end
|
161
173
|
|
162
174
|
def get_trusted(array)
|
163
|
-
|
175
|
+
max_stability = (array.max_by {|i| i["stability"].to_i})["stability"].to_i
|
176
|
+
return (array.select {|i| i["stability"].to_i == max_stability}).uniq
|
164
177
|
end
|
165
178
|
|
166
179
|
def generate_xpath(data, vars)
|
@@ -216,7 +229,8 @@ module Locatine
|
|
216
229
|
@cold_time = timeout
|
217
230
|
raise RuntimeError, "Locatine is unable to find element #{name} in #{scope}" if all.length == 0
|
218
231
|
# Something esoteric here :)
|
219
|
-
|
232
|
+
max = all.count(all.max_by {|i| all.count(i)})
|
233
|
+
suggestion = (all.select {|i| all.count(i) == max}).uniq
|
220
234
|
attributes = generate_data(suggestion, vars)
|
221
235
|
return suggestion, attributes
|
222
236
|
end
|
@@ -293,7 +307,8 @@ module Locatine
|
|
293
307
|
all = all + find_by_locator({xpath: "//*[@*[contains(., '#{part}')]]"}).to_a
|
294
308
|
end
|
295
309
|
if all.length>0
|
296
|
-
|
310
|
+
max = all.count(all.max_by {|i| all.count(i)})
|
311
|
+
guess = (all.select {|i| all.count(i) == max}).uniq
|
297
312
|
guess_data = generate_data(guess, vars)
|
298
313
|
if (engine.elements.length/find_by_data(guess_data, vars).length <=4)
|
299
314
|
puts "Locatine has no good guess for #{name} in #{scope}. Try to change the name. Or just define it."
|
@@ -315,7 +330,7 @@ module Locatine
|
|
315
330
|
if !element.nil?
|
316
331
|
attributes = generate_data(element, vars)
|
317
332
|
else
|
318
|
-
element, attributes = find_by_guess(scope, name, vars)
|
333
|
+
element, attributes = find_by_guess(scope, name, vars) if name.length >= 5
|
319
334
|
end
|
320
335
|
while !finished do
|
321
336
|
sleep 0.1
|
data/lib/locatine/version.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
module Locatine
|
2
2
|
# constants here...
|
3
|
-
|
4
|
-
versions = []
|
5
|
-
1000.times do
|
6
|
-
versions.push generator.rand.round(5)
|
7
|
-
end
|
8
|
-
ITERATION = 0
|
9
|
-
VERSION = versions.sort[ITERATION].to_s
|
3
|
+
VERSION = "0.00506"
|
10
4
|
NAME = "locatine"
|
11
5
|
HOME = File.readable?("#{Dir.pwd}/lib/#{Locatine::NAME}")? "#{Dir.pwd}/lib/#{Locatine::NAME}" : "#{Gem.dir}/gems/#{Locatine::NAME}-#{Locatine::VERSION}/lib/#{Locatine::NAME}"
|
12
6
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locatine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.00506'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei Seleznev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|