site-object 0.4.5 → 0.4.6

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: 15f2ae6c537d2795043ea16f265246f365686990
4
- data.tar.gz: 4045598a63be0d5de8cfa22a3f73be9c8a2966aa
3
+ metadata.gz: 76f3e751539020ff7af4782aaa508521924d3016
4
+ data.tar.gz: 36d5a1a86b6b81a7651f4afbaebe580b5a51ad87
5
5
  SHA512:
6
- metadata.gz: 902911293f6c86fdb7ef2db1684b8c301050ef2852edb42e8af2e9704cc4edd1172b74c1c40134515923beeb594cdc18713dd0819e8b731bf37b2ba29829a173
7
- data.tar.gz: 8787cbcd6c9a25efb261d434aeacd0d6a7a91502e0fe937b5eb8d12baf6f9d72dc3204431b060074effac8f46bad95fb931a60cc34e49a07c1898ee500315109
6
+ metadata.gz: 88b1483f6249fcb4e4ff845d903394a11668a7252b34117b3bf2a5914fba32ad5703cccc85891a68ba2ba5f47be47f7184871e329ef45686226ea242a5a87ceb
7
+ data.tar.gz: 6e355f2c33218f1ba25208ef07b625254e0c4be776e43d0659bab216b88bfb5312169fa689095a7847aac2c5043c6320a9b1beee93a20a0afb2865a9f4a014a2
@@ -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
77
+ attr_reader :page_attributes, :page_elements, :page_url, :url_template, :url_matcher, :has_fragment
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
@@ -180,8 +180,8 @@ module PageObject
180
180
  @arguments ||= @url_template.keys.map { |k| k.to_sym }
181
181
  end
182
182
 
183
- def query_argument
184
- required_arguments.find { |x| @url_template.pattern =~ /{\?#{x}\*}/}
183
+ def query_arguments
184
+ required_arguments.find { |x| @url_template.pattern =~ /\?.*#{x}=*/ }
185
185
  end
186
186
 
187
187
  # Used to define the full or relative URL to the page. Typically, you will *almost* *always* want to use
@@ -285,6 +285,7 @@ module PageObject
285
285
  else
286
286
  @url_template = Addressable::Template.new(Addressable::URI.parse("#{base_url}#{@page_url}"))
287
287
  end
288
+ @has_fragment = @url_template.pattern =~ /#/
288
289
  end
289
290
 
290
291
  # Optional. Allows you to specify a fallback mechanism for checking to see if the correct page is
@@ -320,7 +321,7 @@ module PageObject
320
321
  end
321
322
 
322
323
  module PageInstanceMethods
323
- attr_reader :arguments, :browser, :page_attributes, :page_elements, :page_features, :page_url, :query_argument, :required_arguments, :site, :url_template, :url_matcher
324
+ attr_reader :arguments, :browser, :has_fragment, :page_attributes, :page_elements, :page_features, :page_url, :query_arguments, :required_arguments, :site, :url_template, :url_matcher
324
325
 
325
326
  # Takes the name of a page class. If the current page is of that class then it returns a page
326
327
  # object for the page. Raises a SiteObject::WrongPageError if that's not the case.
@@ -343,7 +344,9 @@ module PageObject
343
344
  @site = site
344
345
  @url_matcher = self.class.url_matcher
345
346
  @url_template = self.class.url_template
346
- @query_argument = self.class.query_argument
347
+ @query_arguments = self.class.query_arguments
348
+ @has_fragment = self.class.has_fragment
349
+
347
350
 
348
351
  # Try to expand the URL template if the URL has parameters.
349
352
  @arguments = {}.with_indifferent_access # Stores the param list that will expand the url_template after examining the arguments used to initialize the page.
@@ -416,45 +419,21 @@ module PageObject
416
419
  "#<#{self.class.name}:#{object_id} @url_template=#{@url_template.inspect}>"
417
420
  end
418
421
 
419
- # Returns true if the page defined by the page object is currently being displayed in the browser,
420
- # false if not. It does this in two different ways, which are described below.
421
- #
422
- # A page always has a URL defined for it. This is typically done by using the Page.set_url method
423
- # to specify a URL when defining the page. You can skip using the set_url method but in that case
424
- # the page URL defaults to the base URL defined for the site object.
425
- #
426
- # The default approach for determining if the page is being displayed relies on the URL defined for
427
- # the page. This method first does a general match against the current browser URL page's URL template.
428
- # If a match occurs here, and there are no required arguments for the page the method returns true.
429
- # If the page's URL template does require arguments the method performs an additional check to
430
- # verify that each of the arguments defined for the page match what's in the current browser URL.
431
- # If all of the arguments match then the method will return true.
432
- #
433
- # This should work for most cases but may not always be enough. For example, there may be a redirect
434
- # and the URL used to navigate to the page may not be the final page URL. There's a fallback
435
- # mechanism for these sorts of situations. You can use the Page.set_url_matcher method to define a
436
- # regular expression that the method will use in place of the URL template. If the regular expression
437
- # matches, then the method will return true even if the URL wouldn't match the URL template.
438
- #
439
- # It's better to use the default URL matching if possible. But if for some reason it's not feasible
440
- # you can use the alternate method to specify how to match the page.
441
422
  def on_page?
442
- if @url_template.pattern =~ /#/ # It has a URL fragment. Don't mess with the browser URL.
443
- if @browser.is_a? Watir::Browser
444
- url = @browser.url
445
- elsif @browser.is_a? Selenium::WebDriver::Driver
446
- url = @browser.current_url
447
- else
448
- raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
449
- end
450
- else # There's no fragment in the URL template, strip the fragment out of the URL so that template matching works better.
451
- if @browser.is_a? Watir::Browser
452
- url = @browser.url.split(/(\?|#)/)[0]
453
- elsif @browser.is_a? Selenium::WebDriver::Driver
454
- url = @browser.current_url.split(/(\?|#)/)[0]
455
- else
456
- raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
423
+ if @browser.is_a? Watir::Browser
424
+ url = @browser.url
425
+ elsif @browser.is_a? Selenium::WebDriver::Driver
426
+ url = @browser.current_url
427
+ else
428
+ raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
429
+ end
430
+
431
+ if query_arguments
432
+ if @has_fragment
433
+ url = url.split(/#/)[0]
457
434
  end
435
+ else
436
+ url = url.split(/\?/)[0]
458
437
  end
459
438
 
460
439
  if @url_matcher && @url_matcher =~ url
@@ -463,12 +442,13 @@ module PageObject
463
442
  if @arguments.empty?
464
443
  return true
465
444
  else
466
- if page_args = @url_template.extract(Addressable::URI.parse(url))
467
- page_args = page_args.with_indifferent_access
468
- (@required_arguments - [query_argument]).all? { |k| page_args[k] == @arguments[k].to_s }
445
+ if pargs = @url_template.extract(Addressable::URI.parse(url))
446
+ pargs = pargs.with_indifferent_access
447
+ @required_arguments.all? { |k| pargs[k] == @arguments[k].to_s }
469
448
  end
470
449
  end
471
450
  end
451
+
472
452
  end
473
453
 
474
454
  def navigation_disabled?
@@ -1,3 +1,3 @@
1
1
  module SiteObject
2
- VERSION = '0.4.5'
2
+ VERSION = '0.4.6'
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.5
4
+ version: 0.4.6
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-05-18 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport