locatine 0.01454 → 0.01546

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f4b5920958d23beb5f982dbf21031b415be3ee2
4
- data.tar.gz: 6845db3f39092cdfb16e041dcbf30137cb061cff
3
+ metadata.gz: 8a4b678e1915017d1898771afe9cd2b737051b62
4
+ data.tar.gz: 8adbe3846eecb369e49483a1aa2e08b291dddf6c
5
5
  SHA512:
6
- metadata.gz: 66bdbebd614dd0e0bc629437b8373ac030b428153c4c76bf85b05f31c213e9a25d184fb9df8bf6925da5b87e34ff776e5efa518f600fed468f53ae6deed26745
7
- data.tar.gz: 8102bbf0e52b8dac143953a548dc36e9cf8b500baf31f818e2b2959f210ba6d8d3b0e062d6646fb1e8632cb815a465e386ffb9e96979ccf99f430634babc290c
6
+ metadata.gz: f79005a1036bbe968439219a2b3c90ec183b95d4ae7990cebdee2aa9065186a93dcb96c592dd5dd894a1b1f633eb20d9e5ee604206c8c6ef88296eb2a936a531
7
+ data.tar.gz: 53b87536a961b56ec9b82a2762812dfd151b7454b716eb108137f97fa8d71e751fca8c564c6da414c0f8d68c5784a69d0c2d4853e9a477d2b248a7b9f5497560
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Locatine app",
3
- "version": "0.01454",
3
+ "version": "0.01546",
4
4
  "description": "Messaging from browser to main app",
5
5
  "devtools_page": "devtools.html",
6
6
  "permissions": ["activeTab", "storage", "contextMenus", "tabs"],
@@ -87,9 +87,9 @@ module Locatine
87
87
  attributes.each_pair do |name, value|
88
88
  next if name.to_s == 'locatineclass'
89
89
 
90
- value.split(/['" ]/).uniq.each do |part|
90
+ value.split(/['" ]/).reject(&:empty?).uniq.each do |part|
91
91
  array.push('name' => name.to_s, 'type' => 'attribute',
92
- 'value' => part) unless part.empty?
92
+ 'value' => part)
93
93
  end
94
94
  end
95
95
  array
@@ -22,7 +22,7 @@ module Locatine
22
22
  results = engine.send(method, locator)
23
23
  return correct_method_detected(results) if collection?(results.class)
24
24
 
25
- return acceptable_method_detected(results, method, locator)
25
+ acceptable_method_detected(results, method, locator)
26
26
  end
27
27
 
28
28
  def correct_method_detected(results)
@@ -6,29 +6,39 @@ module Locatine
6
6
 
7
7
  ##
8
8
  # Getting all the elements via black magic
9
- def find_by_magic(name, scope, data, vars)
9
+ def find_by_magic(name, scope, data, vars, exact)
10
10
  warn "#{name} in #{scope} is lost. Looking for it."
11
11
  @cold_time = 0
12
12
  all = all_options(data, vars)
13
13
  @cold_time = nil
14
- raise "Unable to find element #{name} in #{scope}" if all.empty?
14
+ raise "Unable to find element #{name} in #{scope}" if all.empty? && !exact
15
15
 
16
- suggest_by_all(all, data, vars, name, scope)
16
+ suggest_by_all(all, data, vars, name, scope, exact)
17
17
  end
18
18
 
19
19
  def similar_enough(data, attributes)
20
- (same_entries(data['0'], attributes, '0').length * 100 /
21
- data['0'].length) >= @tolerance
20
+ same = same_entries(data['0'], attributes, '0').length
21
+ all = data['0'].length
22
+ sameness = (same * 100) / all
23
+ sameness >= 100 - @current_t
22
24
  end
23
25
 
24
- def suggest_by_all(all, data, vars, name, scope)
26
+ def best_of_all(all, vars)
25
27
  max = all.count(all.max_by { |i| all.count(i) })
26
- suggestion = (all.select { |i| all.count(i) == max }).uniq
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
28
+ suggest = (all.select { |i| all.count(i) == max }).uniq unless max.zero?
29
+ attributes = generate_data(suggest, vars) unless suggest.nil?
30
+ return suggest, attributes
31
+ end
32
+
33
+ def suggest_by_all(all, data, vars, name, scope, exact)
34
+ suggest, attributes = best_of_all(all, vars)
35
+ ok = similar_enough(data, attributes) unless suggest.nil?
36
+ spawn = !ok && !exact
37
+ raise "Unable to find element similar to #{name} in #{scope}" if spawn
38
+
39
+ return suggest, attributes if ok
30
40
 
31
- return suggestion, attributes
41
+ return nil, nil
32
42
  end
33
43
 
34
44
  def all_options(data, vars)
@@ -44,8 +54,8 @@ module Locatine
44
54
  end
45
55
 
46
56
  def min_max_by_size(middle, size)
47
- min = middle - (size.to_i * (100 + @tolerance)) / 200
48
- max = middle + (size.to_i * (100 + @tolerance)) / 200
57
+ min = middle - (size.to_i * (200 - @current_t)) / 200
58
+ max = middle + (size.to_i * (200 - @current_t)) / 200
49
59
  return min, max
50
60
  end
51
61
 
@@ -16,7 +16,7 @@ module Locatine
16
16
  attributes.each_pair do |_depth, array|
17
17
  s.push array.max_by { |item| item['stability'].to_i }['stability'].to_i
18
18
  end
19
- s.max > 1
19
+ s.max >= @stability_limit
20
20
  end
21
21
 
22
22
  def data_search(name, scope, vars, exact)
@@ -24,7 +24,7 @@ module Locatine
24
24
  attributes = generate_data(result, vars) if result
25
25
  if !result && (!exact || !stable?(@data[scope][name]))
26
26
  result, attributes = find_by_magic(name, scope,
27
- @data[scope][name], vars)
27
+ @data[scope][name], vars, exact)
28
28
  end
29
29
  return result, attributes
30
30
  end
@@ -37,15 +37,21 @@ module Locatine
37
37
  end
38
38
 
39
39
  def full_search(name, scope, vars, locator, exact)
40
- result, attributes = locator_search(locator, vars)
41
- result, attributes = core_search(name, scope, vars, exact) unless result
42
- result, attributes = ask(scope, name, result, vars) if @learn
40
+ result, attributes = search_steps(name, scope, vars, locator, exact)
43
41
  raise "Nothing was found for #{scope} #{name}" if !result && !exact
44
42
 
45
43
  store(attributes, scope, name) if result
46
44
  return result, attributes
47
45
  end
48
46
 
47
+ def search_steps(name, scope, vars, locator, exact)
48
+ result, attributes = locator_search(locator, vars)
49
+ ok = result || ((locator != {}) && exact)
50
+ result, attributes = core_search(name, scope, vars, exact) unless ok
51
+ result, attributes = ask(scope, name, result, vars) if @learn
52
+ return result, attributes
53
+ end
54
+
49
55
  def locator_search(locator, vars)
50
56
  result = find_by_locator(locator) if locator != {}
51
57
  attributes = generate_data(result, vars) if result
@@ -19,6 +19,12 @@ module Locatine
19
19
  (@iframe || @browser)
20
20
  end
21
21
 
22
+ def set_env_for_search(look_in, iframe, tolerance)
23
+ @type = look_in
24
+ @iframe = iframe
25
+ @current_t = tolerance || @tolerance
26
+ end
27
+
22
28
  def not_magic_div
23
29
  "[not(@id = 'locatine_magic_div')]"
24
30
  end
@@ -30,9 +30,9 @@ module Locatine
30
30
  depth: 3,
31
31
  browser: nil,
32
32
  learn: ENV['LEARN'].nil? ? false : true,
33
- stability_limit: 10,
33
+ stability_limit: 1000,
34
34
  scope: 'Default',
35
- tolerance: 33,
35
+ tolerance: 67,
36
36
  visual_search: false)
37
37
  import_browser browser
38
38
  import_file(json)
@@ -85,9 +85,7 @@ module Locatine
85
85
  collection: false,
86
86
  tolerance: nil)
87
87
  name = set_name(simple_name, name)
88
- @type = look_in
89
- @iframe = iframe
90
- @tolerance ||= tolerance
88
+ set_env_for_search(look_in, iframe, tolerance)
91
89
  scope ||= @scope.nil? ? 'Default' : @scope
92
90
  result, attributes = full_search(name, scope, vars, locator, exact)
93
91
  return { xpath: generate_xpath(attributes, vars) } if result &&
@@ -1,6 +1,6 @@
1
1
  module Locatine
2
2
  # constants here...
3
- VERSION = '0.01454'.freeze
3
+ VERSION = '0.01546'.freeze
4
4
  NAME = 'locatine'.freeze
5
5
  HOME = if File.readable?("#{Dir.pwd}/lib/#{Locatine::NAME}")
6
6
  "#{Dir.pwd}/lib/#{Locatine::NAME}"
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.01454'
4
+ version: '0.01546'
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-22 00:00:00.000000000 Z
11
+ date: 2019-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler