Class: Howitzer::Web::Page
- Inherits:
-
Object
- Object
- Howitzer::Web::Page
- Includes:
- CapybaraMethodsProxy, ElementDsl, IframeDsl, PageDsl, PageValidator, SectionDsl, RSpec::Matchers, Singleton
- Defined in:
- lib/howitzer/web/page.rb
Overview
This class represents a single web page. This is a parent class for all web pages
Direct Known Subclasses
Constant Summary collapse
- UnknownPage =
:nodoc:
Class.new
Constants included from CapybaraMethodsProxy
CapybaraMethodsProxy::PROXIED_CAPYBARA_METHODS
Class Method Summary collapse
-
.current_page ⇒ String
Tries to identify current page name or raise the error if ambiguous page matching.
-
.current_url ⇒ String
Current page url from browser.
-
.displayed?(timeout = Howitzer.page_load_idle_timeout) ⇒ Boolean
Waits until a web page is opened.
-
.expanded_url(params = {}, url_processor = nil) ⇒ String
Returns an expanded page url for the page opening.
-
.given ⇒ Page
Returns a singleton instance of the web page.
-
.inherited(subclass) ⇒ Object
This Ruby callback makes all inherited classes as singleton classes.
-
.open(validate: true, url_processor: nil, **params) ⇒ Page
Opens a web page in browser.
-
.path(value) ⇒ Object
DSL to specify an relative path pattern for the page opening.
-
.site(value) ⇒ Object
DSL to specify a site for the page opening.
Instance Method Summary collapse
-
#initialize ⇒ Page
constructor
A new instance of Page.
-
#reload ⇒ Object
Reloads current page in a browser.
Methods included from PageValidator
#check_validations_are_defined!, included, validations
Methods included from SectionDsl
Methods included from CapybaraContextHolder
Methods included from PageDsl
Methods included from IframeDsl
Methods included from ElementDsl
Methods included from CapybaraMethodsProxy
Constructor Details
#initialize ⇒ Page
Returns a new instance of Page.
153 154 155 156 |
# File 'lib/howitzer/web/page.rb', line 153 def initialize check_validations_are_defined! current_window.maximize if Howitzer.maximized_window end |
Class Method Details
.current_page ⇒ String
Tries to identify current page name or raise the error if ambiguous page matching
62 63 64 65 66 67 |
# File 'lib/howitzer/web/page.rb', line 62 def self.current_page page_list = matched_pages return UnknownPage if page_list.count.zero? return page_list.first if page_list.count == 1 raise Howitzer::AmbiguousPageMatchingError, ambiguous_page_msg(page_list) end |
.current_url ⇒ String
Returns current page url from browser.
85 86 87 |
# File 'lib/howitzer/web/page.rb', line 85 def self.current_url .current_session.current_url end |
.displayed?(timeout = Howitzer.page_load_idle_timeout) ⇒ Boolean
Waits until a web page is opened
74 75 76 77 78 79 80 81 |
# File 'lib/howitzer/web/page.rb', line 74 def self.displayed?(timeout = Howitzer.page_load_idle_timeout) end_time = ::Time.now + timeout until ::Time.now > end_time return true if opened? sleep(0.5) end raise Howitzer::IncorrectPageError, incorrect_page_msg end |
.expanded_url(params = {}, url_processor = nil) ⇒ String
Returns an expanded page url for the page opening
95 96 97 98 99 100 |
# File 'lib/howitzer/web/page.rb', line 95 def self.(params = {}, url_processor = nil) if defined?(path_value) return "#{site_value}#{Addressable::Template.new(path_value).expand(params, url_processor)}" end raise Howitzer::NoPathForPageError, "Please specify path for '#{self}' page. Example: path '/home'" end |
.given ⇒ Page
Returns a singleton instance of the web page
52 53 54 55 |
# File 'lib/howitzer/web/page.rb', line 52 def self.given displayed? instance end |
.inherited(subclass) ⇒ Object
This Ruby callback makes all inherited classes as singleton classes.
28 29 30 |
# File 'lib/howitzer/web/page.rb', line 28 def self.inherited(subclass) subclass.class_eval { include Singleton } end |
.open(validate: true, url_processor: nil, **params) ⇒ Page
It tries to open the page twice and then raises the error if a validation is failed
Opens a web page in browser
39 40 41 42 43 44 45 46 47 |
# File 'lib/howitzer/web/page.rb', line 39 def self.open(validate: true, url_processor: nil, **params) url = (params, url_processor) Howitzer::Log.info "Open #{name} page by '#{url}' url" retryable(tries: 2, logger: Howitzer::Log, trace: true, on: Exception) do |retries| Howitzer::Log.info 'Retry...' unless retries.zero? .current_session.visit(url) end given if validate end |
.path(value) ⇒ Object
DSL to specify an relative path pattern for the page opening
115 116 117 118 |
# File 'lib/howitzer/web/page.rb', line 115 def path(value) define_singleton_method(:path_value) { value.to_s } private_class_method :path_value end |
.site(value) ⇒ Object
By default it specifies Howitzer.app_uri.site as a site
DSL to specify a site for the page opening
133 134 135 136 |
# File 'lib/howitzer/web/page.rb', line 133 def site(value) define_singleton_method(:site_value) { value } private_class_method :site_value end |
Instance Method Details
#reload ⇒ Object
Reloads current page in a browser
160 161 162 163 |
# File 'lib/howitzer/web/page.rb', line 160 def reload Howitzer::Log.info "Reload '#{current_url}'" visit current_url end |