class EDSL::PageObject::Page
This class represents an entire page within the browser.
Using this base class is not a requirement, however code in some modules may assume that methods in this class are available when they're dealing with pages
This allows your object to serve as a proxy for the browser and mirror it's API.
Attributes
page_ready_limit[RW]
Public Class Methods
new(web_browser, visit = false)
click to toggle source
Create a new page.
Calls superclass method
# File lib/edsl/page_object/page.rb, line 22 def initialize(web_browser, visit = false) super(web_browser, nil) @page_ready_limit = DEFAULT_PAGE_READY_LIMIT goto if visit end
Public Instance Methods
ready?()
click to toggle source
An always safe to call ready function. Subclasses should implement the _ready? method to provide an actual implementation.
# File lib/edsl/page_object/page.rb, line 30 def ready? return _ready? rescue return false end
when_ready(limit = nil) { |self| ... }
click to toggle source
Block until the page is ready then yield / return self.
If a block is given the page will be yielded to it.
# File lib/edsl/page_object/page.rb, line 40 def when_ready(limit = nil, &block) begin Watir::Wait.until(timeout: (limit || page_ready_limit)) { _ready? } rescue Timeout::Error raise Timeout::Error, "Timeout limit #{limit} reached waiting for #{self.class} to be ready" end yield self if block_given? self end
Private Instance Methods
_ready?()
click to toggle source
Subclasses should override this with something that checks the state of the page.
# File lib/edsl/page_object/page.rb, line 53 def _ready? true end
leave_page_using(method, expected_url = nil)
click to toggle source
# File lib/edsl/page_object/page.rb, line 57 def leave_page_using(method, expected_url = nil) cur_url = browser.url method.call if method.is_a?(Proc) send(method) unless method.is_a?(Proc) Watir::Wait.until { expected_url ? browser.url == expected_url : browser.url != cur_url } end