Class: SitePrism::Page
Class Attribute Summary collapse
Attributes included from Loadable
#load_error, #loaded
Class Method Summary
collapse
Instance Method Summary
collapse
included
Methods included from Loadable
included, #loaded?, #when_loaded
#all_there?, #elements_present
Class Attribute Details
.url ⇒ Object
Returns the value of attribute url.
13
14
15
|
# File 'lib/site_prism/page.rb', line 13
def url
@url
end
|
Class Method Details
.set_url(page_url) ⇒ Object
15
16
17
|
# File 'lib/site_prism/page.rb', line 15
def set_url(page_url)
@url = page_url.to_s
end
|
.set_url_matcher(page_url_matcher) ⇒ Object
19
20
21
|
# File 'lib/site_prism/page.rb', line 19
def set_url_matcher(page_url_matcher)
@url_matcher = page_url_matcher
end
|
.url_matcher ⇒ Object
23
24
25
|
# File 'lib/site_prism/page.rb', line 23
def url_matcher
@url_matcher ||= url
end
|
Instance Method Details
#displayed?(*args) ⇒ Boolean
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/site_prism/page.rb', line 59
def displayed?(*args)
expected_mappings = args.last.is_a?(::Hash) ? args.pop : {}
seconds = !args.empty? ? args.first : Capybara.default_max_wait_time
raise SitePrism::NoUrlMatcherForPageError unless url_matcher
begin
Waiter.wait_until_true(seconds) { url_matches?(expected_mappings) }
rescue SitePrism::TimeoutError
false
end
end
|
#load(expansion_or_html = {}, &block) ⇒ Object
Loads the page. The page will yield the block if defined.
Executes the block, if given. Runs load validations on the page, unless input is a string
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/site_prism/page.rb', line 44
def load(expansion_or_html = {}, &block)
self.loaded = false
if expansion_or_html.is_a?(String)
@page = Capybara.string(expansion_or_html)
yield self if block_given?
else
expanded_url = url(expansion_or_html)
raise SitePrism::NoUrlForPageError unless expanded_url
visit expanded_url
when_loaded(&block) if block_given?
end
end
|
#page ⇒ Object
When instantiating the page. A default validation will be added to all validations you define and add to the Page Class. When calling #load, all of the validations that are set will be ran in order, with the default “displayed?” validation being ran FIRST
33
34
35
|
# File 'lib/site_prism/page.rb', line 33
def page
@page ||= Capybara.current_session
end
|
#secure? ⇒ Boolean
91
92
93
|
# File 'lib/site_prism/page.rb', line 91
def secure?
page.current_url.start_with?('https')
end
|
#url(expansion = {}) ⇒ Object
81
82
83
84
85
|
# File 'lib/site_prism/page.rb', line 81
def url(expansion = {})
return nil if self.class.url.nil?
Addressable::Template.new(self.class.url).expand(expansion).to_s
end
|
#url_matcher ⇒ Object
87
88
89
|
# File 'lib/site_prism/page.rb', line 87
def url_matcher
self.class.url_matcher
end
|
#url_matches(seconds = Capybara.default_max_wait_time) ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/site_prism/page.rb', line 71
def url_matches(seconds = Capybara.default_max_wait_time)
return unless displayed?(seconds)
if url_matcher.is_a?(Regexp)
regexp_backed_matches
else
template_backed_matches
end
end
|