site-object 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52fbfe67ec3e98f7ef7f8f0fb8165c4e5ec1ddd8
4
- data.tar.gz: 279c13969c26dfecab7e2768a029d96e96b0c59d
3
+ metadata.gz: 1a4df6ed4be703a9c8cd7412e4aaced525646eaf
4
+ data.tar.gz: 3bc242ec4569efa77de95d11a2fe5487898932a4
5
5
  SHA512:
6
- metadata.gz: ad42895bba2352c1e2d70557d7384e70126fa9082c35a6ec81d652e82c50303d6bb6305453205d6dfafc9289e5f8615dfe91fda0acb559e8249b5709faaa4f30
7
- data.tar.gz: 4ce4c9f68c5407ee6fa286f1f8126975f14fecbfe034d86ce0890cc1fa3fc2820d1376a1b9015bb44057b59f01425a6efc08e0d330fa28cb6ae9706546f8ec31
6
+ metadata.gz: 2fc776cefa54ab25f230f57937d2b3f7c5f947d8b8d73df846176541d8780e8190dbad35cec9dad298ff080ae6a4d502a9809ad011de7b864bec0858c84914f7
7
+ data.tar.gz: fcac3de77151044e37b6b79fd72488140d97ebe1fa78bc91fc26ff88534a55d5cf7c73737ec364d7f81cbbb7447e94fce3d44874b48e29e9a6a75eb4ccfdd67c
@@ -74,7 +74,7 @@ module PageObject
74
74
  Module.cattr_accessor :page_features
75
75
  end
76
76
 
77
- attr_reader :page_attributes, :page_elements, :page_url, :url_template, :url_matcher, :has_fragment
77
+ attr_reader :page_attributes, :page_elements, :page_url, :url_template, :url_matcher, :has_fragment, :template_arguments, :required_arguments, :query_arguments
78
78
 
79
79
  # DEPRECATED. Use the set_attributes method instead.
80
80
  # This method can be used to disable page navigation when defining a page class (it sets an
@@ -175,14 +175,27 @@ module PageObject
175
175
  @page_attributes.include? :page_template
176
176
  end
177
177
 
178
+ # def template_arguments
179
+ # all = @url_template.keys.map { |k| k.to_sym }
180
+ # optional = all.find_all { |x| @url_template.pattern =~ /(\?#{x}|\/#{x})/ }
181
+ # required = all - optional
182
+ # query = all.find_all { |x| @url_template.pattern =~ /\?#{x}/ }
183
+ # @template_arguments = {
184
+ # all: all,
185
+ # optional: optional,
186
+ # required: required,
187
+ # query: query
188
+ # }
189
+ # end
190
+
178
191
  # Returns an array of symbols representing the required arguments for the page's page URL.
179
- def required_arguments
180
- @arguments ||= @url_template.keys.map { |k| k.to_sym }
181
- end
192
+ # def required_arguments
193
+ # @arguments ||= @url_template.keys.map { |k| k.to_sym }
194
+ # end
182
195
 
183
- def query_arguments
184
- required_arguments.find { |x| @url_template.pattern =~ /\?.*#{x}=*/ }
185
- end
196
+ # def query_arguments
197
+ # required_arguments.find_all { |x| @url_template.pattern =~ /\?.*#{x}=*/ }
198
+ # end
186
199
 
187
200
  # Used to define the full or relative URL to the page. Typically, you will *almost* *always* want to use
188
201
  # this method when defining a page object (but see notes below.) The URL can be defined in a number
@@ -285,7 +298,20 @@ module PageObject
285
298
  else
286
299
  @url_template = Addressable::Template.new(Addressable::URI.parse("#{base_url}#{@page_url}"))
287
300
  end
288
- @has_fragment = @url_template.pattern =~ /#/
301
+
302
+ all = @url_template.keys.map { |k| k.to_sym }
303
+ optional = all.find_all { |x| @url_template.pattern =~ /(\?#{x}|\/#{x})/ }
304
+ required = all - optional
305
+ query = all.find_all { |x| @url_template.pattern =~ /\?#{x}/ }
306
+ @template_arguments = {
307
+ all: all,
308
+ optional: optional,
309
+ required: required,
310
+ query: query
311
+ }
312
+ @required_arguments = @template_arguments[:required]
313
+ @query_arguments = @template_arguments[:query]
314
+ @has_fragment = @url_template.pattern =~ /#/
289
315
  end
290
316
 
291
317
  # Optional. Allows you to specify a fallback mechanism for checking to see if the correct page is
@@ -340,7 +366,8 @@ module PageObject
340
366
  @page_url = self.class.page_url
341
367
  @page_elements = self.class.page_elements
342
368
  @page_features = self.class.page_features
343
- @required_arguments = self.class.required_arguments
369
+ @template_arguments = self.class.template_arguments
370
+ @required_arguments = @template_arguments[:required]
344
371
  @site = site
345
372
  @url_matcher = self.class.url_matcher
346
373
  @url_template = self.class.url_template
@@ -382,12 +409,36 @@ module PageObject
382
409
  # Do nothing here yet.
383
410
  end
384
411
  end
385
- elsif @required_arguments.empty? && args # If there are no required arguments then nothing should be provided.
412
+ elsif @template_arguments[:all].empty? && args # If there are no required/optional arguments then nothing should be provided.
386
413
  raise SiteObject::PageInitError, "#{args.class} was provided as a #{self.class.name} initialization argument, but the page URL doesn't require any arguments.\n\n#{caller.join("\n")}"
387
414
  else
388
415
  # Do nothing here yet.
389
416
  end
390
417
 
418
+ if @template_arguments[:optional].present? && args
419
+ @template_arguments[:optional].each do |arg|
420
+ if args.is_a?(Hash) && args.present?
421
+ args = args.with_indifferent_access
422
+
423
+ if args[arg] #The hash has the required argument.
424
+ @arguments[arg]= args[arg]
425
+ elsif @site.respond_to?(arg)
426
+ @arguments[arg]= site.send(arg)
427
+ else
428
+ # Do nothing.
429
+ end
430
+ elsif args # Some non-hash object was provided.
431
+ if args.respond_to?(arg) #The hash has the required argument.
432
+ @arguments[arg]= args.send(arg)
433
+ elsif @site.respond_to?(arg)
434
+ @arguments[arg]= site.send(arg)
435
+ else
436
+ # Do nothing.
437
+ end
438
+ end
439
+ end
440
+ end
441
+
391
442
  @url = @url_template.expand(@arguments).to_s
392
443
  @page_features ||= []
393
444
  @page_features.each do |arg|
@@ -428,17 +479,11 @@ module PageObject
428
479
  raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
429
480
  end
430
481
 
431
- if query_arguments
432
- if @has_fragment
433
- url = url.split(/#/)[0]
434
- end
435
- else
436
- url = url.split(/\?/)[0]
437
- end
438
-
439
482
  if @url_matcher
440
483
  if @url_matcher =~ url
441
484
  return true
485
+ elsif @url_matcher =~ url.split(/(#|\?)/)[0]
486
+ return true
442
487
  else
443
488
  return false
444
489
  end
@@ -1,3 +1,3 @@
1
1
  module SiteObject
2
- VERSION = '0.4.8'
2
+ VERSION = '0.4.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site-object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Fitisoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-19 00:00:00.000000000 Z
11
+ date: 2017-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -81,4 +81,3 @@ summary: Wraps page objects up into a site object, which provides some introspec
81
81
  and navigation capabilities that page objects don't provide. Works with Watir and
82
82
  Selenium.
83
83
  test_files: []
84
- has_rdoc: