site-object 0.3.0 → 0.4.0

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: 730db955f5d3cf13412e6fc2eef05b75197832ba
4
- data.tar.gz: c1f90e003b9e2bdbd9e38aca3af9dcddb545e4d2
3
+ metadata.gz: 29b5d367c47596bba00efad173e605df63f4135e
4
+ data.tar.gz: 70b1d65e5519d8d0d9eda901157d462d3cb28cce
5
5
  SHA512:
6
- metadata.gz: 65e33a7bfb7b8a0603e7f4db56bc81198c9ba5e9410baf7f28916fb7b1fe23f00f3a3322c1fd74174c76340a23bff66b2fb93353a97a12d91ce085f33b47cc9d
7
- data.tar.gz: 844a52ce7d9c5eeb4df26d430a52bdaa292de5508f5fee0f5d0b3b8698b5d4b33931a0367bdd2231f7a83faec1c2802c238cd5ccdad90e40fe88ba73e8b2f820
6
+ metadata.gz: 04f664abd579838d75b3dd451899508e3493684fc4112afb3adb20ca1344a67089d12f94008daf6ce4ac075140ca8800d32e928569e21a93a9811f2b987b2d62
7
+ data.tar.gz: 0ce857445dbb62b554b26909a72672e2bde06e268d24012e1b58420da06c8971efffe6814c28244fc18356e860e39672747b4440fea4bf3270496d82744245fc
@@ -62,14 +62,10 @@
62
62
  module PageObject
63
63
 
64
64
  module PageClassMethods
65
- attr_reader :arguments, :browser, :navigation_disabled, :page_elements, :page_features, :page_url, :site, :unique_methods, :url_template, :url_matcher
66
-
67
- # Looks up all of the descendants of the current class. Used to figure out which page object classes
68
- # belong to the site.
69
- def descendants
70
- ObjectSpace.each_object(Class).select { |klass| klass < self }
71
- end
65
+ cattr_accessor :page_features # Page features should be inheritable so that page templates work.
66
+ attr_reader :page_attributes, :page_elements, :page_url, :url_template, :url_matcher
72
67
 
68
+ # DEPRECATED. Use the set_attributes method instead.
73
69
  # This method can be used to disable page navigation when defining a page class (it sets an
74
70
  # instance variable called @navigation during initialization.) The use case for this is a page
75
71
  # that can't be accessed directly and requires some level of browser interaction to reach.
@@ -85,6 +81,9 @@ module PageObject
85
81
  # If the visit method is called on the page a SiteObject::PageNavigationNotAllowedError
86
82
  # will be raised.
87
83
  def disable_automatic_navigation
84
+ puts "DEPRECATED. Will be removed in a future release. Use the set_attributes method in place of this one. See documentation for more details."
85
+ @page_attributes ||= []
86
+ @page_attributes << :navigation_disabled
88
87
  @navigation_disabled = true
89
88
  end
90
89
 
@@ -117,6 +116,54 @@ module PageObject
117
116
  end
118
117
  alias :el :element
119
118
 
119
+ # Allows you to set special page attributes that affect page behavior. The two page
120
+ # attributes currently supported are :navigation_disabled and :page_template:
121
+ #
122
+ # * When :navigation_disabled is specified as a page attribute, all automatic and
123
+ # manual browser navigation is disabled. If you call the page's page methods
124
+ # automatic navigation is turned off -- it won't automatically load the page for
125
+ # you. And it the method will raise a PageNavigationNotAllowedError if you call
126
+ # the page's accessor method while you aren't actually on the page. And finally,
127
+ # the page's visit method is disabled. This attribute is useful only when you
128
+ # have a page that can't be automatically navigated to, in which case all of
129
+ # the navigation features described above wouldn't work anyway.
130
+ #
131
+ # * When :page_template is specified as a page attribute, the site object won't
132
+ # create an accessor method for the page when initializing and also won't include
133
+ # the page when calling the site object's pages method. This allows you to define
134
+ # a page object for inheritance purposes only. The idea behind this is to put common
135
+ # features one or more of these templates, which won't get used directly. Then your
136
+ # other page objects that you actually do want to use can inherit from one of the
137
+ # templates, gaining all of its features. For example, you can put things like a
138
+ # logout link or common menus into a template and then have all of the page objects
139
+ # that need those features inherit from the template and get those features
140
+ # automatically.
141
+ #
142
+ # If an unsupported attribute is specified a PageConfigError will be raised.
143
+ #
144
+ # Usage:
145
+ # set_attributes :attr1, :attr2
146
+ def set_attributes(*args)
147
+ @page_attributes ||= []
148
+ args.each do |arg|
149
+ case arg
150
+ when :navigation_disabled
151
+ @navigation_disabled = true
152
+ when :page_template
153
+ @page_template = true
154
+ else
155
+ raise SiteObject::PageConfigError, "Unsupported page attribute argument: #{arg} for #{self} page definition. Argument class: #{arg.class}. Arguments must be one or more of the following symbols: :navigation_disabled, :template."
156
+ end
157
+ end
158
+
159
+ @page_attributes = args
160
+ end
161
+
162
+ def page_template?
163
+ @page_attributes ||= []
164
+ @page_attributes.include? :page_template
165
+ end
166
+
120
167
  # Returns an array of symbols representing the required arguments for the page's page URL.
121
168
  def required_arguments
122
169
  @arguments ||= @url_template.keys.map { |k| k.to_sym }
@@ -255,12 +302,16 @@ module PageObject
255
302
  #
256
303
  # Use the PageFeature class to define page features.
257
304
  def use_features(*args)
258
- @page_features = args
305
+ if self.page_features
306
+ args.each { |feature| self.page_features << feature }
307
+ else
308
+ self.page_features = args
309
+ end
259
310
  end
260
311
  end
261
312
 
262
313
  module PageInstanceMethods
263
- attr_reader :arguments, :browser, :navigation_disabled, :page_elements, :page_features, :page_url, :required_arguments, :site, :url_template, :url_matcher
314
+ attr_reader :arguments, :browser, :page_attributes, :page_elements, :page_features, :page_url, :required_arguments, :site, :url_template, :url_matcher
264
315
 
265
316
  # Takes the name of a page class. If the current page is of that class then it returns a page
266
317
  # object for the page. Raises a SiteObject::WrongPageError if that's not the case.
@@ -275,7 +326,7 @@ module PageObject
275
326
  # handle all of this for you.
276
327
  def initialize(site, args={})
277
328
  @browser = site.browser
278
- @navigation_disabled = self.class.navigation_disabled
329
+ @page_attributes = self.class.page_attributes
279
330
  @page_url = self.class.page_url
280
331
  @page_elements = self.class.page_elements
281
332
  @page_features = self.class.page_features
@@ -318,7 +369,6 @@ module PageObject
318
369
  # Do nothing here.
319
370
  end
320
371
  @url = @url_template.expand(@arguments).to_s
321
-
322
372
  @page_features ||= []
323
373
  @page_features.each do |arg|
324
374
  self.class_eval do
@@ -337,7 +387,7 @@ module PageObject
337
387
 
338
388
  @site.most_recent_page = self
339
389
  unless on_page?
340
- if @navigation_disabled
390
+ if navigation_disabled?
341
391
  if page = @site.page
342
392
  raise SiteObject::PageNavigationNotAllowedError, "The #{self.class.name} page could not be accessed. Navigation is intentionally disabled for this page and the browser was displaying the #{@site.page.class.name} page when you tried to access it.\n\nPAGE URL:\n------------\n#{@site.browser.url}\n\n#{caller.join("\n")}"
343
393
  else
@@ -397,6 +447,10 @@ module PageObject
397
447
  false
398
448
  end
399
449
 
450
+ def navigation_disabled?
451
+ @page_attributes.include? :navigation_disabled
452
+ end
453
+
400
454
  # Refreshes the page.
401
455
  def refresh # TODO: Isolate browser library-specific code so that the adding a new browser library is cleaner.
402
456
  if @browser.is_a?(Watir::Browser)
@@ -413,7 +467,7 @@ module PageObject
413
467
  # navigation has been disabled for the page. Raises a SiteObject::WrongPageError if the
414
468
  # specified page isn't getting displayed after navigation.
415
469
  def visit
416
- if @navigation_disabled
470
+ if navigation_disabled?
417
471
  raise SiteObject::PageNavigationNotAllowedError, "Navigation has been disabled for the #{self.class.name} page. This was done when defining the page class and usually means that the page can't be reached directly through a URL and requires some additional work to access."
418
472
  end
419
473
  if @browser.is_a?(Watir::Browser)
@@ -77,25 +77,27 @@ module SiteObject
77
77
  @arguments = args.with_indifferent_access
78
78
  @base_url = @arguments[:base_url]
79
79
  @browser = @arguments[:browser]
80
- @pages = self.class::Page.descendants
80
+ @pages = self.class::Page.descendants.reject { |p| p.page_template? }
81
81
 
82
82
  # Set up accessor methods for each page and page checking methods..
83
83
  @pages.each do |current_page|
84
- current_page.set_url_template(@base_url)
84
+ unless current_page.page_template?
85
+ current_page.set_url_template(@base_url)
85
86
 
86
- if current_page.url_matcher
87
- unless current_page.url_matcher.is_a? Regexp
88
- raise SiteObject::PageConfigError, "A url_matcher was defined for the #{current_page} page but it was not a regular expression. Check the value provided to the set_url_matcher method in the class definition for this page. Object provided was a #{current_page.url_matcher.class.name}"
87
+ if current_page.url_matcher
88
+ unless current_page.url_matcher.is_a? Regexp
89
+ raise SiteObject::PageConfigError, "A url_matcher was defined for the #{current_page} page but it was not a regular expression. Check the value provided to the set_url_matcher method in the class definition for this page. Object provided was a #{current_page.url_matcher.class.name}"
90
+ end
89
91
  end
90
- end
91
92
 
92
- self.class.class_eval do
93
- define_method(current_page.to_s.underscore) do |args={}, block=nil|
94
- current_page.new(self, args)
95
- end
93
+ self.class.class_eval do
94
+ define_method(current_page.to_s.underscore) do |args={}, block=nil|
95
+ current_page.new(self, args)
96
+ end
96
97
 
97
- define_method("#{current_page.to_s.underscore}?") do
98
- on_page? current_page
98
+ define_method("#{current_page.to_s.underscore}?") do
99
+ on_page? current_page
100
+ end
99
101
  end
100
102
  end
101
103
  end
@@ -1,3 +1,3 @@
1
1
  module SiteObject
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Fitisoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-08 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,11 +80,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubyforge_project: site-object
83
- rubygems_version: 2.2.3
83
+ rubygems_version: 2.4.5.1
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Wraps page objects up into a site object, which provides some introspection
87
87
  and navigation capabilities that page objects don't provide. Works with Watir and
88
88
  Selenium.
89
89
  test_files: []
90
- has_rdoc: