locatine 0.0092 → 0.00463

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
  SHA1:
3
- metadata.gz: 44a26e49cfff1bf0841fd588c9556fa0fbb1b394
4
- data.tar.gz: 8f5b147ce47421e947be9ccdc2191da0fa746621
3
+ metadata.gz: 3f5d7a3f44e75991451c83cc507561dc4a1c7f06
4
+ data.tar.gz: 88aaf2612d0f3d4b0a56b2fa1ef6cb830eddd790
5
5
  SHA512:
6
- metadata.gz: 3d151d506c89a6990640d34515519121a1b5b0da0c5d4797d3751b2b486ce7cb094ec90a7adab71c5580a2f2dbcd88c8f169c0c078f75c0c35bcc05589db9fbc
7
- data.tar.gz: 3f6251ba3eed8756ca023d47a43b57953210463670430320cf46d06e762113796b2bc8f12d51f58d89f5d2c873e7de602787f5cfb4913d6d39f74d422755eea4
6
+ metadata.gz: 967f585713d8557bf164013ba74fb804d55b1628d5f2057b450873b3107027cd36f9ef7db48e0f0e1741a92296518a879748adf0c0c075f02d3df87c4a474414
7
+ data.tar.gz: 387240a6229f98260bb3ce3f64a6bcfc8f0e6eae856c8bb579a870d92be2193ae5acab128dd194d86545e7342ef88dbb2abca2b6a295a4719c3d25ab22252d3d
@@ -2,31 +2,27 @@ require "watir"
2
2
  require "json"
3
3
  require "fileutils"
4
4
  require "chromedriver-helper"
5
+ require "pry"
5
6
 
6
7
  module Locatine
7
8
 
8
9
  ##
9
10
  # Search is the main class of the Locatine
10
11
  #
11
- # Locatine can search.
12
+ # Locatine can dance.
12
13
  class Search
13
14
 
14
15
  attr_accessor :data, :depth, :browser, :learn, :json, :stability_limit, :scope
15
16
 
16
17
  ##
17
- # Creates a new instance of Search
18
+ # Creates a new instance of Dance
18
19
  #
19
20
  # Params:
20
21
  # +json+ is the name of file to store//read data. Default => "./Locatine_files/default.json"
21
- #
22
22
  # +depth+ is the value that shows how many data will be stored for element.
23
- #
24
23
  # +browser+ is the instance of Watir::Browser. Unless provided it gonna be created with locatine-app onboard.
25
- #
26
24
  # +learn+ shows will locatine ask for assistance from user or will fail on error. learn is true when LEARN parameter is set in environment.
27
- #
28
25
  # +stability_limit+ shows max times attribute should be present to consider it trusted.
29
- #
30
26
  # +scope+ will be used in search (if not provided) defaulkt is "Default"
31
27
  def initialize(json: "./Locatine_files/default.json",
32
28
  depth: 3,
@@ -53,30 +49,14 @@ module Locatine
53
49
  # Looking for the element
54
50
  #
55
51
  # Params:
56
- #
57
52
  # +scope+ is a parameter that is used to get information about the element from @data. Default is "Default"
58
- #
59
53
  # +name+ is a parameter that is used to get information about the element from @data. Must not be nil.
60
- #
61
54
  # +exact+ if true locatine will be forced to use only basic search. Default is false
62
- #
63
55
  # +locator+ if not empty it is used for the first attempt to find the element. Default is {}
64
- #
65
56
  # +vars+ hash of variables that will be used for dynamic attributes. See readme for example
66
- #
67
57
  # +look_in+ only elements of that kind will be used. Use Watir::Browser methods returning collections (:text_fields, :links, :divs, etc.)
68
- #
69
58
  # +iframe+ if provided locatine will look for elements inside of it
70
- def find(simple_name = nil,
71
- name: nil,
72
- scope: nil,
73
- exact: false,
74
- locator: {},
75
- vars: {},
76
- look_in: nil,
77
- iframe: nil,
78
- return_locator: false,
79
- collection: false)
59
+ def find(simple_name = nil, name: nil, scope: nil, exact: false, locator: {}, vars: {}, look_in: nil, iframe: nil, return_locator: false)
80
60
  name ||= simple_name
81
61
  raise ArgumentError, ":name should be provided" if !name
82
62
  @type = look_in
@@ -94,18 +74,15 @@ module Locatine
94
74
  end
95
75
  end
96
76
  result, attributes = ask(scope, name, result, vars) if @learn
97
- raise RuntimeError, "Nothing was found for #{scope} #{name}" if !result && !exact
98
- if result
99
- attributes = generate_data(result, vars) if !attributes
100
- store(attributes, scope, name)
101
- return return_locator ? {xpath: generate_xpath(attributes, vars)} : to_subtype(result, collection)
102
- else
103
- return nil
104
- end
77
+ raise RuntimeError, "Nothing was found for #{scope} #{name}" if !result
78
+ attributes = generate_data(result, vars) if !attributes
79
+ @type = nil
80
+ store(attributes, scope, name)
81
+ return return_locator ? {xpath: generate_xpath(attributes, vars)} : to_subtype(result)
105
82
  end
106
83
 
107
84
  ##
108
- # Find alias with return_locator option enforced
85
+ # Find alias with return_locator enforced
109
86
  def lctr(*args)
110
87
  if args.last.class == Hash
111
88
  args.last[:return_locator] = true
@@ -115,12 +92,6 @@ module Locatine
115
92
  find(args)
116
93
  end
117
94
 
118
- ##
119
- # Find alias with collection option enforced
120
- def collect(*args)
121
- enforce(:collection, true, *args)
122
- end
123
-
124
95
  private
125
96
 
126
97
  ##
@@ -142,18 +113,6 @@ module Locatine
142
113
  end
143
114
  end
144
115
 
145
- def enforce(what, value, *args)
146
- if args.last.class == Hash
147
- args.last[what] = value
148
- find(*args)
149
- else
150
- temp = Hash.new
151
- temp[what] = value
152
- args.push(temp)
153
- find(*args)
154
- end
155
- end
156
-
157
116
  def engine
158
117
  return (@iframe || @browser)
159
118
  end
@@ -201,12 +160,7 @@ module Locatine
201
160
  end
202
161
 
203
162
  def get_trusted(array)
204
- if array.length > 0
205
- max_stability = (array.max_by {|i| i["stability"].to_i})["stability"].to_i
206
- return (array.select {|i| i["stability"].to_i == max_stability}).uniq
207
- else
208
- return []
209
- end
163
+ return (array.select {|i| i["stability"].to_i == (array.max_by {|i| i["stability"].to_i})["stability"].to_i}).uniq
210
164
  end
211
165
 
212
166
  def generate_xpath(data, vars)
@@ -262,8 +216,7 @@ module Locatine
262
216
  @cold_time = timeout
263
217
  raise RuntimeError, "Locatine is unable to find element #{name} in #{scope}" if all.length == 0
264
218
  # Something esoteric here :)
265
- max = all.count(all.max_by {|i| all.count(i)})
266
- suggestion = (all.select {|i| all.count(i) == max}).uniq
219
+ suggestion = (all.select {|i| all.count(i) == all.count(all.max_by {|i| all.count(i)})}).uniq
267
220
  attributes = generate_data(suggestion, vars)
268
221
  return suggestion, attributes
269
222
  end
@@ -319,15 +272,12 @@ module Locatine
319
272
  end
320
273
  end
321
274
 
322
- def set_title(text)
323
- puts text
324
- send_to_app("locatinetitle", text)
325
- end
326
-
327
275
  ##
328
276
  # Sending request to locatine app
329
277
  def start_listening(scope, name)
330
278
  send_to_app("locatinestyle", "blocked", @browser) if @iframe
279
+ puts "You are defining #{name} in #{scope}" # TODO send to app
280
+ send_to_app("locatinetitle", "You are defining #{name} in #{scope}.")
331
281
  send_to_app("locatinehint", "Toggle single//collection mode button if you need. If you want to do some actions on the page toggle Locatine waiting button. You also can select element on devtools -> Elements. Do not forget to confirm your selection.")
332
282
  send_to_app("locatinestyle", "set_true")
333
283
  sleep 0.5
@@ -343,17 +293,15 @@ module Locatine
343
293
  all = all + find_by_locator({xpath: "//*[@*[contains(., '#{part}')]]"}).to_a
344
294
  end
345
295
  if all.length>0
346
- max = all.count(all.max_by {|i| all.count(i)})
347
- guess = (all.select {|i| all.count(i) == max}).uniq
296
+ guess = (all.select {|i| all.count(i) == all.count(all.max_by {|i| all.count(i)})}).uniq
348
297
  guess_data = generate_data(guess, vars)
349
- by_data = find_by_data(guess_data, vars)
350
- if by_data.nil? || (engine.elements.length/find_by_data(guess_data, vars).length <=4)
351
- set_title "Locatine has no good guess for #{name} in #{scope}. Try to change the name. Or just define it."
298
+ if (engine.elements.length/find_by_data(guess_data, vars).length <=4)
299
+ puts "Locatine has no good guess for #{name} in #{scope}. Try to change the name. Or just define it."
352
300
  guess = nil
353
301
  guess_data = {}
354
302
  end
355
303
  else
356
- set_title "Locatine has no guess for #{name} in #{scope}. Try to change the name. Or just define it."
304
+ puts "Locatine has no guess for #{name} in #{scope}. Try to change the name. Or just define it."
357
305
  end
358
306
  @cold_time = timeout
359
307
  return guess, guess_data.to_h
@@ -367,8 +315,7 @@ module Locatine
367
315
  if !element.nil?
368
316
  attributes = generate_data(element, vars)
369
317
  else
370
- set_title("Locatine is trying to guess what is #{name} in #{scope}.")
371
- element, attributes = find_by_guess(scope, name, vars) if name.length >= 5
318
+ element, attributes = find_by_guess(scope, name, vars)
372
319
  end
373
320
  while !finished do
374
321
  sleep 0.1
@@ -388,17 +335,13 @@ module Locatine
388
335
  if old_element != element
389
336
  mass_highlight_turn(old_element, false) if old_element
390
337
  mass_highlight_turn(element) if element
391
- if element.nil?
392
- set_title "Nothing is selected as #{name} in #{scope}"
393
- else
394
- set_title "#{element.length} elements were selected as #{name} in #{scope}. If it is correct - confirm the selection."
395
- end
338
+ puts "#{element.length} elemens were selected as #{name} in #{scope}"
396
339
  end
397
340
  old_element, old_tag, old_index = element, tag, index
398
341
  case get_from_app("locatineconfirmed")
399
342
  when "true"
400
343
  send_to_app("locatineconfirmed", "ok")
401
- send_to_app("locatinetitle", "Right now you are defining nothing. So no button will work")
344
+ send_to_app("locatinetitle", "You are defining nothing. So no button will work")
402
345
  send_to_app("locatinehint", "Place for a smart hint here")
403
346
  finished = true
404
347
  when "declined"
@@ -586,14 +529,11 @@ module Locatine
586
529
  #
587
530
  # Params:
588
531
  # +result+ must be Watir::HTMLElementCollection or Array
589
- #
590
- # +collection+ nil, true or false
591
- def to_subtype(result, collection)
592
- case collection
593
- when true
532
+ def to_subtype(result)
533
+ if result.size == 1
534
+ return result[0].to_subtype
535
+ else
594
536
  return result
595
- when false
596
- return result.first.to_subtype
597
537
  end
598
538
  end
599
539
  end
@@ -1,6 +1,12 @@
1
1
  module Locatine
2
2
  # constants here...
3
- VERSION = "0.0092"
3
+ generator = Random.new 42
4
+ versions = []
5
+ 1000.times do
6
+ versions.push generator.rand.round(5)
7
+ end
8
+ ITERATION = 0
9
+ VERSION = versions.sort[ITERATION].to_s
4
10
  NAME = "locatine"
5
11
  HOME = File.readable?("#{Dir.pwd}/lib/#{Locatine::NAME}")? "#{Dir.pwd}/lib/#{Locatine::NAME}" : "#{Gem.dir}/gems/#{Locatine::NAME}-#{Locatine::VERSION}/lib/#{Locatine::NAME}"
6
12
  end
data/lib/locatine.rb CHANGED
@@ -1,2 +1 @@
1
- require "locatine/search"
2
- require "locatine/version"
1
+ Dir.glob("./lib/locatine/*.rb").each {|it| require it}
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.0092'
4
+ version: '0.00463'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Seleznev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-05 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,15 +115,6 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - lib/locatine.rb
118
- - lib/locatine/app/background.js
119
- - lib/locatine/app/content.css
120
- - lib/locatine/app/content.js
121
- - lib/locatine/app/devtools.html
122
- - lib/locatine/app/devtools.js
123
- - lib/locatine/app/manifest.json
124
- - lib/locatine/app/popup.css
125
- - lib/locatine/app/popup.html
126
- - lib/locatine/app/popup.js
127
118
  - lib/locatine/search.rb
128
119
  - lib/locatine/version.rb
129
120
  homepage: https://github.com/sseleznevqa/locatine
@@ -1,9 +0,0 @@
1
- chrome.browserAction.onClicked.addListener(
2
- function(tab) {
3
- console.log("WAS here");
4
- chrome.windows.create( {'url': 'popup.html',
5
- 'type': 'popup',
6
- 'width': 800,
7
- 'height': 600});
8
-
9
- });
@@ -1,40 +0,0 @@
1
- @keyframes locatine_found {
2
- 0% {border: 4px dashed #6495ED;}
3
- 20% {border: 4px dashed #FF7F50;}
4
- 40% {border: 4px dashed #8FBC8F;}
5
- 60% {border: 4px dashed #FFA500;}
6
- 80% {border: 4px dashed #DDA0DD;}
7
- 100% {border: 4px dashed #6495ED;}
8
- }
9
-
10
- div[locatinestyle=true] {
11
- position:fixed;
12
- padding:0;
13
- margin:0;
14
- top:0;
15
- left:0;
16
- opacity: 0;
17
- background: black;
18
- height: 100%;
19
- width: 100%;
20
- pointer-events: visible;
21
- display: block;
22
- z-index: 2147483646;
23
- }
24
-
25
- div[locatinestyle=false] {
26
- height: 0%;
27
- width: 0%;
28
- }
29
-
30
- div[locatinestyle=blocked] {
31
- height: 0%;
32
- width: 0%;
33
- }
34
-
35
- [locatineclass=foundbylocatine]
36
- {animation: locatine_found 6s infinite;
37
- -webkit-appearance: none;
38
- -moz-appearance: none;
39
- appearance: none;
40
- }
@@ -1,94 +0,0 @@
1
- async function set_value(name, value){
2
- let temp = {};
3
- temp[name] = value;
4
- await chrome.storage.sync.set(temp, function() {});
5
- };
6
-
7
- async function get_value(name) {
8
-   let x = await new Promise((resolve, reject) => chrome.storage.sync.get([name], resolve));
9
- return x[name];
10
- };
11
-
12
- document.addEventListener("locatine_send", async function(e) {
13
- await set_value(e.detail.varname, e.detail.varvalue);
14
- });
15
-
16
- async function refreshData(){
17
- if (!document.getElementById("locatine_magic_div")){
18
- const options = {
19
- "locatineclass": "locatine_smthing",
20
- "id":"locatine_magic_div",
21
- "locatinestyle": await get_value('magic_div') || "false",
22
- "locatinetitle": "ok",
23
- "locatinehint": "ok"
24
- };
25
- locatine_create_element(document.body, "div", options, "");
26
- } else {
27
- const magicDiv = document.getElementById("locatine_magic_div");
28
- if (magicDiv.getAttribute("locatinestyle") === "set_true") {
29
- await set_value('magic_div', true);
30
- magicDiv.setAttribute("locatinestyle", "true");
31
- };
32
- if (magicDiv.getAttribute("locatinetitle") != "ok") {
33
- await set_value('locatine_title', magicDiv.getAttribute("locatinetitle"));
34
- await set_value('locatine_hint', magicDiv.getAttribute("locatinehint"));
35
- magicDiv.setAttribute("locatinetitle", "ok");
36
- }
37
- let status = await get_value('magic_div');
38
- if (magicDiv.getAttribute("locatinestyle") != "set_true"){
39
- magicDiv.setAttribute("locatinestyle", status);
40
- }
41
- magicDiv.setAttribute("locatinecollection", await get_value("locatine_collection"))
42
- if (magicDiv.getAttribute("locatineconfirmed") === "ok") {
43
- magicDiv.removeAttribute("tag");
44
- magicDiv.removeAttribute("index");
45
- await set_value("locatine_confirm", false);
46
- await set_value('magic_div', false);
47
- }
48
- const confirmed = await get_value('locatine_confirm');
49
- magicDiv.setAttribute("locatineconfirmed", confirmed);
50
- };
51
- const magic_cover = document.getElementById('locatine_magic_div');
52
- magic_cover.onclick = function(e) {locatine_magic_click(e)};
53
- };
54
-
55
- function getSelected(value){
56
- const tagName = value.tagName;
57
- const array = Array.prototype.slice.call( document.getElementsByTagName(tagName) );
58
- const index = array.indexOf(value);
59
- document.getElementById("locatine_magic_div").setAttribute("tag", tagName);
60
- document.getElementById("locatine_magic_div").setAttribute("index", index);
61
- };
62
-
63
- function locatine_magic_click(e) {
64
- document.getElementById("locatine_magic_div").setAttribute("locatinestyle", "blocked");
65
- const value = document.elementFromPoint(e.clientX, e.clientY);
66
- document.getElementById("locatine_magic_div").setAttribute("locatinestyle", "true");
67
- const tagName = value.tagName;
68
- const array = Array.prototype.slice.call( document.getElementsByTagName(tagName) );
69
- const index = array.indexOf(value);
70
- document.getElementById("locatine_magic_div").setAttribute("TAG", tagName);
71
- document.getElementById("locatine_magic_div").setAttribute("INDEX", index);
72
- };
73
-
74
- function locatine_create_element(dom, tag, attrs, inner) {
75
- const element = document.createElement(tag);
76
- dom.appendChild(element);
77
- for (var key in attrs) {
78
- element.setAttribute(key, attrs[key])
79
- };
80
- element.innerHTML = inner;
81
- return element;
82
- };
83
-
84
- //set_value('magic_div','off');
85
-
86
- setInterval(async function(){
87
- if (document.getElementById("locatine_magic_div")) {
88
- if (document.getElementById("locatine_magic_div").getAttribute("locatinestyle") != "blocked") {
89
- await refreshData()
90
- }
91
- } else {
92
- await refreshData()
93
- }
94
- }, 100);
@@ -1 +0,0 @@
1
- <script src="devtools.js"></script>
@@ -1,3 +0,0 @@
1
- setInterval(function(){
2
- chrome.devtools.inspectedWindow.eval("getSelected($0)", { useContentScriptContext: true });
3
- }, 100);
@@ -1,20 +0,0 @@
1
- {
2
- "name": "Locatine app",
3
- "version": "0.0092",
4
- "description": "Messaging from browser to main app",
5
- "devtools_page": "devtools.html",
6
- "permissions": ["activeTab", "storage", "contextMenus", "tabs"],
7
- "background": {
8
- "scripts": ["background.js"],
9
- "persistent": true
10
- },
11
- "content_scripts": [{
12
- "matches": ["<all_urls>"],
13
- "all_frames": true,
14
- "js": ["content.js"],
15
- "css": ["content.css"]
16
- }],
17
- "browser_action": {
18
- "default_title": "Locatine"},
19
- "manifest_version": 2
20
- }
@@ -1,41 +0,0 @@
1
- .button {
2
- border: none;
3
- height: 30px;
4
- width: 100%;
5
- color: white;
6
- padding: 5px 32px;
7
- text-align: center;
8
- text-decoration: none;
9
- display: inline-block;
10
- font-size: 16px;
11
- }
12
-
13
- .green {
14
- background-color: #4CAF50
15
- }
16
-
17
- .red {
18
- background-color: #AF4C50
19
- }
20
-
21
- .blue {
22
- background-color: #4C50AF
23
- }
24
-
25
- .header {
26
- padding: 10px 5px 10px 5px;
27
- text-align: center;
28
- color: black;
29
- font-size: 25px;
30
- }
31
-
32
- .hint {
33
- padding: 10px 5px 10px 5px;
34
- text-align: center;
35
- background-color: #EFFA93;
36
- box-shadow: 5px 5px 5px;
37
- }
38
-
39
- .block {
40
- padding: 30px 5px 30px 5px;
41
- }
@@ -1,17 +0,0 @@
1
-
2
- <html>
3
- <head>
4
- <link rel="stylesheet" href="popup.css">
5
- </head>
6
- <body>
7
- <h2 class="header" id="mainTitle">Right now you are defining nothing. So no button will work</h2>
8
- <h3 class="hint" id="hint">But you can click it anyway :)</h3>
9
- <div class="block">
10
- <input class="blue button" id="watchSwitch" type="button" value="Do not watch"/>
11
- <input class="blue button" id="mode" type="button" value="Adding mode is enabled"/>
12
- <input class="red button" id="clearMark" type="button" value="Clear selection"/>
13
- <input class="green button" id="confirm" type="button" value="Confirm selection"/>
14
- </div>
15
- <script src="popup.js"></script>
16
- </body>
17
- </html>
@@ -1,50 +0,0 @@
1
- async function get_value(name) {
2
- let x = await new Promise((resolve, reject) => chrome.storage.sync.get([name], resolve));
3
- return x[name];
4
- };
5
-
6
- async function set_value(name, value){
7
- let temp = {};
8
- temp[name] = value;
9
- await chrome.storage.sync.set(temp, function() {});
10
- };
11
-
12
- async function correct_buttons() {
13
- if (await get_value("magic_div") === true) {
14
- document.getElementById("watchSwitch").setAttribute("value", "Locatine is waiting for click");
15
- } else {
16
- document.getElementById("watchSwitch").setAttribute("value", "Locatine is not waiting now");
17
- };
18
- if (await get_value("locatine_collection") === true) {
19
- document.getElementById("mode").setAttribute("value", "You are in collection mode")
20
- } else {
21
- document.getElementById("mode").setAttribute("value", "You are in single selection mode")
22
- };
23
- document.getElementById("mainTitle").innerText = await get_value("locatine_title");
24
- document.getElementById("hint").innerText = await get_value("locatine_hint");
25
- }
26
-
27
- async function watch() {
28
- await set_value("magic_div", !(await get_value("magic_div")));
29
- }
30
-
31
- function clear() {
32
- set_value("locatine_confirm", "declined");
33
- }
34
-
35
- function confirm() {
36
- set_value("locatine_confirm", true);
37
- }
38
-
39
- async function mode() {
40
- await set_value("locatine_collection", !(await get_value("locatine_collection")));
41
- }
42
-
43
- document.getElementById("watchSwitch").onclick = function() {watch()};
44
- document.getElementById("clearMark").onclick = function() {clear()};
45
- document.getElementById("confirm").onclick = function() {confirm()};
46
- document.getElementById("mode").onclick = function() {mode()};
47
-
48
- setInterval(function(){
49
- correct_buttons();
50
- }, 100);