unobtainium-multifind 0.2.0 → 0.3.0

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: 392fa2fb38d4cec4325a05a5b69243a5f9f4be07
4
- data.tar.gz: c56559898399e3d17d8642d6e819c8983aa5edbb
3
+ metadata.gz: c8353b1d5e748ec3304a0279b370b43a78914df5
4
+ data.tar.gz: a73f7d17ed12dccace0cfb453874373f5bc6acb1
5
5
  SHA512:
6
- metadata.gz: 1774529bf9115b1ab19348ba2e34acf6110d841f90a2aea769f40ade372cceddc7224a120d06048b25255f7ce9ec731a058735ec29fc79b8c1d09b025120fa63
7
- data.tar.gz: ec8e6dff393173d2a35eb9547b79de88b37cda555a74c5df10ea8557b598f69ae7ac8de12b544b3c37f9b10ecda6f21091cacb27c783d8f8c2f28a28ccc0ea6d
6
+ metadata.gz: 89196e5772927c51b4e0a07700a2b9dc348380ec2633b6fe779d1aaf2cf9050777b8a4c005e0c9c90a8163bc02e6f17fee39220c5043a6fe06032d3b9341760f
7
+ data.tar.gz: b7f000cd8f7159f3ba083a629437953e5a70b7e15e1a2ec8d798a84f843c1047dec7611cb6d2228591ceab8113c3ef8382293ab8c9d0e17cd652deb1a156e1e7
@@ -70,3 +70,6 @@ Style/NumericLiterals:
70
70
 
71
71
  Style/FileName:
72
72
  Enabled: false
73
+
74
+ Style/SpaceAfterNot:
75
+ Enabled: false
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unobtainium-multifind (0.2.0)
4
+ unobtainium-multifind (0.3.0)
5
5
  unobtainium (~> 0.5)
6
6
 
7
7
  GEM
@@ -35,8 +35,8 @@ GEM
35
35
  diff-lcs (>= 1.2.0, < 2.0)
36
36
  rspec-support (~> 3.4.0)
37
37
  rspec-support (3.4.1)
38
- rubocop (0.39.0)
39
- parser (>= 2.3.0.7, < 3.0)
38
+ rubocop (0.40.0)
39
+ parser (>= 2.3.1.0, < 3.0)
40
40
  powerpack (~> 0.1)
41
41
  rainbow (>= 1.99.1, < 3.0)
42
42
  ruby-progressbar (~> 1.7)
@@ -68,11 +68,11 @@ DEPENDENCIES
68
68
  phantomjs
69
69
  rake (~> 11.1)
70
70
  rspec (~> 3.4)
71
- rubocop (~> 0.39)
71
+ rubocop (~> 0.40)
72
72
  selenium-webdriver
73
73
  simplecov (~> 0.11)
74
74
  unobtainium-multifind!
75
75
  yard (~> 0.8)
76
76
 
77
77
  BUNDLED WITH
78
- 1.12.1
78
+ 1.12.3
@@ -36,6 +36,10 @@ module Unobtainium
36
36
  # that Selenium::WebDriver::Element responds to, or :exists? if you only
37
37
  # care whether the element exists.
38
38
  check_element: :displayed?,
39
+ # The default method to perform the actual find is :find_element, but
40
+ # you can override this here. The most sensible case would be to use
41
+ # :find_elements instead, of course.
42
+ find_method: :find_element,
39
43
  }.freeze
40
44
 
41
45
  class << self
@@ -54,9 +58,9 @@ module Unobtainium
54
58
 
55
59
  ##
56
60
  # Find multiple elements. Each argument is a Hash of selector options
57
- # that are passed to #find_element. If one argument contains keys from
58
- # the DEFAULT_OPTIONS Hash, it is instead treated as an options Hash for
59
- # the #multifind method.
61
+ # that are passed to options[:find_method]. If one argument contains keys
62
+ # from the DEFAULT_OPTIONS Hash, it is instead treated as an options Hash
63
+ # for the #multifind method.
60
64
  # @return Array of found elements or nil entries if no matching element
61
65
  # was found.
62
66
  def multifind(*args)
@@ -67,7 +71,7 @@ module Unobtainium
67
71
  results = []
68
72
  selectors.each do |selector|
69
73
  begin
70
- results << find_element(selector)
74
+ results << send(options[:find_method], selector)
71
75
  rescue ::Selenium::WebDriver::Error::NoSuchElementError => err
72
76
  if options[:raise_on_error]
73
77
  raise
@@ -153,24 +157,13 @@ module Unobtainium
153
157
  end
154
158
 
155
159
  # Filter all results according to the :check_element option
156
- filtered = []
157
- results.each do |result|
158
- if result.nil?
159
- filtered << result
160
- next
161
- end
162
- if result.is_a?(::Selenium::WebDriver::Error::NoSuchElementError)
163
- filtered << result
164
- next
165
- end
166
-
167
- # Run check_element
168
- if result.send(options[:check_element])
169
- filtered << result
170
- next
160
+ filtered = results.map do |result|
161
+ if result.is_a? Array
162
+ next result.map do |inner|
163
+ next apply_filter(inner, options)
164
+ end
171
165
  end
172
-
173
- filtered << nil
166
+ next apply_filter(result, options)
174
167
  end
175
168
 
176
169
  return filtered
@@ -205,10 +198,28 @@ module Unobtainium
205
198
  # or :last. An empty result is appropriate.
206
199
  return []
207
200
  end
201
+
202
+ ##
203
+ # Applies the :check_element filter
204
+ def apply_filter(elem, options)
205
+ if elem.nil?
206
+ return elem
207
+ end
208
+
209
+ if elem.is_a?(::Selenium::WebDriver::Error::NoSuchElementError)
210
+ return elem
211
+ end
212
+
213
+ if elem.send(options[:check_element])
214
+ return elem
215
+ end
216
+ return nil
217
+ end
208
218
  end # module DriverModule
209
219
  end # module MultiFind
210
220
  end # module Unobtainium
211
221
 
212
222
  ::Unobtainium::Driver.register_module(
213
223
  ::Unobtainium::MultiFind::DriverModule,
214
- __FILE__)
224
+ __FILE__
225
+ )
@@ -9,6 +9,6 @@
9
9
  module Unobtainium
10
10
  module MultiFind
11
11
  # The current release version
12
- VERSION = "0.2.0".freeze
12
+ VERSION = "0.3.0".freeze
13
13
  end # module MultiFind
14
14
  end # module Unobtainium
@@ -38,6 +38,10 @@ describe 'Unobtainium::MultiFind::DriverModule' do
38
38
  end
39
39
 
40
40
  describe "find functionality" do
41
+ before do
42
+ require 'unobtainium-multifind'
43
+ end
44
+
41
45
  it "can find a single element" do
42
46
  drv = @tester.driver(DRIVER)
43
47
  drv.navigate.to(TEST_URL)
@@ -181,6 +185,10 @@ describe 'Unobtainium::MultiFind::DriverModule' do
181
185
  end
182
186
 
183
187
  describe "find options" do
188
+ before do
189
+ require 'unobtainium-multifind'
190
+ end
191
+
184
192
  it "can throw on errors" do
185
193
  drv = @tester.driver(DRIVER)
186
194
  drv.navigate.to(TEST_URL)
@@ -252,5 +260,50 @@ describe 'Unobtainium::MultiFind::DriverModule' do
252
260
  drv.find(xpath: '//foo')
253
261
  end.to raise_error
254
262
  end
263
+
264
+ it "can override the find method with :find_elements" do
265
+ drv = @tester.driver(DRIVER)
266
+ drv.navigate.to(TEST_URL)
267
+
268
+ drv.multifind_options = { find_method: :find_elements }
269
+
270
+ elem = drv.find(xpath: '//foo/bar')
271
+ expect(elem).not_to be_nil
272
+ expect(elem).not_to be_empty
273
+ expect(elem.length).to eql 1
274
+ expect(elem[0]).not_to be_nil
275
+
276
+ expect(elem[0].is_a?(Array)).to be_truthy
277
+ expect(elem[0].length).to eql 1
278
+ expect(elem[0][0]).not_to be_nil
279
+ end
280
+
281
+ it "treats hidden elements well with :find_elements" do
282
+ drv = @tester.driver(DRIVER)
283
+ drv.navigate.to(TEST_URL)
284
+
285
+ drv.multifind_options = { find_method: :find_elements }
286
+
287
+ elem = drv.find(xpath: '//foo/hidden')
288
+ expect(elem).not_to be_nil
289
+ expect(elem).not_to be_empty
290
+ expect(elem.length).to eql 1
291
+ expect(elem[0]).not_to be_nil
292
+
293
+ expect(elem[0].is_a?(Array)).to be_truthy
294
+ expect(elem[0].length).to eql 1
295
+ expect(elem[0][0]).to be_nil
296
+ end
297
+
298
+ it "raises errors when the find method is invalid" do
299
+ drv = @tester.driver(DRIVER)
300
+ drv.navigate.to(TEST_URL)
301
+
302
+ drv.multifind_options = { find_method: :does_not_exist }
303
+
304
+ expect do
305
+ drv.find(xpath: '//foo/bar')
306
+ end.to raise_error
307
+ end
255
308
  end
256
309
  end
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
42
42
  spec.requirements = "Unobtainium driver implementing the Selenium API"
43
43
 
44
44
  spec.add_development_dependency "bundler", "~> 1.12"
45
- spec.add_development_dependency "rubocop", "~> 0.39"
45
+ spec.add_development_dependency "rubocop", "~> 0.40"
46
46
  spec.add_development_dependency "rake", "~> 11.1"
47
47
  spec.add_development_dependency "rspec", "~> 3.4"
48
48
  spec.add_development_dependency "simplecov", "~> 0.11"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unobtainium-multifind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Finkhaeuser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.39'
33
+ version: '0.40'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.39'
40
+ version: '0.40'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement