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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ec7ffd6c0a45544ae5cbd20581f72190bbfa3ee5dd2c5e444740c1d03d7ba04
4
- data.tar.gz: 7552e77cfc41106c4679a99554980f67ad4decc354348ee0d01479c9799687fa
3
+ metadata.gz: b992087a77664cfe04949ab6bb1f343edb0c03801bcc118ac21631c4455463f3
4
+ data.tar.gz: b0d586f4c4de1c38a84eee4d1f9e434a3d8136d4ae25e83367dc573a5ec67c76
5
5
  SHA512:
6
- metadata.gz: 6d42ad78b43ff2335357546b50daa98734e1d06527e26fc6608540135ffb73d4f1aebcf9b5e3fb44c74b3125a31045b3206a8ddabdc0c08211f28f71390fdc9f
7
- data.tar.gz: 2b752ff4e3a7b60ae8eb12f585eef9df6445f3c659169e7470bcfbc18f848938762815a8a977ce4825be250f527a425b0c2ff1b96d52240db4223e9d1d8a201e
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.03050**. The 4th version since rewriting. 5-15 next versions is dedicated to bug fixing, tweaking.
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
 
@@ -12,9 +12,11 @@ module Locatine
12
12
  ##
13
13
  # Init method
14
14
  #
15
- # +session+ is a Locatine::Session instance
16
- # +element_code+ is an element hash returned by selenium it is shaped like:
17
- # {"element-6066-11e4-a52e-4f735466cecf"=>"c95a0580-4ac7-4c6d-..."}
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'
@@ -21,23 +21,30 @@ module Locatine
21
21
  ##
22
22
  # Method to find elements
23
23
  #
24
- # +session+ instance of Locatine::Session
25
- # +locator+ can be a classic locator shaped for webdriver protocol like:
26
- # {'using => 'xpath', 'value' => '//div'} or
27
- # {'using' => 'css selector', 'value' => 'div'}
28
- # It also can be a locator with magic comment like
29
- # {'using' => 'css selector', 'value' => 'div/*magic comment*/'}
30
- # It also can be a locator with incapsulated json
31
- # {'using' => 'css selector', 'value' => 'div/*{"name": "magic comment"}*/'}
32
- # It can be a locatine locator
33
- # {'using' => 'locatine', 'value' => '{"name": "magic comment"}'} or
34
- # {'using' => 'locatine', 'value' => 'magic comment'
35
- # +parent+ is the parent element to look for the nested ones.
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
- timer
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)
@@ -3,7 +3,7 @@
3
3
  module Locatine
4
4
  module ResultsHelpers
5
5
  #
6
- # Trying to guess element here
6
+ # Trying to compare elements here
7
7
  module Comparing
8
8
  private
9
9
 
@@ -3,7 +3,7 @@
3
3
  module Locatine
4
4
  module ResultsHelpers
5
5
  #
6
- # Trying to guess element here
6
+ # Trying to configure results here
7
7
  module Config
8
8
  private
9
9
 
@@ -19,8 +19,8 @@ module Locatine
19
19
  def classic_thread
20
20
  Thread.new do
21
21
  while empty?
22
- sleep 0.5
23
22
  classic_find
23
+ sleep 1
24
24
  end
25
25
  end
26
26
  end
@@ -16,8 +16,8 @@ module Locatine
16
16
  ##
17
17
  # Init of the new session instance
18
18
  #
19
- # +selenium+ is a selenium address like "https://host:port"
20
- # +session+ is a session id provided by selenium
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
- # +params+ is a hash of settings like {json: "some", depth: 0...}
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
- # +params+ is a hash of settings like {json: "some", depth: 0...}
48
- # +parent+ is an element code of the element to look under. It is counted
49
- # only for the most simple search. If element is lost parent will be
50
- # ignored
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
- # Note this method will be not called when you are asking selenoum via
64
- # locatine to execute a script. This class is for internal use.
65
- # +script+ some valid js code
66
- # +*args+ arguments to be passed to script.
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
- # +path+ is a relative path to call on selenium like '/elements'
93
- # +method+ is an http method to perform ('Get', 'Post', etc.)
94
- # +body+ is for request data. json here (selenium wants it) or nil
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)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Locatine
4
4
  # constants here...
5
- VERSION = '0.03050'
5
+ VERSION = '0.03118'
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.03050'
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-10 00:00:00.000000000 Z
11
+ date: 2020-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler