Class: SitePrism::Page
Overview
rubocop:disable Metrics/ClassLength
Class Attribute Summary collapse
Attributes included from Loadable
#load_error, #loaded
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from DSL
included
Methods included from Loadable
included, #loaded?, #when_loaded
#all_there?, #elements_present
Class Attribute Details
.url ⇒ Object
Returns the value of attribute url.
14
15
16
|
# File 'lib/site_prism/page.rb', line 14
def url
@url
end
|
Class Method Details
.set_url(page_url) ⇒ Object
16
17
18
|
# File 'lib/site_prism/page.rb', line 16
def set_url(page_url)
@url = page_url.to_s
end
|
.set_url_matcher(page_url_matcher) ⇒ Object
20
21
22
|
# File 'lib/site_prism/page.rb', line 20
def set_url_matcher(page_url_matcher)
@url_matcher = page_url_matcher
end
|
.url_matcher ⇒ Object
24
25
26
|
# File 'lib/site_prism/page.rb', line 24
def url_matcher
@url_matcher ||= url
end
|
Instance Method Details
#displayed?(*args) ⇒ Boolean
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/site_prism/page.rb', line 66
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
When calling #load, all the validations that are set will be ran in order
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/site_prism/page.rb', line 46
def load(expansion_or_html = {}, &block)
self.loaded = false
SitePrism.logger.debug("Reset loaded state on #{self.class}.")
return_yield = if expansion_or_html.is_a?(String)
load_html_string(expansion_or_html, &block)
else
load_html_website(expansion_or_html, &block)
end
self.loaded = true
SitePrism.logger.info("#{self.class} loaded.")
return_yield || true
end
|
#page ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/site_prism/page.rb', line 29
def page
if defined?(@page)
@page
else
Capybara.current_session
end
end
|
#secure? ⇒ Boolean
98
99
100
|
# File 'lib/site_prism/page.rb', line 98
def secure?
page.current_url.start_with?('https')
end
|
#url(expansion = {}) ⇒ Object
88
89
90
91
92
|
# File 'lib/site_prism/page.rb', line 88
def url(expansion = {})
return nil if self.class.url.nil?
Addressable::Template.new(self.class.url).expand(expansion).to_s
end
|
#url_matcher ⇒ Object
94
95
96
|
# File 'lib/site_prism/page.rb', line 94
def url_matcher
self.class.url_matcher
end
|
#url_matches(seconds = Capybara.default_max_wait_time) ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/site_prism/page.rb', line 78
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
|