locatine 0.01100 → 0.01135

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ca422d8fbe87acacb5b19639d98c509fbdb04a2
4
- data.tar.gz: b81058cdc3aa26f76a5521312de44f11f5b299bd
3
+ metadata.gz: f3cb2cbc141c7d5c0961539de0d404445f6b5f61
4
+ data.tar.gz: 7597435001651d14154b8e0ccfc584491e26aafa
5
5
  SHA512:
6
- metadata.gz: f3435a0ae9f55f95e2419d47f37e066c9af65c4cc630b222229a5057aec35060a4a3d24504a5bb1eed21bee6c2c59611b692eb14dec12a945648da1f75bb8fd0
7
- data.tar.gz: 96236870dffc079e8fa474b8fab27d5276c57ddbb1655ff0b8edf598a7eea1e45476e8cfb41b27e6feb16fc992c0f66bca6f80a84afdfe45df623ae75f9b9cc2
6
+ metadata.gz: 58f225f496d12d9e9e7a517c96ea72365fe86cd699b969ad5a8d21c9d2578e9cfb11e992676b72f6309679c39dca22a76ced8a2f6b3b46881258419b4f593a17
7
+ data.tar.gz: e0715af3063fd55346c94649feb8d3a02b26382c9c02b6797fe070ab91cb3b04afde97f23f81abadc60758e45fd481c38755e35b3c79afbf540f1743a4e3f909
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Locatine app",
3
- "version": "0.01100",
3
+ "version": "0.01135",
4
4
  "description": "Messaging from browser to main app",
5
5
  "devtools_page": "devtools.html",
6
6
  "permissions": ["activeTab", "storage", "contextMenus", "tabs"],
@@ -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 = '/*' * depth.to_i
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 = '/*' * depth.to_i
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 = '/*' * depth.to_i
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
 
@@ -11,24 +11,34 @@ module Locatine
11
11
  name
12
12
  end
13
13
 
14
- def core_search(result, name, scope, vars, exact)
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 = find_by_data(@data[scope][name], vars)
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
 
@@ -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 &&
@@ -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/xpath_generator'
12
- require 'locatine/find_by_locator'
13
- require 'locatine/find_by_magic'
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
@@ -1,6 +1,6 @@
1
1
  module Locatine
2
2
  # constants here...
3
- VERSION = '0.01100'.freeze
3
+ VERSION = '0.01135'.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.01100'
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-08 00:00:00.000000000 Z
11
+ date: 2019-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler