locatine 0.02710 → 0.02878
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/lib/locatine.rb +1 -0
- data/lib/locatine/daemon.rb +10 -0
- data/lib/locatine/error.rb +14 -0
- data/lib/locatine/logger.rb +7 -0
- data/lib/locatine/results.rb +13 -3
- data/lib/locatine/results_helpers/find_by_magic.rb +5 -2
- data/lib/locatine/scripts/page.js +2 -1
- data/lib/locatine/session.rb +16 -7
- data/lib/locatine/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 457cb5d21eae999673da17f8c5c200181755f846946e81c81d9a23bbafa85528
|
4
|
+
data.tar.gz: f3ae98ffc268889f4781126b71106ffc99c29c73f9cd4e8321743388fb56bf70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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
|
|
data/lib/locatine.rb
CHANGED
data/lib/locatine/daemon.rb
CHANGED
@@ -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
|
data/lib/locatine/logger.rb
CHANGED
@@ -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
|
data/lib/locatine/results.rb
CHANGED
@@ -22,8 +22,12 @@ module Locatine
|
|
22
22
|
|
23
23
|
def simple_find
|
24
24
|
path = @parent ? "/element/#{@parent}/elements" : '/elements'
|
25
|
-
|
26
|
-
JSON.parse(
|
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
|
-
|
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
|
53
|
+
// We need to incapsulate since chromedriver cannot return a giant object
|
54
|
+
return JSON.stringify({"result": [result]});
|
data/lib/locatine/session.rb
CHANGED
@@ -49,12 +49,7 @@ module Locatine
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def find(params, parent = nil)
|
52
|
-
|
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
|
-
|
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)
|
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.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-
|
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
|