locatine 0.01100 → 0.01135
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locatine/app/manifest.json +1 -1
- data/lib/locatine/find_by_locator.rb +3 -3
- data/lib/locatine/find_by_magic.rb +12 -0
- data/lib/locatine/find_logic.rb +21 -11
- data/lib/locatine/public.rb +6 -2
- data/lib/locatine/search.rb +9 -8
- data/lib/locatine/version.rb +1 -1
- 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: f3cb2cbc141c7d5c0961539de0d404445f6b5f61
|
4
|
+
data.tar.gz: 7597435001651d14154b8e0ccfc584491e26aafa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58f225f496d12d9e9e7a517c96ea72365fe86cd699b969ad5a8d21c9d2578e9cfb11e992676b72f6309679c39dca22a76ced8a2f6b3b46881258419b4f593a17
|
7
|
+
data.tar.gz: e0715af3063fd55346c94649feb8d3a02b26382c9c02b6797fe070ab91cb3b04afde97f23f81abadc60758e45fd481c38755e35b3c79afbf540f1743a4e3f909
|
@@ -63,7 +63,7 @@ module Locatine
|
|
63
63
|
##
|
64
64
|
# Getting elements by tag
|
65
65
|
def find_by_tag(hash, vars, depth = 0)
|
66
|
-
correction = '
|
66
|
+
correction = '//*' if depth.to_i > 0
|
67
67
|
xpath = "//*[self::#{process_string(hash['value'], vars)}]"
|
68
68
|
find_by_locator(xpath: "#{xpath}#{correction}#{not_magic_div}")
|
69
69
|
end
|
@@ -71,7 +71,7 @@ module Locatine
|
|
71
71
|
##
|
72
72
|
# Getting elements by text
|
73
73
|
def find_by_text(hash, vars, depth = 0)
|
74
|
-
correction = '
|
74
|
+
correction = '//*' if depth.to_i > 0
|
75
75
|
xpath = "//*[contains(text(), '#{process_string(hash['value'], vars)}')]"
|
76
76
|
find_by_locator(xpath: "#{xpath}#{correction}#{not_magic_div}")
|
77
77
|
end
|
@@ -79,7 +79,7 @@ module Locatine
|
|
79
79
|
##
|
80
80
|
# Getting elements by attribute
|
81
81
|
def find_by_attribute(hash, vars, depth = 0)
|
82
|
-
correction = '
|
82
|
+
correction = '//*' if depth.to_i > 0
|
83
83
|
full_part = '//*[@*'
|
84
84
|
hash['name'].split('_').each do |part|
|
85
85
|
full_part += "[contains(name(), '#{part}')]"
|
@@ -13,9 +13,21 @@ module Locatine
|
|
13
13
|
@cold_time = nil
|
14
14
|
raise "Unable to find element #{name} in #{scope}" if all.empty?
|
15
15
|
|
16
|
+
suggest_by_all(all, data, vars, name, scope)
|
17
|
+
end
|
18
|
+
|
19
|
+
def similar_enough(data, attributes)
|
20
|
+
(same_entries(data['0'], attributes, '0').length * 100 /
|
21
|
+
data['0'].length) > @tolerance
|
22
|
+
end
|
23
|
+
|
24
|
+
def suggest_by_all(all, data, vars, name, scope)
|
16
25
|
max = all.count(all.max_by { |i| all.count(i) })
|
17
26
|
suggestion = (all.select { |i| all.count(i) == max }).uniq
|
18
27
|
attributes = generate_data(suggestion, vars)
|
28
|
+
ok = similar_enough(data, attributes)
|
29
|
+
raise "Unable to find element similar to #{name} in #{scope}" unless ok
|
30
|
+
|
19
31
|
return suggestion, attributes
|
20
32
|
end
|
21
33
|
|
data/lib/locatine/find_logic.rb
CHANGED
@@ -11,24 +11,34 @@ module Locatine
|
|
11
11
|
name
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def stable?(attributes)
|
15
|
+
s = []
|
16
|
+
attributes.each_pair do |_depth, array|
|
17
|
+
s.push array.max_by { |item| item['stability'].to_i }['stability'].to_i
|
18
|
+
end
|
19
|
+
s.max > 1
|
20
|
+
end
|
21
|
+
|
22
|
+
def data_search(name, scope, vars, exact)
|
23
|
+
result = find_by_data(@data[scope][name], vars)
|
24
|
+
attributes = generate_data(result, vars) if result
|
25
|
+
if !result && (!exact || !stable?(@data[scope][name]))
|
26
|
+
result, attributes = find_by_magic(name, scope,
|
27
|
+
@data[scope][name], vars)
|
28
|
+
end
|
29
|
+
return result, attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
def core_search(name, scope, vars, exact)
|
15
33
|
if @data[scope][name].to_h != {}
|
16
|
-
result =
|
17
|
-
attributes = generate_data(result, vars) if result
|
18
|
-
if !result && !exact
|
19
|
-
result, attributes = find_by_magic(name, scope,
|
20
|
-
@data[scope][name], vars)
|
21
|
-
end
|
34
|
+
result, attributes = data_search(name, scope, vars, exact)
|
22
35
|
end
|
23
36
|
return result, attributes
|
24
37
|
end
|
25
38
|
|
26
39
|
def full_search(name, scope, vars, locator, exact)
|
27
40
|
result, attributes = locator_search(locator, vars)
|
28
|
-
unless result
|
29
|
-
result, attributes = core_search(result, name, scope,
|
30
|
-
vars, exact)
|
31
|
-
end
|
41
|
+
result, attributes = core_search(name, scope, vars, exact) unless result
|
32
42
|
result, attributes = ask(scope, name, result, vars) if @learn
|
33
43
|
raise "Nothing was found for #{scope} #{name}" if !result && !exact
|
34
44
|
|
data/lib/locatine/public.rb
CHANGED
@@ -26,7 +26,8 @@ module Locatine
|
|
26
26
|
browser: nil,
|
27
27
|
learn: ENV['LEARN'].nil? ? false : true,
|
28
28
|
stability_limit: 10,
|
29
|
-
scope: 'Default'
|
29
|
+
scope: 'Default',
|
30
|
+
tolerance: 15)
|
30
31
|
browser ||= right_browser
|
31
32
|
@browser = browser
|
32
33
|
@json = json
|
@@ -37,6 +38,7 @@ module Locatine
|
|
37
38
|
@learn = learn
|
38
39
|
@stability_limit = stability_limit
|
39
40
|
@scope = scope
|
41
|
+
@tolerance = tolerance
|
40
42
|
end
|
41
43
|
|
42
44
|
##
|
@@ -77,10 +79,12 @@ module Locatine
|
|
77
79
|
look_in: nil,
|
78
80
|
iframe: nil,
|
79
81
|
return_locator: false,
|
80
|
-
collection: false
|
82
|
+
collection: false,
|
83
|
+
tolerance: nil)
|
81
84
|
name = set_name(simple_name, name)
|
82
85
|
@type = look_in
|
83
86
|
@iframe = iframe
|
87
|
+
@tolerance ||= tolerance
|
84
88
|
scope ||= @scope.nil? ? 'Default' : @scope
|
85
89
|
result, attributes = full_search(name, scope, vars, locator, exact)
|
86
90
|
return { xpath: generate_xpath(attributes, vars) } if result &&
|
data/lib/locatine/search.rb
CHANGED
@@ -4,19 +4,19 @@ require 'fileutils'
|
|
4
4
|
require 'chromedriver-helper'
|
5
5
|
|
6
6
|
# Internal requires
|
7
|
+
require 'locatine/merge'
|
7
8
|
require 'locatine/public'
|
8
|
-
require 'locatine/find_logic'
|
9
|
-
require 'locatine/file_work'
|
10
9
|
require 'locatine/helpers'
|
11
|
-
require 'locatine/
|
12
|
-
require 'locatine/
|
13
|
-
require 'locatine/
|
10
|
+
require 'locatine/file_work'
|
11
|
+
require 'locatine/highlight'
|
12
|
+
require 'locatine/find_logic'
|
14
13
|
require 'locatine/dialog_logic'
|
14
|
+
require 'locatine/find_by_magic'
|
15
15
|
require 'locatine/find_by_guess'
|
16
|
-
require 'locatine/highlight'
|
17
16
|
require 'locatine/data_generate'
|
18
|
-
require 'locatine/merge'
|
19
17
|
require 'locatine/dialog_actions'
|
18
|
+
require 'locatine/xpath_generator'
|
19
|
+
require 'locatine/find_by_locator'
|
20
20
|
|
21
21
|
module Locatine
|
22
22
|
##
|
@@ -44,6 +44,7 @@ module Locatine
|
|
44
44
|
:learn,
|
45
45
|
:json,
|
46
46
|
:stability_limit,
|
47
|
-
:scope
|
47
|
+
:scope,
|
48
|
+
:tolerance
|
48
49
|
end
|
49
50
|
end
|
data/lib/locatine/version.rb
CHANGED
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.01135'
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|