Class: SitePrism::Page
- Inherits:
-
Object
- Object
- SitePrism::Page
- Extended by:
- ElementContainer
- Includes:
- Capybara::DSL, ElementChecker
- Defined in:
- lib/site_prism/page.rb
Overview
Subclasses of Page represent pages in your app.
class Home < SitePrism::Page
end
The above is an example of how to make a class representing the home page. There are a number of properties that can be set on a page - here is an example of a more fully spec’ed out page:
class Home < SitePrism::Page
set_url "/"
set_url_matcher /\/home.htm$/
end
Class Method Summary collapse
-
.set_url(page_url) ⇒ Object
Set the url associated with this page.
-
.set_url_matcher(page_url_matcher) ⇒ Object
Set the url matcher associated with this page.
-
.url ⇒ String
Get the url associated with this page.
-
.url_matcher ⇒ Regexp
Get the url matcher associated with this page.
Instance Method Summary collapse
-
#displayed? ⇒ Boolean
Checks to see if we’re on this page or not.
-
#load ⇒ Object
Visits the url associated with this page.
-
#title ⇒ String?
Gets the title of the current page.
-
#url ⇒ Object
Get the url associated with this page.
-
#url_matcher ⇒ Object
Get the url matcher associated with this page.
Methods included from ElementContainer
add_element_name, element, element_names, elements, section, sections
Methods included from ElementChecker
Class Method Details
.set_url(page_url) ⇒ Object
Set the url associated with this page
46 47 48 |
# File 'lib/site_prism/page.rb', line 46 def self.set_url page_url @url = page_url end |
.set_url_matcher(page_url_matcher) ⇒ Object
Set the url matcher associated with this page
56 57 58 |
# File 'lib/site_prism/page.rb', line 56 def self.set_url_matcher page_url_matcher @url_matcher = page_url_matcher end |
.url ⇒ String
Get the url associated with this page
63 64 65 |
# File 'lib/site_prism/page.rb', line 63 def self.url @url end |
.url_matcher ⇒ Regexp
Get the url matcher associated with this page
70 71 72 |
# File 'lib/site_prism/page.rb', line 70 def self.url_matcher @url_matcher end |
Instance Method Details
#displayed? ⇒ Boolean
Checks to see if we’re on this page or not
35 36 37 38 |
# File 'lib/site_prism/page.rb', line 35 def displayed? raise SitePrism::NoUrlMatcherForPage if url_matcher.nil? !(page.current_url =~ url_matcher).nil? end |
#load ⇒ Object
Visits the url associated with this page
19 20 21 22 |
# File 'lib/site_prism/page.rb', line 19 def load raise SitePrism::NoUrlForPage if url.nil? visit url end |
#title ⇒ String?
Gets the title of the current page
88 89 90 91 |
# File 'lib/site_prism/page.rb', line 88 def title title_selector = 'html > head > title' using_wait_time(0) { page.find(title_selector).text if page.has_selector?(title_selector) } end |
#url ⇒ Object
Get the url associated with this page
76 77 78 |
# File 'lib/site_prism/page.rb', line 76 def url self.class.url end |
#url_matcher ⇒ Object
Get the url matcher associated with this page
82 83 84 |
# File 'lib/site_prism/page.rb', line 82 def url_matcher self.class.url_matcher end |