locatine 0.02651 → 0.02653

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: 346a046dc0581334a4266d04cd1e67aa901173fee6b1d283ee9a5f2f6b65c847
4
- data.tar.gz: 4844bdbc771b339065af81425be655928d9212c55d15aab78639d777c7a17c53
3
+ metadata.gz: d99cd5d5712f3b8c2e5ee842d747cabe50389989ae74ee3cfa2e7c7c053459bb
4
+ data.tar.gz: 5887791f4997688df39acfab6d5bb9e15827e77b970643a9e6fd63afa9947e57
5
5
  SHA512:
6
- metadata.gz: 29615368e78617aace0075da63b77f4870ecd10e377ad561b0211d5907d37a4954c2f7fd8e625e1a7f98c9ecb1733ef36605a5d8ad75a5e284f53b2e22039cd6
7
- data.tar.gz: 6091dda3b44a530b3d5ddc5bca2c2cd871dab961a6e2768253d214292c9d196d5feae0e3a76b03aa6c45e3cfbba0c5e2159d338ec6bbe69ff422565e1e96202a
6
+ metadata.gz: fbd537352c05d38f9b4a2f8ebaee26c1e83d787071593caaa1a72bce8be60c41b36c2d869923d633bfb3851e26497b63f453c15e69fac4725986d8207cea03a7
7
+ data.tar.gz: 11f6d7403fb9eed905255a1c4d1eee477a2ea220d867d0a4d7ce09a9a0b50b081daf59f21cb92dbffcbe4dd4e31ca76ef01e3234e66353ee203a1007b8cc4685
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.02651**. This is the 1st version since redesign. Next 5-15 versions will be about bug fixing and minor tweaks.
17
+ Version of Locatine is **0.02653**. This is the 1st version since redesign. Next 5-15 versions will be about bug fixing and minor tweaks.
18
18
 
19
19
  ## Attention
20
20
 
@@ -80,7 +80,7 @@ driver = Selenium::WebDriver.
80
80
 
81
81
  This way is recommended because of the simplicity.
82
82
 
83
- Another way is to set options after the session was created by making [POST request to '/locatine/session/%session_id%'](https://github.com/sseleznevqa/locatine#post-to-wd-hub-session_id)
83
+ Another way is to set options after the session was created by making [POST request to '/locatine/session/%session_id%'](https://github.com/sseleznevqa/locatine#post-to-wdhubsession)
84
84
 
85
85
  ## Settings to pass
86
86
 
@@ -329,7 +329,7 @@ For more information about locators read about [locator strategies](https://www.
329
329
 
330
330
  Locatine also provides its own locator strategy == 'locatine'. In order to use it you need to inject it to the code of selenium-webdriver implementation.
331
331
 
332
- See it's done for ruby [here](https://github.com/sseleznevqa/locatine/tree/master/spec/e2e_spec.rb#L6-L25)
332
+ See it's done for ruby [here](https://github.com/sseleznevqa/locatine/tree/master/spec/e2e_spec.rb#L5-L11)
333
333
 
334
334
  When it's done you can use:
335
335
 
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'sinatra/base'
4
4
  require 'json'
5
- require 'locatine/session'
6
- require 'locatine/daemon_helpers/methods'
7
5
 
8
6
  module Locatine
9
7
  #
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorize'
4
+
5
+ module Locatine
6
+ #
7
+ # Methods for sending lines to STDOUT
8
+ module Logger
9
+ def warn(text)
10
+ puts "WARNING: #{Time.now}: ".yellow + text
11
+ end
12
+
13
+ def log(text)
14
+ puts "MESSAGE: #{Time.now}: ".magenta + text
15
+ end
16
+
17
+ def locatine_error(text)
18
+ puts "ERROR: #{Time.now}: ".red + text.red
19
+ end
20
+
21
+ def warn_locator
22
+ warn("Locator is broken. For #{name} by"\
23
+ " #{@locator['using']}>>>'#{locator['value']}'")
24
+ end
25
+
26
+ def warn_guess
27
+ warn("Locatine is trying to guess what is #{@name}")
28
+ end
29
+
30
+ def log_start
31
+ log "#{Time.now}: Locatine is working on #{@name}"
32
+ end
33
+
34
+ def warn_magic
35
+ warn "Locatine cannot find element #{@name} by usual methods and "\
36
+ 'starting to look for some element that is similar. Retrived '\
37
+ 'element may be not the one that is desired from this point'
38
+ end
39
+
40
+ def warn_lost
41
+ warn "Locatine found nothing for #{@name}"
42
+ end
43
+
44
+ def warn_unstable_page
45
+ warn 'Locatine detected stale element error. It means some elements'\
46
+ ' found by locatine are not attached to DOM anymore.'\
47
+ ' Page is unstable. Starting searching process again'
48
+ end
49
+
50
+ def log_found
51
+ log "Locatine found something as #{@name}"
52
+ log "XPATH == #{generate_xpath(raw_info)}"
53
+ end
54
+
55
+ def raise_script_error(script, args, answer)
56
+ locatine_error 'Locatine faced an error while trying to perform '\
57
+ "js script.\n ---Script was: #{script}\n\n ---Arguments was: #{args}"\
58
+ "\n\n ---Answer was: #{answer}"
59
+ raise answer['error']
60
+ end
61
+ end
62
+ end
@@ -1,12 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'locatine/results_helpers/info_generator'
4
- require 'locatine/results_helpers/xpath_generator'
5
- require 'locatine/results_helpers/find_by_magic'
6
- require 'locatine/results_helpers/common'
7
- require 'locatine/results_helpers/logger'
8
- require 'locatine/results_helpers/guess'
9
-
10
3
  module Locatine
11
4
  #
12
5
  # Locatine results container
@@ -15,7 +8,7 @@ module Locatine
15
8
  include Locatine::ResultsHelpers::XpathGenerator
16
9
  include Locatine::ResultsHelpers::FindByMagic
17
10
  include Locatine::ResultsHelpers::Common
18
- include Locatine::ResultsHelpers::Logger
11
+ include Locatine::Logger
19
12
  include Locatine::ResultsHelpers::Guess
20
13
 
21
14
  attr_accessor :name, :config, :locator
@@ -40,6 +40,32 @@ module Locatine
40
40
  end
41
41
  answer
42
42
  end
43
+
44
+ def count_similarity
45
+ all = 0
46
+ same = 0
47
+ # Next is necessary for unknown reason (smthing thread related)
48
+ raw = raw_info['0']
49
+ get_trusted(known['0']).each do |hash|
50
+ caught = (raw.select { |item| info_hash_eq(item, hash) }).first
51
+ all += 1
52
+ same += 1 if caught
53
+ end
54
+ similar_enough(same, all)
55
+ end
56
+
57
+ def similar?
58
+ return false if empty?
59
+
60
+ return true if tolerance == 100
61
+
62
+ count_similarity
63
+ end
64
+
65
+ def similar_enough(same, all)
66
+ sameness = (same * 100) / all
67
+ sameness >= 100 - tolerance
68
+ end
43
69
  end
44
70
  end
45
71
  end
@@ -1,14 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'locatine/results'
4
- require 'locatine/element'
5
- require 'locatine/results_helpers/logger'
6
-
7
3
  module Locatine
8
4
  #
9
5
  # Locatine session operator finds and returns
10
6
  class Session
11
- include Locatine::ResultsHelpers::Logger
7
+ include Locatine::Logger
12
8
  attr_accessor :json, :depth, :trusted, :untrusted, :tolerance, :stability,
13
9
  :elements, :timeout
14
10
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Locatine
4
4
  # constants here...
5
- VERSION = '0.02651'
5
+ VERSION = '0.02653'
6
6
  NAME = 'locatine'
7
7
  HOME = if File.readable?("#{Dir.pwd}/lib/#{Locatine::NAME}")
8
8
  "#{Dir.pwd}/lib/#{Locatine::NAME}"
data/lib/locatine.rb CHANGED
@@ -1,5 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'locatine/daemon_helpers/methods'
4
+ require 'locatine/results_helpers/common'
5
+ require 'locatine/results_helpers/find_by_magic'
6
+ require 'locatine/results_helpers/guess'
7
+ require 'locatine/results_helpers/info_generator'
8
+ require 'locatine/results_helpers/xpath_generator'
9
+
10
+ require 'locatine/logger'
3
11
  require 'locatine/version'
4
12
  require 'locatine/daemon'
5
13
  require 'locatine/session'
14
+ require 'locatine/element'
15
+ require 'locatine/results'
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.02651'
4
+ version: '0.02653'
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-01 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,12 +141,12 @@ files:
141
141
  - lib/locatine/daemon.rb
142
142
  - lib/locatine/daemon_helpers/methods.rb
143
143
  - lib/locatine/element.rb
144
+ - lib/locatine/logger.rb
144
145
  - lib/locatine/results.rb
145
146
  - lib/locatine/results_helpers/common.rb
146
147
  - lib/locatine/results_helpers/find_by_magic.rb
147
148
  - lib/locatine/results_helpers/guess.rb
148
149
  - lib/locatine/results_helpers/info_generator.rb
149
- - lib/locatine/results_helpers/logger.rb
150
150
  - lib/locatine/results_helpers/xpath_generator.rb
151
151
  - lib/locatine/scripts/element.js
152
152
  - lib/locatine/scripts/page.js
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'colorize'
4
-
5
- module Locatine
6
- module ResultsHelpers
7
- #
8
- # Methods for sending lines to STDOUT
9
- module Logger
10
- def warn(text)
11
- puts "WARNING: #{Time.now}: ".yellow + text
12
- end
13
-
14
- def log(text)
15
- puts "MESSAGE: #{Time.now}: ".magenta + text
16
- end
17
-
18
- def locatine_error(text)
19
- puts "ERROR: #{Time.now}: ".red + text.red
20
- end
21
-
22
- def warn_locator
23
- warn("Locator is broken. For #{name} by"\
24
- " #{@locator['using']}>>>'#{locator['value']}'")
25
- end
26
-
27
- def warn_guess
28
- warn("Locatine is trying to guess what is #{@name}")
29
- end
30
-
31
- def log_start
32
- log "#{Time.now}: Locatine is working on #{@name}"
33
- end
34
-
35
- def warn_magic
36
- warn "Locatine cannot find element #{@name} by usual methods and "\
37
- 'starting to look for some element that is similar. Retrived '\
38
- 'element may be not the one that is desired from this point'
39
- end
40
-
41
- def warn_lost
42
- warn "Locatine found nothing for #{@name}"
43
- end
44
-
45
- def warn_unstable_page
46
- warn 'Locatine detected stale element error. It means some elements'\
47
- ' found by locatine are not attached to DOM anymore.'\
48
- ' Page is unstable. Starting searching process again'
49
- end
50
-
51
- def log_found
52
- log "Locatine found something as #{@name}"
53
- log "XPATH == #{generate_xpath(raw_info)}"
54
- end
55
-
56
- def raise_script_error(script, args, answer)
57
- locatine_error 'Locatine faced an error while trying to perform '\
58
- "js script.\n ---Script was: #{script}\n\n ---Arguments was: #{args}"\
59
- "\n\n ---Answer was: #{answer}"
60
- raise answer['error']
61
- end
62
- end
63
- end
64
- end