locatine 0.02539 → 0.02710

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +271 -296
  3. data/bin/locatine-daemon.rb +4 -2
  4. data/lib/locatine.rb +13 -2
  5. data/lib/locatine/daemon.rb +42 -60
  6. data/lib/locatine/daemon_helpers/methods.rb +85 -0
  7. data/lib/locatine/element.rb +32 -0
  8. data/lib/locatine/logger.rb +62 -0
  9. data/lib/locatine/results.rb +118 -0
  10. data/lib/locatine/results_helpers/common.rb +68 -0
  11. data/lib/locatine/results_helpers/find_by_magic.rb +118 -0
  12. data/lib/locatine/results_helpers/guess.rb +76 -0
  13. data/lib/locatine/results_helpers/info_generator.rb +79 -0
  14. data/lib/locatine/{for_search → results_helpers}/xpath_generator.rb +18 -11
  15. data/lib/locatine/scripts/element.js +40 -0
  16. data/lib/locatine/scripts/page.js +53 -0
  17. data/lib/locatine/scripts/parent.js +6 -0
  18. data/lib/locatine/session.rb +98 -0
  19. data/lib/locatine/version.rb +4 -2
  20. metadata +39 -49
  21. data/lib/locatine/app/background.js +0 -9
  22. data/lib/locatine/app/content.css +0 -43
  23. data/lib/locatine/app/content.js +0 -148
  24. data/lib/locatine/app/devtools.html +0 -1
  25. data/lib/locatine/app/devtools.js +0 -3
  26. data/lib/locatine/app/manifest.json +0 -20
  27. data/lib/locatine/app/popup.css +0 -47
  28. data/lib/locatine/app/popup.html +0 -19
  29. data/lib/locatine/app/popup.js +0 -63
  30. data/lib/locatine/daemon_helpers.rb +0 -52
  31. data/lib/locatine/for_search.rb +0 -6
  32. data/lib/locatine/for_search/data_generate.rb +0 -67
  33. data/lib/locatine/for_search/data_logic.rb +0 -98
  34. data/lib/locatine/for_search/defaults.rb +0 -40
  35. data/lib/locatine/for_search/dialog_logic.rb +0 -85
  36. data/lib/locatine/for_search/element_selection.rb +0 -80
  37. data/lib/locatine/for_search/file_work.rb +0 -67
  38. data/lib/locatine/for_search/find_by_guess.rb +0 -68
  39. data/lib/locatine/for_search/find_by_locator.rb +0 -59
  40. data/lib/locatine/for_search/find_by_magic.rb +0 -65
  41. data/lib/locatine/for_search/find_logic.rb +0 -79
  42. data/lib/locatine/for_search/helpers.rb +0 -107
  43. data/lib/locatine/for_search/highlight.rb +0 -41
  44. data/lib/locatine/for_search/listening.rb +0 -47
  45. data/lib/locatine/for_search/merge.rb +0 -40
  46. data/lib/locatine/for_search/name_helper.rb +0 -51
  47. data/lib/locatine/for_search/page_work.rb +0 -126
  48. data/lib/locatine/for_search/public.rb +0 -179
  49. data/lib/locatine/for_search/saying.rb +0 -196
  50. data/lib/locatine/large_scripts/css.js +0 -21
  51. data/lib/locatine/large_scripts/dimensions.js +0 -17
  52. data/lib/locatine/large_scripts/element.js +0 -31
  53. data/lib/locatine/large_scripts/page.js +0 -60
  54. data/lib/locatine/scope.rb +0 -88
  55. data/lib/locatine/search.rb +0 -67
@@ -1,196 +0,0 @@
1
- module Locatine
2
- module ForSearch
3
- ##
4
- # texts, errors
5
- # rubocop:disable Metrics/ModuleLength
6
- module Saying
7
- private
8
-
9
- def send_info(message)
10
- puts "#{time}: #{message}"
11
- end
12
-
13
- def send_warn(message)
14
- warn "#{time}: WARNING: #{message}"
15
- end
16
-
17
- def verb(length)
18
- length > 1 ? 'elements were' : 'element was'
19
- end
20
-
21
- ##
22
- # Setting attribute of locatine div (way to communicate)
23
- def send_to_app(what, value, bro = engine)
24
- fix_iframe
25
- bro.wd.execute_script(
26
- %[if (document.getElementById('locatine_magic_div')){
27
- const magic_div = document.getElementById('locatine_magic_div');
28
- return magic_div.setAttribute("#{what}", "#{value}")}]
29
- )
30
- fix_iframe
31
- end
32
-
33
- def push_title(text)
34
- send_info text
35
- send_to_app('locatinetitle', text)
36
- end
37
-
38
- def send_found(name, scope, length)
39
- push_title("#{length} #{verb(length)} found as #{name} in #{scope}"\
40
- ' using previously saved information')
41
- end
42
-
43
- def send_guessing(name, scope)
44
- push_title("Locatine is trying to guess what is #{name} in #{scope}.")
45
- end
46
-
47
- def send_selected(length, name, scope)
48
- push_title "#{length} #{verb(length)} selected as #{name} in "\
49
- "#{scope}. If it is correct - confirm the selection."
50
- end
51
-
52
- def send_working(tag, index)
53
- push_title "You've selected //#{tag}[#{index}]."\
54
- ' Wait while Locatine works'
55
- end
56
-
57
- def send_lost
58
- push_title 'Selected element was lost before locatine locate it. '\
59
- 'Consider choosing it from devtools or write your own locator'
60
- end
61
-
62
- def send_clear(name, scope)
63
- name = 'some element' if name.to_s.empty?
64
- push_title "Now nothing is selected as #{name} in #{scope}"
65
- end
66
-
67
- def send_no_guess(name, scope)
68
- push_title "Locatine has no good guess for #{name} in #{scope}."
69
- end
70
-
71
- def send_has_guess(name, scope)
72
- push_title "Something is guessed as #{name} in #{scope}."
73
- end
74
-
75
- def send_selecting(name, scope)
76
- name = 'some element' if name.to_s.empty?
77
- push_title "You are selecting #{name} in #{scope}"
78
- send_to_app('locatinehint', 'Toggle single//collection mode button if '\
79
- 'you need. If you want to do some actions on the page toggle'\
80
- ' Locatine waiting button. You also can select element on devtools '\
81
- '-> Elements. Do not forget to confirm your selection.')
82
- end
83
-
84
- def send_has_response
85
- push_title 'Right now you are defining nothing. So no button will work'
86
- send_to_app('locatinehint', 'Your previous selection is confirmed. '\
87
- 'Locatine is waiting for new find request')
88
- end
89
-
90
- def send_same_entry(length, name, scope, found)
91
- push_title "#{length} #{verb(length)} selected as #{name} in #{scope}."\
92
- " But it was already defined #{found.length} times."
93
- example = found.sample
94
- same = found.select { |i| (i[:name] == name) && (i[:scope] == scope) }
95
- if same.empty?
96
- send_same_entry_example(example)
97
- else
98
- send_fully_similar
99
- end
100
- end
101
-
102
- def send_same_entry_example(example)
103
- send_to_app('locatinehint', "For example like #{example[:name]} in"\
104
- " #{example[:scope]}")
105
- end
106
-
107
- def send_fully_similar
108
- send_to_app('locatinehint', 'And it was defined with the same name'\
109
- ' and in the same scope. So saving your selection will cause'\
110
- ' deleting of all previously stored data about the element')
111
- end
112
-
113
- def warn_dropping(tag, index)
114
- send_warn('For some reason locatine cannot proceed with'\
115
- " //#{tag}[#{index}] element. You've selected. Maybe element was"\
116
- ' changed somewhere in the middle of locatine work. If this error is'\
117
- 'repeating you can try to select element via devtools or you can'\
118
- ' provide a locator')
119
- end
120
-
121
- def warn_type
122
- send_warn("Check also. Maybe #{tag} element cannot be found as @type?")
123
- end
124
-
125
- def warn_acceptable_type(method)
126
- send_warn "#{method} works for :look_in. But it is better to use a"\
127
- ' method of Watir::Browser that returns a collection (like :divs,'\
128
- ' :links, etc.)'
129
- end
130
-
131
- def warn_element_lost(name, scope)
132
- send_warn "#{name} in #{scope} is//are lost. Locatine is trying "\
133
- 'to find it anyway.'
134
- end
135
-
136
- def warn_cannot_highlight(data)
137
- send_warn "Something was found as #{data} but we cannot highlight it"
138
- end
139
-
140
- def warn_broken_locator(locator)
141
- send_warn "Can find nothing using #{locator}"
142
- end
143
-
144
- def warn_unstable
145
- send_warn 'It seems that page is unstable. It may lead to problems '\
146
- 'with resolving elements'
147
- end
148
-
149
- def warn_highly_unstable
150
- send_warn 'It seems that page is HIGHLY unstable. No guaranties now.'
151
- end
152
-
153
- def warn_much_highlight(size)
154
- send_warn "Only the first 50 elements of #{size} were highlighted."
155
- end
156
-
157
- def warn_lost_found(name, scope)
158
- send_warn "Something was found as #{name} in #{scope}."
159
- end
160
-
161
- def warn_not_found(name, scope)
162
- send_warn "Locatine cannot find element #{name} in #{scope}"
163
- end
164
-
165
- def warn_totally_same(how_deep)
166
- send_warn('There are more than one elements with totally similar'\
167
- " attributes. Custom depth for element is set to #{how_deep}.")
168
- end
169
-
170
- def warn_no_negatives
171
- send_warn 'The only way to find the selected element is to use'\
172
- " negative expression like //*[not(@id='something')]. Locatine does"\
173
- ' not support it. So you must to provide for element a custom locator.'\
174
- ' Or find it as a part of collection and than return it by index'
175
- end
176
-
177
- def raise_not_found(name, scope)
178
- raise "Locatine cannot find element #{name} in #{scope}"
179
- end
180
-
181
- def raise_not_similar(name, scope)
182
- raise "Locatine cannot find element similar to #{name} in #{scope}"
183
- end
184
-
185
- def raise_no_name
186
- raise ArgumentError, ':name is not provided.'
187
- end
188
-
189
- def raise_no_var(thevar)
190
- raise ArgumentError, ":#{thevar} must be "\
191
- 'provided in vars since element was defined with it'
192
- end
193
- end
194
- end
195
- end
196
- # rubocop:enable Metrics/ModuleLength
@@ -1,21 +0,0 @@
1
- function walk(elm, result) {
2
- let node;
3
-
4
- const tagName = elm.tagName;
5
- const array = Array.prototype.slice.call( document.getElementsByTagName(tagName) );
6
- const index = array.indexOf(elm);
7
-
8
- const item = [tagName, index, getComputedStyle(elm).cssText]
9
- result.push(item)
10
-
11
- // Handle child elements
12
- for (node = elm.firstChild; node; node = node.nextSibling) {
13
- if (node.nodeType === 1) { // 1 == Element
14
- result = walk(node, result);
15
- }
16
- }
17
- return result
18
- }
19
- let array = walk(document.body,[]);
20
- array.shift();
21
- return array;
@@ -1,17 +0,0 @@
1
- function walk(xmi, xma, ymi, yma){
2
- let x;
3
- let y;
4
- let array =[];
5
- let one;
6
- for (x = xmi; x <= xma; x++) {
7
- for (y = ymi; y <= yma; y++) {
8
- one = document.elementFromPoint(x, y);
9
- if ((one != document.documentElement) && (one != document.body)){
10
- array.push(document.elementFromPoint(x, y));
11
- }
12
- }
13
- }
14
- return [...new Set(array)];
15
- }
16
-
17
- return walk(parseInt(arguments[0]), parseInt(arguments[1]), parseInt(arguments[2]), parseInt(arguments[3]))
@@ -1,31 +0,0 @@
1
-
2
- function one_element(target){
3
- console.log("TARGET ==", target);
4
-
5
- let element = {};
6
- let attribute = {};
7
-
8
- element = {attrs: [], text: "", tag: ""};
9
- if (target.childNodes){
10
- for (let i = 0; i < target.childNodes.length; ++i){
11
- if (target.childNodes[i].nodeType === 3){
12
- element.text += target.childNodes[i].textContent;
13
- }
14
- }
15
- } else {
16
- element.text = target.textContent
17
- }
18
- element.tag = target.tagName.toLowerCase();
19
- let atts = target.attributes;
20
- if (atts) {
21
- for (var k = 0, n = atts.length; k < n; k++){
22
- att = atts[k];
23
- attribute = {};
24
- attribute[att.nodeName] = att.nodeValue;
25
- element.attrs.push(attribute);
26
- }
27
- }
28
- return element;
29
- }
30
- let x = one_element(arguments[0]);
31
- return x;
@@ -1,60 +0,0 @@
1
-
2
- function walk(elm) {
3
- let node;
4
-
5
- const tagName = elm.tagName.toLowerCase();
6
- const array = Array.prototype.slice.call( document.getElementsByTagName(tagName) );
7
- const index = array.indexOf(elm);
8
- const relative = elm.getBoundingClientRect();
9
-
10
- // init item
11
- const item = {tag: tagName,
12
- index: index,
13
- style: getComputedStyle(elm).cssText,
14
- text: "",
15
- attrs: {},
16
- coordinates: {top:0, bottom:0, left:0, right:0},
17
- children: []};
18
-
19
- // text for item
20
- if (elm.childNodes) {
21
- for (let z = 0; z < elm.childNodes.length; ++z){
22
- if (elm.childNodes[z].nodeType === 3){
23
- item.text += elm.childNodes[z].textContent;
24
- }
25
- }
26
- } else {
27
- item.text = elm.textContent
28
- }
29
-
30
- // attributes for item
31
- atts = elm.attributes;
32
- if (atts) {
33
- for (var att, k = 0, n = atts.length; k < n; k++){
34
- att = atts[k];
35
- item.attrs[att.nodeName] = att.nodeValue;
36
- }
37
- }
38
-
39
- item.coordinates.top = relative["top"] + window.scrollY;
40
- item.coordinates.bottom = relative["bottom"] + window.scrollY;
41
- item.coordinates.left = relative["left"] + window.scrollX;
42
- item.coordinates.right = relative["right"] + window.scrollX;
43
-
44
- // Handle child elements (not magic ones)
45
- for (node = elm.firstChild; node; node = node.nextSibling) {
46
- if (node.nodeType === 1) { // 1 == Element
47
- if (node.attributes['id']) {
48
- if (node.attributes['id'].value !== 'locatine_magic_div') {
49
- item.children.push(walk(node))
50
- }
51
- } else {
52
- item.children.push(walk(node))
53
- }
54
- }
55
- }
56
-
57
- return item;
58
- }
59
- let result = walk(document.body);
60
- return [result];
@@ -1,88 +0,0 @@
1
- module Locatine
2
- ##
3
- # Scope is the class representing group of elements
4
- #
5
- # Locatine has scopes
6
- class Scope
7
- def initialize(scope, search)
8
- @search = search
9
- @scope = scope
10
- end
11
-
12
- ##
13
- # Way to define locatine a bunch elements at once. Elements will be taken
14
- # from user selection one by one and saved in scope.
15
- #
16
- # Params:
17
- #
18
- # +vars+ hash of vars used for dynamic attributes. Same as in :find
19
- def define(vars = {})
20
- find_all(vars, false, true) if data.to_h != {}
21
- new_define(vars)
22
- end
23
-
24
- ##
25
- # Getting all the elements of the scope at once
26
- #
27
- # Params:
28
- #
29
- # +vars+ hash of vars used for dynamic attributes. Same as in :find
30
- def all(vars = {})
31
- find_all(vars)
32
- end
33
-
34
- ##
35
- # Checking all the elements of the scope at once.
36
- # Will fail if something was lost
37
- #
38
- # Params:
39
- #
40
- # +vars+ hash of vars used for dynamic attributes. Same as in :find
41
- def check(vars = {})
42
- success = []
43
- result = find_all(vars, true)
44
- result.each_pair do |name, hash|
45
- success.push name if hash[:elements].empty?
46
- end
47
- raise "Check of #{@scope} failed! Lost: #{success}" unless success.empty?
48
-
49
- result
50
- end
51
-
52
- private
53
-
54
- def data
55
- @search.data[@scope]
56
- end
57
-
58
- def find_one(name, hash, vars, strict)
59
- locator = { xpath: @search.send(:generate_xpath, hash, vars) } if strict
60
- elements = @search.collect(scope: @scope, name: name,
61
- locator: locator,
62
- exact: strict,
63
- no_fail: strict)
64
- locator = { xpath: @search.send(:generate_xpath, hash, vars) }
65
- { elements: elements, locator: locator }
66
- end
67
-
68
- def find_all(vars = {}, strict = false, define = false)
69
- learn = @search.learn
70
- @search.learn = define
71
- result = {}
72
- data.each_pair do |name, hash|
73
- result[name] = find_one(name, hash, vars, strict)
74
- end
75
- @search.learn = learn
76
- result
77
- end
78
-
79
- def new_define(vars)
80
- item = @search.send(:ask, @scope, '', nil, vars)
81
- return find_all(vars) if item[:element].nil?
82
-
83
- @search.send(:set_env_for_search, nil, nil, nil, nil, nil, nil)
84
- @search.send(:store, item[:attributes], @scope, item[:name])
85
- new_define(vars)
86
- end
87
- end
88
- end
@@ -1,67 +0,0 @@
1
- require 'watir'
2
- require 'json'
3
- require 'fileutils'
4
- require 'webdrivers'
5
-
6
- # Internal requires
7
- require 'locatine/for_search/merge'
8
- require 'locatine/for_search/public'
9
- require 'locatine/for_search/saying'
10
- require 'locatine/for_search/helpers'
11
- require 'locatine/for_search/defaults'
12
- require 'locatine/for_search/file_work'
13
- require 'locatine/for_search/page_work'
14
- require 'locatine/for_search/listening'
15
- require 'locatine/for_search/highlight'
16
- require 'locatine/for_search/data_logic'
17
- require 'locatine/for_search/find_logic'
18
- require 'locatine/for_search/name_helper'
19
- require 'locatine/for_search/dialog_logic'
20
- require 'locatine/for_search/find_by_magic'
21
- require 'locatine/for_search/find_by_guess'
22
- require 'locatine/for_search/data_generate'
23
- require 'locatine/for_search/xpath_generator'
24
- require 'locatine/for_search/find_by_locator'
25
- require 'locatine/for_search/element_selection'
26
-
27
- module Locatine
28
- ##
29
- # Search is the main class of the Locatine
30
- #
31
- # Locatine can search.
32
- class Search
33
- include Locatine::ForSearch::Merge
34
- include Locatine::ForSearch::Public
35
- include Locatine::ForSearch::Saying
36
- include Locatine::ForSearch::Helpers
37
- include Locatine::ForSearch::Defaults
38
- include Locatine::ForSearch::FileWork
39
- include Locatine::ForSearch::PageWork
40
- include Locatine::ForSearch::DataLogic
41
- include Locatine::ForSearch::Listening
42
- include Locatine::ForSearch::FindLogic
43
- include Locatine::ForSearch::Highlight
44
- include Locatine::ForSearch::NameHelper
45
- include Locatine::ForSearch::FindByMagic
46
- include Locatine::ForSearch::DialogLogic
47
- include Locatine::ForSearch::FindByGuess
48
- include Locatine::ForSearch::DataGenerate
49
- include Locatine::ForSearch::FindByLocator
50
- include Locatine::ForSearch::XpathGenerator
51
- include Locatine::ForSearch::ElementSelection
52
-
53
- attr_accessor :data,
54
- :depth,
55
- :learn,
56
- :stability_limit,
57
- :scope,
58
- :tolerance,
59
- :visual_search,
60
- :no_fail,
61
- :trusted,
62
- :untrusted,
63
- :autolearn
64
- attr_reader :json,
65
- :browser
66
- end
67
- end