Module: PageMagic::ClassMethods
- Defined in:
- lib/page_magic/class_methods.rb
Overview
module ClassMethods - contains class level methods for PageObjects
Constant Summary collapse
- DEFAULT_ON_LOAD =
Default block to be run when a page is loaded. This is used if a specific handler is not registered
proc {}
Instance Method Summary collapse
-
#load(source) ⇒ Object<InstanceMethods>
create an new page object instance based on top of the source supplied.
-
#on_load(&block) ⇒ Object
sets block to run when page has loaded if one has not been set on the page object class it will return a default block that does nothing.
-
#url(url = nil) ⇒ Object
getter setter for storing the page url.
-
#visit(application: nil, browser: :rack_test, options: {}) ⇒ Session
Visit this page based on the class level registered url.
Instance Method Details
#load(source) ⇒ Object<InstanceMethods>
create an new page object instance based on top of the source supplied
12 13 14 |
# File 'lib/page_magic/class_methods.rb', line 12 def load(source) new(Session.new(Capybara::Node::Simple.new(source))) end |
#on_load(&block) ⇒ Object
sets block to run when page has loaded if one has not been set on the page object class it will return a default block that does nothing
18 19 20 21 22 |
# File 'lib/page_magic/class_methods.rb', line 18 def on_load(&block) return @on_load || DEFAULT_ON_LOAD unless block @on_load = block end |
#url(url = nil) ⇒ Object
getter setter for storing the page url
26 27 28 29 |
# File 'lib/page_magic/class_methods.rb', line 26 def url(url = nil) @url = url if url @url end |
#visit(application: nil, browser: :rack_test, options: {}) ⇒ Session
Visit this page based on the class level registered url
36 37 38 39 40 41 42 43 |
# File 'lib/page_magic/class_methods.rb', line 36 def visit(application: nil, browser: :rack_test, options: {}) = { browser: browser, options: , url: url } [:application] = application if application PageMagic.session(**).tap do |session| session.visit(self, url: url) end end |