Class: SitePrism::Page

Inherits:
Object
  • Object
show all
Extended by:
ElementContainer
Includes:
Capybara::DSL, ElementChecker
Defined in:
lib/site_prism/page.rb

Instance Attribute Summary

Attributes included from ElementContainer

#mapped_items

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ElementContainer

add_to_mapped_items, element, elements, iframe, raise_if_block, section, sections

Methods included from ElementChecker

#all_there?

Class Method Details

.set_url(page_url) ⇒ Object


50
51
52
# File 'lib/site_prism/page.rb', line 50

def self.set_url(page_url)
  @url = page_url.to_s
end

.set_url_matcher(page_url_matcher) ⇒ Object


54
55
56
# File 'lib/site_prism/page.rb', line 54

def self.set_url_matcher(page_url_matcher)
  @url_matcher = page_url_matcher
end

.urlObject


58
59
60
# File 'lib/site_prism/page.rb', line 58

def self.url
  @url
end

.url_matcherObject


62
63
64
# File 'lib/site_prism/page.rb', line 62

def self.url_matcher
  @url_matcher || url
end

Instance Method Details

#displayed?(*args) ⇒ Boolean


21
22
23
24
25
26
27
28
29
30
# File 'lib/site_prism/page.rb', line 21

def displayed?(*args)
  expected_mappings = args.last.is_a?(::Hash) ? args.pop : {}
  seconds = args.length > 0 ? args.first : Waiter.default_wait_time
  fail SitePrism::NoUrlMatcherForPage if url_matcher.nil?
  begin
    Waiter.wait_until_true(seconds) { url_matches?(expected_mappings) }
  rescue SitePrism::TimeoutException
    false
  end
end

#load(expansion_or_html = {}) ⇒ Object


11
12
13
14
15
16
17
18
19
# File 'lib/site_prism/page.rb', line 11

def load(expansion_or_html = {})
  if expansion_or_html.is_a? String
    @page = Capybara.string(expansion_or_html)
  else
    expanded_url = url(expansion_or_html)
    fail SitePrism::NoUrlForPage if expanded_url.nil?
    visit expanded_url
  end
end

#pageObject


7
8
9
# File 'lib/site_prism/page.rb', line 7

def page
  @page || Capybara.current_session
end

#regexp_backed_matchesObject


42
43
44
# File 'lib/site_prism/page.rb', line 42

def regexp_backed_matches
  url_matcher.match(page.current_url)
end

#secure?Boolean


75
76
77
# File 'lib/site_prism/page.rb', line 75

def secure?
  !current_url.match(/^https/).nil?
end

#template_backed_matchesObject


46
47
48
# File 'lib/site_prism/page.rb', line 46

def template_backed_matches
  matcher_template.mappings(page.current_url)
end

#url(expansion = {}) ⇒ Object


66
67
68
69
# File 'lib/site_prism/page.rb', line 66

def url(expansion = {})
  return nil if self.class.url.nil?
  Addressable::Template.new(self.class.url).expand(expansion).to_s
end

#url_matcherObject


71
72
73
# File 'lib/site_prism/page.rb', line 71

def url_matcher
  self.class.url_matcher
end

#url_matches(seconds = Waiter.default_wait_time) ⇒ Object


32
33
34
35
36
37
38
39
40
# File 'lib/site_prism/page.rb', line 32

def url_matches(seconds = Waiter.default_wait_time)
  return unless displayed?(seconds)

  if url_matcher.is_a?(Regexp)
    regexp_backed_matches
  else
    template_backed_matches
  end
end