locatine 0.01839 → 0.01971

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: 6085cdba5bc5b209bf24330ded9e2458c045d3e3
4
- data.tar.gz: '0678ca74613066d304d6d8408ec18ef2dc5575da'
3
+ metadata.gz: 7f657236dd233260c2ce19bfc4960c3f7a77ccaf
4
+ data.tar.gz: fd76da1f17ae3eed77e0b04dc2df3add1ecfbb2f
5
5
  SHA512:
6
- metadata.gz: 10b9daf2cdd2139ddaf3f3054957ff467ba607681c692c6c7f3ea12c04b9d77845ab4a216003ccacdd6a84a5de901675f2708b2a17df967889d2a808c7dfbcfd
7
- data.tar.gz: dfb7c5746b8219d8c90215c239d8aab91de686959911cd087d442a23d92e8564a8ff917f339cf2c22303b5722542f8fd32d61fea292b06b8196426741c680609
6
+ metadata.gz: 5c060f1f8c183113a1d3c95aac8612d889b03afeb439d5f41e676e7b3fe513bcb9082499f93616c4cb774a348aed91f45187e95b09c411caa8768a1cc292ea3a
7
+ data.tar.gz: 974782f877bdfd62faac8bee06ac8df307ae829d498e01db2ce6e6256d3506d351fe1281343695561b9bb477daf030c988fdfcc016923711142f7b20a94156ef
data/README.md CHANGED
@@ -16,7 +16,7 @@ That's it.
16
16
 
17
17
  ## Stage of development:
18
18
 
19
- Version of Locatine is **0.01839** only. It means so far this is an early alfa. You can use it in a real project if you are really risky person.
19
+ Version of Locatine is **0.01971** only. It means so far this is an early alfa. You can use it in a real project if you are really risky person.
20
20
 
21
21
  ## Installation
22
22
 
@@ -38,12 +38,14 @@ Or install it yourself as:
38
38
 
39
39
  1. Be sure that you have [Chrome browser](https://www.google.com/chrome/browser/desktop/) installed. It should work with any browser but something you can do in Chrome only
40
40
  2. Write the code
41
+
41
42
  ```ruby
42
43
  require 'locatine'
43
44
  s = Locatine::Search.new
44
45
  s.browser.goto("yourpage.com.com")
45
46
  s.find(name: "element", scope: "Main").click
46
47
  ```
48
+
47
49
  3. Run it in terminal with parameter LEARN=1 approximately like:
48
50
 
49
51
  $ LEARN=1 ruby path_to_your_test.rb
@@ -53,7 +55,7 @@ s.find(name: "element", scope: "Main").click
53
55
  6. Click Locatine application icon at the browser panel
54
56
  7. And confirm the selection
55
57
 
56
- ![Steps 4-5-6](readme/567.png)
58
+ ![U can see an image here. On github)](readme/567.png)
57
59
 
58
60
  8. Now you can run the test without LEARN parameter and it will work.
59
61
 
@@ -275,8 +277,9 @@ scope.define
275
277
 
276
278
  You will be able to select all the elements and collections for scope one by one. When it is finished click "Abort Selection" button to exit the loop.
277
279
 
280
+ You can force use dynamic variables on define where is possible (same rules as for find):
281
+
278
282
  ```ruby
279
- # You can force use dynamic variables on define where is possible (same rules as for find)
280
283
  vars = {text: "dynamic text",
281
284
  tag: "span",
282
285
  attrName: "part of dynamic attr-value"}
@@ -289,7 +292,26 @@ search.find(scope: "Name of scope",
289
292
  vars: vars # Necessary if elements were defined with vars)
290
293
  ```
291
294
 
292
- Scope itself is not very useful now. But we are looking forward.
295
+ ### Methods of scope
296
+
297
+ If you want to get a hash with all elements that are defined in scope:
298
+
299
+ ```ruby
300
+ # Lost elements will be found if possible!
301
+ search.get_scope(name: "Name of scope").all
302
+ # => {"element name": {
303
+ # elements: Array of Watir::Element,
304
+ # locator: valid xpath locator
305
+ # }...
306
+ # }
307
+ ```
308
+
309
+ If you want to check presence of all elements:
310
+
311
+ ```ruby
312
+ # Will raise an error if something lost!
313
+ search.get_scope(name: "Name of scope").check
314
+ ```
293
315
 
294
316
  ## Other ways to use find
295
317
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Locatine app",
3
- "version": "0.01839",
3
+ "version": "0.01971",
4
4
  "description": "Messaging from browser to main app",
5
5
  "devtools_page": "devtools.html",
6
6
  "permissions": ["activeTab", "storage", "contextMenus", "tabs"],
@@ -118,6 +118,16 @@ module Locatine
118
118
  import_browser(value)
119
119
  end
120
120
 
121
+ ##
122
+ # Returns an instance of the Scope class. Starts define if learn == true
123
+ #
124
+ # Params:
125
+ #
126
+ # +name+ is a parameter that stores name of the scope.
127
+ # Default is "Default"
128
+ #
129
+ # +vars+ is a hash which will be used to generate dynamic attributes.
130
+ # See readme for explanation.
121
131
  def get_scope(name: 'Default', vars: {})
122
132
  answer = Scope.new(name, self)
123
133
  answer.define(vars) if @learn
@@ -9,12 +9,77 @@ module Locatine
9
9
  @scope = scope
10
10
  end
11
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
12
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].nil?
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, exact: strict)
62
+ locator = { xpath: @search.send(:generate_xpath, hash, vars) }
63
+ { elements: elements, locator: locator }
64
+ end
65
+
66
+ def find_all(vars = {}, strict = false, define = false)
67
+ learn = @search.learn
68
+ @search.learn = define
69
+ result = {}
70
+ data.each_pair do |name, hash|
71
+ result[name] = find_one(name, hash, vars, strict)
72
+ end
73
+ @search.learn = learn
74
+ result
75
+ end
76
+
77
+ def new_define(vars)
13
78
  item = @search.send(:ask, @scope, '', nil, vars)
14
- return if item[:element].nil?
79
+ return find_all(vars) if item[:element].nil?
15
80
 
16
81
  @search.send(:store, item[:attributes], @scope, item[:name])
17
- define(vars)
82
+ new_define(vars)
18
83
  end
19
84
  end
20
85
  end
@@ -1,6 +1,6 @@
1
1
  module Locatine
2
2
  # constants here...
3
- VERSION = '0.01839'.freeze
3
+ VERSION = '0.01971'.freeze
4
4
  NAME = 'locatine'.freeze
5
5
  HOME = if File.readable?("#{Dir.pwd}/lib/#{Locatine::NAME}")
6
6
  "#{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.01839'
4
+ version: '0.01971'
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-04-10 00:00:00.000000000 Z
11
+ date: 2019-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,7 +148,6 @@ files:
148
148
  - lib/locatine/scope.rb
149
149
  - lib/locatine/search.rb
150
150
  - lib/locatine/version.rb
151
- - readme/567.png
152
151
  homepage: https://github.com/sseleznevqa/locatine
153
152
  licenses:
154
153
  - MIT
data/readme/567.png DELETED
Binary file