site-object 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/site-object/exceptions.rb +1 -1
- data/lib/site-object/page.rb +40 -31
- data/lib/site-object/site.rb +18 -8
- data/lib/site-object/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ffad1526098cde8900f8949d589b74808119b9f
|
4
|
+
data.tar.gz: 270bc988459c67d8e2aa4b557f3ad147569f0620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f223fe2372d5ee95767ded972117c6873efd2e3f8c74b9e153fa94d9b09bd552b72d2413297139eb467332a07f42704e66ab8d12a22e94c13687f0b481b8af6
|
7
|
+
data.tar.gz: ae1d1cae273f5c1ff2b69ab3661bde87cda118221e27995db3b27dac89fa2ed470b70e37628fff7236b7fdf3996be016e84dc17c0221749f9b0d9fe547e48c4f
|
data/lib/site-object/page.rb
CHANGED
@@ -81,7 +81,7 @@ module PageObject
|
|
81
81
|
# If the visit method is called on the page a SiteObject::PageNavigationNotAllowedError
|
82
82
|
# will be raised.
|
83
83
|
def disable_automatic_navigation
|
84
|
-
puts "
|
84
|
+
puts "The disable_automatic_navigation method is deprecated and will be removed in a future release. Use the set_attributes method in place of this one in the class definition. See documentation for more details."
|
85
85
|
@page_attributes ||= []
|
86
86
|
@page_attributes << :navigation_disabled
|
87
87
|
@navigation_disabled = true
|
@@ -264,17 +264,11 @@ module PageObject
|
|
264
264
|
end
|
265
265
|
|
266
266
|
def set_url_template(base_url)
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
@url_template = Addressable::Template.new(@page_url)
|
273
|
-
else
|
274
|
-
@url_template = Addressable::Template.new(Addressable::URI.parse("#{base_url}#{@page_url}"))
|
275
|
-
end
|
276
|
-
rescue Addressable::URI::InvalidURIError => e
|
277
|
-
raise SiteObject::PageInitError, "Unable to initialize #{self.class} because there's no base_url defined for the site and the page object URL that was defined was a URL fragment (#{@page_url})\n\n#{caller.join("\n")}"
|
267
|
+
case @page_url
|
268
|
+
when /(http:\/\/|https:\/\/)/i
|
269
|
+
@url_template = Addressable::Template.new(@page_url)
|
270
|
+
else
|
271
|
+
@url_template = Addressable::Template.new(Addressable::URI.parse("#{base_url}#{@page_url}"))
|
278
272
|
end
|
279
273
|
end
|
280
274
|
|
@@ -324,7 +318,7 @@ module PageObject
|
|
324
318
|
# There's no need to ever call this directly. Initializes a page object within the context of a
|
325
319
|
# site object. Takes a site object and a hash of configuration arguments. The site object will
|
326
320
|
# handle all of this for you.
|
327
|
-
def initialize(site, args=
|
321
|
+
def initialize(site, args=nil)
|
328
322
|
@browser = site.browser
|
329
323
|
@page_attributes = self.class.page_attributes
|
330
324
|
@page_url = self.class.page_url
|
@@ -337,13 +331,21 @@ module PageObject
|
|
337
331
|
|
338
332
|
# Try to expand the URL template if the URL has parameters.
|
339
333
|
@arguments = {}.with_indifferent_access # Stores the param list that will expand the url_template after examining the arguments used to initialize the page.
|
340
|
-
if @required_arguments.
|
341
|
-
|
342
|
-
|
334
|
+
if @required_arguments.present? && !args
|
335
|
+
@required_arguments.each do |arg|
|
336
|
+
if @site.respond_to?(arg)
|
337
|
+
@arguments[arg]= site.send(arg)
|
338
|
+
else
|
339
|
+
raise SiteObject::PageInitError, "No arguments provided when attempting to initialize #{self.class.name}. This page object requires the following arguments for initialization: :#{@required_arguments.join(', :')}.\n\n#{caller.join("\n")}"
|
340
|
+
end
|
341
|
+
end
|
342
|
+
elsif @required_arguments.present?
|
343
343
|
@required_arguments.each do |arg| # Try to extract each URL argument from the hash or object provided, OR from the site object.
|
344
|
-
if args.is_a?(Hash) &&
|
345
|
-
|
346
|
-
|
344
|
+
if args.is_a?(Hash) && args.present?
|
345
|
+
args = args.with_indifferent_access
|
346
|
+
|
347
|
+
if args[arg] #The hash has the required argument.
|
348
|
+
@arguments[arg]= args[arg]
|
347
349
|
elsif @site.respond_to?(arg)
|
348
350
|
@arguments[arg]= site.send(arg)
|
349
351
|
else
|
@@ -358,16 +360,15 @@ module PageObject
|
|
358
360
|
raise SiteObject::PageInitError, "#{args.class} was provided, but this object did not respond to :#{arg}, which is necessary to build an URL for the #{self.class.name} page.\n\n#{caller.join("\n")}"
|
359
361
|
end
|
360
362
|
else
|
361
|
-
|
363
|
+
# No need to do anything here.
|
362
364
|
end
|
363
365
|
end
|
364
|
-
elsif @required_arguments.
|
365
|
-
|
366
|
-
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")}"
|
367
|
-
end
|
366
|
+
elsif @required_arguments.empty? && args # If there are no required arguments then nothing should be provided.
|
367
|
+
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")}"
|
368
368
|
else
|
369
369
|
# Do nothing here.
|
370
370
|
end
|
371
|
+
|
371
372
|
@url = @url_template.expand(@arguments).to_s
|
372
373
|
@page_features ||= []
|
373
374
|
@page_features.each do |arg|
|
@@ -388,11 +389,7 @@ module PageObject
|
|
388
389
|
@site.most_recent_page = self
|
389
390
|
unless on_page?
|
390
391
|
if navigation_disabled?
|
391
|
-
|
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")}"
|
393
|
-
else
|
394
|
-
raise SiteObject::PageNavigationNotAllowedError, "The #{self.class.name} page could not be accessed. Navigation is intentionally disabled for this page and the page that the browser was displaying could not be recognized.\n\nPAGE URL:\n------------\n#{@site.browser.url}\n\nPAGE TEXT:\n------------\n#{@site.browser.text}\n\n#{caller.join("\n")}"
|
395
|
-
end
|
392
|
+
raise SiteObject::PageNavigationNotAllowedError, "Navigation is intentionally disabled for the #{self.class.name} page. You can only call the accessor method for this page when it's already being displayed in the browser.\n\nCurrent URL:\n------------\n#{@site.browser.url}\n\n#{caller.join("\n")}"
|
396
393
|
end
|
397
394
|
visit
|
398
395
|
end
|
@@ -427,9 +424,21 @@ module PageObject
|
|
427
424
|
# you can use the alternate method to specify how to match the page.
|
428
425
|
def on_page?
|
429
426
|
if @url_template.pattern =~ /#/ # It has a URL fragment. Don't mess with the browser URL.
|
430
|
-
|
427
|
+
if @browser.is_a? Watir::Browser
|
428
|
+
url = @browser.url
|
429
|
+
elsif @browser.is_a? Selenium::WebDriver::Driver
|
430
|
+
url = @browser.current_url
|
431
|
+
else
|
432
|
+
raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
|
433
|
+
end
|
431
434
|
else # There's no fragment in the URL template, strip the fragment out of the URL so that template matching works better.
|
432
|
-
|
435
|
+
if @browser.is_a? Watir::Browser
|
436
|
+
url = @browser.url.split('#')[0]
|
437
|
+
elsif @browser.is_a? Selenium::WebDriver::Driver
|
438
|
+
url = @browser.current_url.split('#')[0]
|
439
|
+
else
|
440
|
+
raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
|
441
|
+
end
|
433
442
|
end
|
434
443
|
|
435
444
|
if @url_matcher && @url_matcher =~ url
|
data/lib/site-object/site.rb
CHANGED
@@ -7,8 +7,6 @@ module SiteObject
|
|
7
7
|
attr_reader :base_url, :unique_methods
|
8
8
|
attr_accessor :pages, :browser, :arguments, :most_recent_page
|
9
9
|
|
10
|
-
include SiteObjectExceptions
|
11
|
-
|
12
10
|
# Sets up a Page class when the SiteObject module is included in the class you're using to model
|
13
11
|
# your site.
|
14
12
|
def self.included(base)
|
@@ -91,7 +89,7 @@ module SiteObject
|
|
91
89
|
end
|
92
90
|
|
93
91
|
self.class.class_eval do
|
94
|
-
define_method(current_page.to_s.underscore) do |args=
|
92
|
+
define_method(current_page.to_s.underscore) do |args=nil, block=nil|
|
95
93
|
current_page.new(self, args)
|
96
94
|
end
|
97
95
|
|
@@ -164,7 +162,13 @@ module SiteObject
|
|
164
162
|
# site.on_page? AccountSummaryPage
|
165
163
|
# =>true
|
166
164
|
def on_page?(page_arg)
|
167
|
-
|
165
|
+
if @browser.is_a? Watir::Browser
|
166
|
+
url = @browser.url
|
167
|
+
elsif @browser.is_a? Selenium::WebDriver::Driver
|
168
|
+
url = @browser.current_url
|
169
|
+
else
|
170
|
+
raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
|
171
|
+
end
|
168
172
|
|
169
173
|
if page_arg.url_matcher && page_arg.url_matcher =~ url
|
170
174
|
return true
|
@@ -197,13 +201,19 @@ module SiteObject
|
|
197
201
|
def page
|
198
202
|
return @most_recent_page if @most_recent_page && @most_recent_page.on_page?
|
199
203
|
|
200
|
-
|
201
|
-
|
204
|
+
if @browser.is_a? Watir::Browser
|
205
|
+
url = @browser.url
|
206
|
+
elsif @browser.is_a? Selenium::WebDriver::Driver
|
207
|
+
url = @browser.current_url
|
208
|
+
else
|
209
|
+
raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
|
210
|
+
end
|
202
211
|
|
212
|
+
found_page = nil
|
203
213
|
@pages.each do |p|
|
204
|
-
if p.
|
214
|
+
if p.url_matcher && p.url_matcher =~ url
|
205
215
|
found_page = p
|
206
|
-
elsif p.
|
216
|
+
elsif p.url_template.match url
|
207
217
|
found_page = p
|
208
218
|
end
|
209
219
|
|
data/lib/site-object/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.1
|
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-11-
|
11
|
+
date: 2015-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|