locatine 0.03050 → 0.03118
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 +4 -4
- data/README.md +1 -5
- data/lib/locatine/element.rb +5 -3
- data/lib/locatine/results.rb +31 -15
- data/lib/locatine/results_helpers/comparing.rb +1 -1
- data/lib/locatine/results_helpers/config.rb +1 -1
- data/lib/locatine/results_helpers/find_by_magic.rb +1 -1
- data/lib/locatine/session.rb +22 -14
- data/lib/locatine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b992087a77664cfe04949ab6bb1f343edb0c03801bcc118ac21631c4455463f3
|
|
4
|
+
data.tar.gz: b0d586f4c4de1c38a84eee4d1f9e434a3d8136d4ae25e83367dc573a5ec67c76
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59ae3ed8e6aa6ac27be09e3bcaeda8e4ce7968db40e8393efd0fe47aeb25be5770181c718555ed304a1938133e7c198b788e82adbf557acb1e451aa650d90d6e
|
|
7
|
+
data.tar.gz: b56c011bb15c36a1e42dd342f2cc0f09f21ad65835d3cdf457e20b915b18faaeb381bf3c9328b705e6b4a6ec613ebc17712e0cfead1de2e094905509bb50fbe8
|
data/README.md
CHANGED
|
@@ -14,11 +14,7 @@ That's it.
|
|
|
14
14
|
|
|
15
15
|
## Stage of development:
|
|
16
16
|
|
|
17
|
-
Version of Locatine is **0.
|
|
18
|
-
|
|
19
|
-
## Attention
|
|
20
|
-
|
|
21
|
-
This version of Locatine is not compatible to previous.
|
|
17
|
+
Version of Locatine is **0.03118**.
|
|
22
18
|
|
|
23
19
|
## Installation
|
|
24
20
|
|
data/lib/locatine/element.rb
CHANGED
|
@@ -12,9 +12,11 @@ module Locatine
|
|
|
12
12
|
##
|
|
13
13
|
# Init method
|
|
14
14
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
15
|
+
# @param session [Locatine::Session instance]
|
|
16
|
+
# @param element_code [Hash] is an element hash returned by selenium,
|
|
17
|
+
# it is shaped like:
|
|
18
|
+
#
|
|
19
|
+
# +{"element-6066-11e4-a52e-4f735466cecf"=>"c95a0580-4ac7-4c6d-..."}+
|
|
18
20
|
def initialize(session, element_code)
|
|
19
21
|
unless element_code
|
|
20
22
|
raise ArgumentError, 'Cannot init element with no element data'
|
data/lib/locatine/results.rb
CHANGED
|
@@ -21,23 +21,30 @@ module Locatine
|
|
|
21
21
|
##
|
|
22
22
|
# Method to find elements
|
|
23
23
|
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
24
|
+
# @param session [Locatine::Session]
|
|
25
|
+
# @param locator [Hash] can be a classic locator shaped for webdriver
|
|
26
|
+
# protocol like:
|
|
27
|
+
#
|
|
28
|
+
# +{'using => 'xpath', 'value' => '//div'}+ or
|
|
29
|
+
# +{'using' => 'css selector', 'value' => 'div'}+
|
|
30
|
+
#
|
|
31
|
+
# It also can be a locator with magic comment like:
|
|
32
|
+
#
|
|
33
|
+
# +{'using' => 'css selector', 'value' => 'div/*magic comment*/'}+
|
|
34
|
+
#
|
|
35
|
+
# It also can be a locator with incapsulated json
|
|
36
|
+
#
|
|
37
|
+
# +{'using' => 'css selector', 'value' => 'div/*{"name": "magic "}*/'}+
|
|
38
|
+
#
|
|
39
|
+
# It can be a locatine locator
|
|
40
|
+
#
|
|
41
|
+
# +{'using' => 'locatine', 'value' => '{"name": "magic comment"}'}+ or
|
|
42
|
+
# +{'using' => 'locatine', 'value' => 'magic comment'}+
|
|
43
|
+
# @param parent is the parent element to look for the nested ones.
|
|
44
|
+
# @return class instance populated by results or an empty array
|
|
36
45
|
def find(session, locator, parent)
|
|
37
46
|
configure(session, locator, parent)
|
|
38
|
-
|
|
39
|
-
classic_find
|
|
40
|
-
guess if name_only?
|
|
47
|
+
find_routine
|
|
41
48
|
return self unless empty?
|
|
42
49
|
|
|
43
50
|
find_by_magic if known && tolerance.positive?
|
|
@@ -56,6 +63,15 @@ module Locatine
|
|
|
56
63
|
|
|
57
64
|
private
|
|
58
65
|
|
|
66
|
+
def find_routine
|
|
67
|
+
timer
|
|
68
|
+
classic_find
|
|
69
|
+
guess if name_only?
|
|
70
|
+
return if first.class == Locatine::Error || empty?
|
|
71
|
+
|
|
72
|
+
log_found if name_only?
|
|
73
|
+
end
|
|
74
|
+
|
|
59
75
|
def simple_find
|
|
60
76
|
path = @parent ? "/element/#{@parent}/elements" : '/elements'
|
|
61
77
|
response = @session.api_request(path, 'Post', @locator.to_json)
|
data/lib/locatine/session.rb
CHANGED
|
@@ -16,8 +16,8 @@ module Locatine
|
|
|
16
16
|
##
|
|
17
17
|
# Init of the new session instance
|
|
18
18
|
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
19
|
+
# @param selenium [String] is a selenium address like +"https://host:port"+
|
|
20
|
+
# @param session [String] is a session id provided by selenium
|
|
21
21
|
def initialize(selenium, session)
|
|
22
22
|
@selenium = selenium
|
|
23
23
|
@parsed_selenium = URI.parse @selenium
|
|
@@ -31,7 +31,8 @@ module Locatine
|
|
|
31
31
|
##
|
|
32
32
|
# This method is to set settings
|
|
33
33
|
#
|
|
34
|
-
#
|
|
34
|
+
# @param params [Hash] is for settings like +{json: "some", depth: 0...}+
|
|
35
|
+
# @return params hash :)
|
|
35
36
|
def configure(params)
|
|
36
37
|
params.to_h.each_pair do |var, value|
|
|
37
38
|
instance_variable_set("@#{var}", value)
|
|
@@ -44,10 +45,13 @@ module Locatine
|
|
|
44
45
|
# Find method is for finding elements.
|
|
45
46
|
#
|
|
46
47
|
# That is the part that is replacing simple finding by selenium
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
48
|
+
# @param params [Hash] is for settings like +{json: "some", depth: 0...}+
|
|
49
|
+
# @param parent [String] is an element code of the element to look under.
|
|
50
|
+
# It is counted
|
|
51
|
+
# only for the most simple search. If element is lost parent will be
|
|
52
|
+
# ignored
|
|
53
|
+
# @return populated instance of Locatine::Results or an empty array
|
|
54
|
+
# or Locatine::Error
|
|
51
55
|
def find(params, parent = nil)
|
|
52
56
|
find_routine(params, parent)
|
|
53
57
|
rescue RuntimeError => e
|
|
@@ -60,10 +64,10 @@ module Locatine
|
|
|
60
64
|
##
|
|
61
65
|
# Session can execute js scripts on a page
|
|
62
66
|
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
+
# @note This method will be not called when you are asking selenum via
|
|
68
|
+
# locatine to execute a script. This method is for internal use only.
|
|
69
|
+
# @param script [String] some valid js code
|
|
70
|
+
# @param *args [Array] arguments to be passed to script.
|
|
67
71
|
def execute_script(script, *args)
|
|
68
72
|
args.map! { |item| item.class == Locatine::Element ? item.answer : item }
|
|
69
73
|
response = api_request('/execute/sync', 'Post',
|
|
@@ -89,9 +93,13 @@ module Locatine
|
|
|
89
93
|
#
|
|
90
94
|
# We are using it to ask for elements found by selenium or
|
|
91
95
|
# for script execution
|
|
92
|
-
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
96
|
+
# @param path [String] is a relative path to call on selenium like
|
|
97
|
+
# +'/elements'+
|
|
98
|
+
# @param method [String] is an http method to perform ( +'Get'+, +'Post'+,
|
|
99
|
+
# etc.)
|
|
100
|
+
# @param body [String] is for request data. Json here (selenium wants it)
|
|
101
|
+
# or nil
|
|
102
|
+
# @return result of call whatever it is
|
|
95
103
|
def api_request(path, method, body)
|
|
96
104
|
uri = call_uri(path)
|
|
97
105
|
req = Net::HTTP.const_get(method)
|
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.03118'
|
|
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-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|