locatine 0.02247 → 0.02327

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: 023773fde5af096ee6f8b04948dbeadcee35f3d2
4
- data.tar.gz: 2071bcae7bf758afc1196a82f04f74690931f9c0
3
+ metadata.gz: a584853859a41d1442f3037bef100dec0bb1d09e
4
+ data.tar.gz: 298cabc4969b4e454bb3d6bd9f5f2b5d091ff53c
5
5
  SHA512:
6
- metadata.gz: c3c8e5959c2fd4b850608ee0d998357c32ce9af253e6726c3077f6eafeeef4625a85fa0e5c70f10564d14c1d46756efe61a9823f4e68f2ac37dd5000d008d1bb
7
- data.tar.gz: 99f44eb1de8f7158f8b108edc971c2682322fc2fb60db7e2729da318a73729e21f1dece359616bdfd14e9703a8277b6372c968cac73725fd82e930a85d61fa80
6
+ metadata.gz: 4a317d9efb1aab542d551d90272ee912edb9b7ee36df13ad74292d1ac377848995d19a786104a5db89480f636bf14d77c3b3f1271d4b408732729d8f0498baa8
7
+ data.tar.gz: 99dbade69774c044b519d78e5c3ec3b0ba7469eb803e9cff80eee1fa3549bd566460ffaaf2c3c95e7a7817bd83c6dd2254101ef50666a76503a91a19a06b117f
data/README.md CHANGED
@@ -16,7 +16,7 @@ That's it.
16
16
 
17
17
  ## Stage of development:
18
18
 
19
- Version of Locatine is **0.02247** only. It means so far this is an alfa. You can use it in a real project if you are a risky person.
19
+ Version of Locatine is **0.02327** only. It means so far this is an alfa. You can use it in a real project if you are a risky person.
20
20
 
21
21
  ## Installation
22
22
 
@@ -96,7 +96,9 @@ Locatine::Search.new(json: "./Locatine_files/default.json",
96
96
  scope: "Default",
97
97
  tolerance: 33,
98
98
  visual_search: false,
99
- no_fail: false)
99
+ no_fail: false,
100
+ trusted: [],
101
+ untrusted: [])
100
102
  ```
101
103
 
102
104
  ### json
@@ -147,6 +149,12 @@ Be careful! Set true only if appearance of your page is pretty stable.
147
149
 
148
150
  When element is lost and no_fail is true you will get nil for single element and [] for collection. If no_fail is false (which is default) and locatine cannot find something you will face an error.
149
151
 
152
+ ### trusted/untrusted
153
+
154
+ If you are sure that some attribute (or something) is not good(generated by random, not uniq, etc.) you can forbid to use it in search. You can write attribute name, "text", "tag", or css attribute name (if you are using visual_search)
155
+
156
+ On the other hand you can force locatine to always trust something with trusted.
157
+
150
158
  ## Changing options on fly
151
159
 
152
160
  You can get or set these values on fly. Like:
@@ -170,7 +178,9 @@ s.find(name: "some name",
170
178
  return_locator: false,
171
179
  collection: false,
172
180
  tolerance: nil,
173
- no_fail: nil)
181
+ no_fail: nil,
182
+ trusted: [],
183
+ untrusted: [])
174
184
  ```
175
185
  ### name
176
186
 
@@ -257,6 +267,10 @@ It is disabling attempts to find element by advanced algorithms. If locator is p
257
267
 
258
268
  no_fail option that will work for that search only.
259
269
 
270
+ ### trusted//untrusted
271
+
272
+ You can set trusted elements just for search
273
+
260
274
  ## Scope
261
275
 
262
276
  If you want to define a whole bunch of elements at once you can do:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Locatine app",
3
- "version": "0.02247",
3
+ "version": "0.02327",
4
4
  "description": "Messaging from browser to main app",
5
5
  "devtools_page": "devtools.html",
6
6
  "permissions": ["activeTab", "storage", "contextMenus", "tabs"],
@@ -19,7 +19,7 @@ module Locatine
19
19
  return element, attrs
20
20
  end
21
21
 
22
- def negative_needed(element, vars, old_depth)
22
+ def negative_need(element, vars, old_depth)
23
23
  @depth = old_depth
24
24
  warn_no_negatives
25
25
  generate_data([element], vars).to_h
@@ -27,10 +27,10 @@ module Locatine
27
27
 
28
28
  def complex_attrs(element, vars, old_depth = @depth)
29
29
  attrs = get_family_info(element, vars).to_h
30
- return negative_needed(element, vars, old_depth) if attrs.length < @depth
30
+ return negative_need(element, vars, old_depth) if attrs.length < @depth
31
31
 
32
32
  if find_by_data(attrs, vars).length > 1
33
- @depth +=1
33
+ @depth += 1
34
34
  return complex_attrs(element, vars, old_depth)
35
35
  end
36
36
  @depth = old_depth
@@ -43,11 +43,18 @@ module Locatine
43
43
  final
44
44
  end
45
45
 
46
- def stability_bump(to_add, hash)
46
+ def stability_value(name, max, init = 0)
47
+ result = @trust_now.include?(name) ? max.to_s : (init.to_i + 1).to_s
48
+ result = '0' if @untrust_now.include?(name)
49
+ result
50
+ end
51
+
52
+ def stability_bump(to_add, hash, max)
47
53
  if to_add.empty? # new ones
48
- hash['stability'] = '1'
54
+ hash['stability'] = stability_value(hash['name'], max)
49
55
  elsif to_add[0]['stability'].to_i < @stability_limit # old ones
50
- to_add[0]['stability'] = (to_add[0]['stability'].to_i + 1).to_s
56
+ to_add[0]['stability'] = stability_value(to_add[0]['name'],
57
+ max, to_add[0]['stability'])
51
58
  end
52
59
  to_add.empty? ? [hash] : to_add
53
60
  end
@@ -26,11 +26,18 @@ module Locatine
26
26
  @iframe = @browser.iframe(@iframe.selector) if @iframe && @iframe.stale?
27
27
  end
28
28
 
29
- def set_env_for_search(look_in, iframe, tolerance, no_fail)
29
+ def set_env_for_search(look_in,
30
+ iframe,
31
+ tolerance,
32
+ no_fail,
33
+ trusted,
34
+ untrusted)
30
35
  @type = look_in
31
36
  @iframe = iframe
32
37
  @current_t = tolerance || @tolerance
33
38
  @current_no_f = no_fail || @no_fail
39
+ @trust_now = trusted || @trusted
40
+ @untrust_now = untrusted || @untrusted
34
41
  end
35
42
 
36
43
  def not_magic_div
@@ -18,7 +18,8 @@ module Locatine
18
18
  array.each do |hash|
19
19
  item = second[depth]
20
20
  to_add = item.nil? ? [] : select_same(second[depth], hash)
21
- to_add = stability_bump(to_add, hash) if stability_up
21
+ max = max_stability(second[depth]).to_i + 1
22
+ to_add = stability_bump(to_add, hash, max) if stability_up
22
23
  result += to_add
23
24
  end
24
25
  result
@@ -36,7 +36,9 @@ module Locatine
36
36
  scope: 'Default',
37
37
  tolerance: 67,
38
38
  visual_search: false,
39
- no_fail: false)
39
+ no_fail: false,
40
+ trusted: [],
41
+ untrusted: [])
40
42
  import_browser browser
41
43
  import_file(json)
42
44
  @depth = depth
@@ -46,6 +48,8 @@ module Locatine
46
48
  @tolerance = tolerance
47
49
  @visual_search = visual_search
48
50
  @no_fail = no_fail
51
+ @trusted = trusted
52
+ @untrusted = untrusted
49
53
  end
50
54
 
51
55
  ##
@@ -91,9 +95,12 @@ module Locatine
91
95
  return_locator: false,
92
96
  collection: false,
93
97
  tolerance: nil,
94
- no_fail: nil)
98
+ no_fail: nil,
99
+ trusted: nil,
100
+ untrusted: nil)
95
101
  name = set_name(simple_name, name)
96
- set_env_for_search(look_in, iframe, tolerance, no_fail)
102
+ set_env_for_search(look_in, iframe, tolerance,
103
+ no_fail, trusted, untrusted)
97
104
  scope ||= @scope.nil? ? 'Default' : @scope
98
105
  result, attributes = full_search(name, scope, vars, locator, exact)
99
106
  return { xpath: generate_xpath(attributes, vars) } if result &&
@@ -7,14 +7,20 @@ module Locatine
7
7
 
8
8
  def get_trusted(array)
9
9
  if !array.empty?
10
- max_stability = (array
11
- .max_by { |i| i['stability'].to_i })['stability']
12
- (array.select { |i| i['stability'].to_i == max_stability.to_i }).uniq
10
+ max = max_stability(array)
11
+ (array.select { |i| i['stability'].to_i == max.to_i }).uniq
13
12
  else
14
13
  []
15
14
  end
16
15
  end
17
16
 
17
+ def max_stability(array)
18
+ max = (array.max_by { |i| i['stability'].to_i })
19
+ return max['stability'] if max
20
+
21
+ return 0
22
+ end
23
+
18
24
  def generate_xpath(data, vars)
19
25
  xpath = "[not(@id = 'locatine_magic_div')]"
20
26
  data.each_pair do |_depth, array|
@@ -80,6 +80,7 @@ module Locatine
80
80
  item = @search.send(:ask, @scope, '', nil, vars)
81
81
  return find_all(vars) if item[:element].nil?
82
82
 
83
+ @search.send(:set_env_for_search, nil, nil, nil, nil, nil, nil)
83
84
  @search.send(:store, item[:attributes], @scope, item[:name])
84
85
  new_define(vars)
85
86
  end
@@ -55,7 +55,9 @@ module Locatine
55
55
  :scope,
56
56
  :tolerance,
57
57
  :visual_search,
58
- :no_fail
58
+ :no_fail,
59
+ :trusted,
60
+ :untrusted
59
61
  attr_reader :json,
60
62
  :browser
61
63
  end
@@ -1,6 +1,6 @@
1
1
  module Locatine
2
2
  # constants here...
3
- VERSION = '0.02247'.freeze
3
+ VERSION = '0.02327'.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.02247'
4
+ version: '0.02327'
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-05-06 00:00:00.000000000 Z
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler