locatine 0.02710 → 0.02878

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
  SHA256:
3
- metadata.gz: 56487180200c449f68c037e000f60aa54165623f2fa8ccfab887d8756c7e848c
4
- data.tar.gz: 8cc1c4a8edffdc0bab1dc2ca4f32038f106412a3bc4864d11547bc27ddcf091e
3
+ metadata.gz: 457cb5d21eae999673da17f8c5c200181755f846946e81c81d9a23bbafa85528
4
+ data.tar.gz: f3ae98ffc268889f4781126b71106ffc99c29c73f9cd4e8321743388fb56bf70
5
5
  SHA512:
6
- metadata.gz: edb0be42a2a0b1d624a53975cf0ace45688df57b20b8e75bfaf6eca1c1adf992a64848b94ef984517ca8de8f14856c6795738b0ef14c4b5928727b11b91da595
7
- data.tar.gz: e20848ead9b6346734b19062568d70025d579f314773fed3ee66c2104732c83c30dce86f1b0e0101df51b5831ffbae4fa79b5b048ee9688f17416bc8a84486e8
6
+ metadata.gz: ed6f3ad8a5e29ea3b3e672b5a5cbd006571fa9536821dbc0b1467b005cf0998efc19425ba17f166a608cf84b5a884908c1d718275dbbebd0a56372a85f10d988
7
+ data.tar.gz: a7e5b86fe05b8710fd5bbd675733937dab017f8c27d8e27e4dbd5865da9313211775877c931a56c36414e0f1a3d94d3c66365a511f543daad4022fb00be91b14
data/README.md CHANGED
@@ -14,7 +14,7 @@ That's it.
14
14
 
15
15
  ## Stage of development:
16
16
 
17
- Version of Locatine is **0.02710**. The 3rd version since rewriting. 10-15 next versions is dedicated to bug fixing, tweaking.
17
+ Version of Locatine is **0.02878**. The 4th version since rewriting. 5-15 next versions is dedicated to bug fixing, tweaking.
18
18
 
19
19
  ## Attention
20
20
 
@@ -367,9 +367,7 @@ element = driver.find_element(css: "/*important input*/")
367
367
 
368
368
  Locatine will try to find it by those two words. If the id is really uniq it will return the desired element.
369
369
 
370
- Right now there is a Locatine Naming App that is in pending review status in the Chrome extension shop. This app is for creating good locatine locators.
371
-
372
- If you wanna try it before it is published - code is in the app folder of this repository.
370
+ There is a [Locatine Name Helper chrome extension](https://chrome.google.com/webstore/detail/locatine-locator-helper/heeoaalghiamfjphdlieoblmodpcficg). This app is for creating good locatine locators (it is creating a pair - most uniq attribute value + tag for selected element, elements). Note that the app is an early draft. It's gonne be better with time.
373
371
 
374
372
  **NOTE! Locatine locators case insensitive.**
375
373
 
@@ -13,3 +13,4 @@ require 'locatine/daemon'
13
13
  require 'locatine/session'
14
14
  require 'locatine/element'
15
15
  require 'locatine/results'
16
+ require 'locatine/error'
@@ -34,10 +34,18 @@ module Locatine
34
34
  { result: result }.to_json
35
35
  end
36
36
 
37
+ def send_error(error)
38
+ status error.status
39
+
40
+ error.answer
41
+ end
42
+
37
43
  # selenium calls
38
44
  post '/wd/hub/session/*/element' do
39
45
  content_type settings.headers['Content-Type']
40
46
  results = settings.sessions[session_id].find(params, element_id)
47
+ return send_error(results.first) if results.first.class == Locatine::Error
48
+
41
49
  status 200
42
50
  results.empty? ? raise_not_found : { value: results.first.answer }.to_json
43
51
  end
@@ -45,6 +53,8 @@ module Locatine
45
53
  post '/wd/hub/session/*/elements' do
46
54
  content_type settings.headers['Content-Type']
47
55
  results = settings.sessions[session_id].find(params, element_id)
56
+ return send_error(results.first) if results.first.class == Locatine::Error
57
+
48
58
  status 200
49
59
  answer = results.empty? ? [] : results.map(&:answer)
50
60
  { value: answer }.to_json
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Locatine
4
+ #
5
+ # Simple error
6
+ class Error
7
+ attr_accessor :answer, :status
8
+
9
+ def initialize(response)
10
+ @answer = response.body
11
+ @status = response.code
12
+ end
13
+ end
14
+ end
@@ -58,5 +58,12 @@ module Locatine
58
58
  "\n\n ---Answer was: #{answer}"
59
59
  raise answer['error']
60
60
  end
61
+
62
+ def warn_error_detected(answer)
63
+ warn "selenium is returning an error with code #{answer.code} "\
64
+ 'It will be returned to your code. It can be locatine internal '\
65
+ 'bug, selenium problem (dead browser for example) or something '\
66
+ 'in your code (invalid locator for example)'
67
+ end
61
68
  end
62
69
  end
@@ -22,8 +22,12 @@ module Locatine
22
22
 
23
23
  def simple_find
24
24
  path = @parent ? "/element/#{@parent}/elements" : '/elements'
25
- selenium_found = @session.api_request(path, 'Post', @locator.to_json).body
26
- JSON.parse(selenium_found)['value'].each do |item|
25
+ response = @session.api_request(path, 'Post', @locator.to_json)
26
+ found = JSON.parse(response.body)
27
+ error_present = (found['value'].class == Hash) && found['value']['error']
28
+ return error_routine(response) if error_present
29
+
30
+ found['value'].each do |item|
27
31
  push Locatine::Element.new(@session, item)
28
32
  end
29
33
  self
@@ -33,9 +37,15 @@ module Locatine
33
37
  # {"element-6066-11e4
34
38
  end
35
39
 
40
+ def error_routine(answer)
41
+ @error = Locatine::Error.new(answer)
42
+ warn_error_detected(answer)
43
+ push @error
44
+ end
45
+
36
46
  def classic_find
37
47
  first_attempt
38
- locating = @locator['value'].empty? || tolerance.positive?
48
+ locating = (@locator['value'].empty? || tolerance.positive?) && !@error
39
49
  return unless locating
40
50
 
41
51
  second_attempt
@@ -72,9 +72,12 @@ module Locatine
72
72
 
73
73
  def normalize_indexes(indexes = Thread.current['out'])
74
74
  list = all_elements
75
- return warn_unstable_page if list != @everything
75
+ warn_unstable_page if list != @everything
76
+ max_list = max_indexes(indexes)
77
+ old_answers = max_list.map { |index| @everything[index.to_i] }
78
+ answers = max_list.map { |index| list[index.to_i] }
79
+ return if old_answers != answers
76
80
 
77
- answers = max_indexes(indexes).map { |index| list[index.to_i] }
78
81
  answers.each do |item|
79
82
  push Locatine::Element.new(@session, item)
80
83
  end
@@ -50,4 +50,5 @@ function walk(target) {
50
50
  }
51
51
  const everything = Array.prototype.slice.call( document.getElementsByTagName("*") );
52
52
  let result = walk(document.body);
53
- return [result];
53
+ // We need to incapsulate since chromedriver cannot return a giant object
54
+ return JSON.stringify({"result": [result]});
@@ -49,12 +49,7 @@ module Locatine
49
49
  end
50
50
 
51
51
  def find(params, parent = nil)
52
- results = Results.new
53
- results.configure(self, params, parent)
54
- answer = results.find
55
- @elements[results.name] = results.info unless answer.empty?
56
- write unless answer.empty?
57
- answer
52
+ find_routine(params, parent)
58
53
  rescue RuntimeError => e
59
54
  raise e.message unless e.message == 'stale element reference'
60
55
 
@@ -62,6 +57,17 @@ module Locatine
62
57
  find(params, parent)
63
58
  end
64
59
 
60
+ def find_routine(params, parent)
61
+ results = Results.new
62
+ results.configure(self, params, parent)
63
+ answer = results.find
64
+ if !answer.empty? && answer.first.class != Locatine::Error
65
+ @elements[results.name] = results.info
66
+ write
67
+ end
68
+ answer
69
+ end
70
+
65
71
  def execute_script(script, *args)
66
72
  args.map! { |item| item.class == Locatine::Element ? item.answer : item }
67
73
  response = api_request('/execute/sync', 'Post',
@@ -74,7 +80,10 @@ module Locatine
74
80
  end
75
81
 
76
82
  def page
77
- execute_script(File.read("#{HOME}/scripts/page.js"))
83
+ # We need duplicated JSON parse since standart
84
+ # chromedriver giving an error here if the page is too large
85
+ page = execute_script(File.read("#{HOME}/scripts/page.js"))
86
+ JSON.parse(page, max_nesting: false)['result']
78
87
  end
79
88
 
80
89
  def call_uri(path)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Locatine
4
4
  # constants here...
5
- VERSION = '0.02710'
5
+ VERSION = '0.02878'
6
6
  NAME = 'locatine'
7
7
  HOME = if File.readable?("#{Dir.pwd}/lib/#{Locatine::NAME}")
8
8
  "#{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.02710'
4
+ version: '0.02878'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Seleznev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-05 00:00:00.000000000 Z
11
+ date: 2020-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,6 +141,7 @@ files:
141
141
  - lib/locatine/daemon.rb
142
142
  - lib/locatine/daemon_helpers/methods.rb
143
143
  - lib/locatine/element.rb
144
+ - lib/locatine/error.rb
144
145
  - lib/locatine/logger.rb
145
146
  - lib/locatine/results.rb
146
147
  - lib/locatine/results_helpers/common.rb