class Pincers::Core::RootContext
Attributes
config[R]
Public Class Methods
new(_backend, _config={})
click to toggle source
Calls superclass method
# File lib/pincers/core/root_context.rb, line 10 def initialize(_backend, _config={}) super nil, nil, nil @backend = _backend @config = Pincers.config.values.merge _config end
Public Instance Methods
advanced_mode?()
click to toggle source
# File lib/pincers/core/root_context.rb, line 101 def advanced_mode? @config[:advanced_mode] end
as_http_client(&_block)
click to toggle source
# File lib/pincers/core/root_context.rb, line 109 def as_http_client(&_block) http_client = backend.as_http_client unless _block.nil? r = _block.call http_client backend.merge_http_client http_client r else http_client end end
back(_steps=1)
click to toggle source
# File lib/pincers/core/root_context.rb, line 78 def back(_steps=1) wrap_errors { backend.navigate_back _steps } self end
backend()
click to toggle source
# File lib/pincers/core/root_context.rb, line 36 def backend @backend end
close()
click to toggle source
# File lib/pincers/core/root_context.rb, line 88 def close wrap_errors { backend.close_document } self end
default_interval()
click to toggle source
# File lib/pincers/core/root_context.rb, line 97 def default_interval @config[:wait_interval] end
default_timeout()
click to toggle source
# File lib/pincers/core/root_context.rb, line 93 def default_timeout @config[:wait_timeout] end
document()
click to toggle source
# File lib/pincers/core/root_context.rb, line 32 def document @backend.document end
download(_url)
click to toggle source
# File lib/pincers/core/root_context.rb, line 105 def download(_url) as_http_client.get(_url).document end
element()
click to toggle source
# File lib/pincers/core/root_context.rb, line 28 def element @backend.document_root.first end
elements()
click to toggle source
# File lib/pincers/core/root_context.rb, line 24 def elements @backend.document_root end
forward(_steps=1)
click to toggle source
# File lib/pincers/core/root_context.rb, line 73 def forward(_steps=1) wrap_errors { backend.navigate_forward _steps } self end
goto(_urlOrOptions)
click to toggle source
# File lib/pincers/core/root_context.rb, line 56 def goto(_urlOrOptions) wrap_errors do if _urlOrOptions.is_a? String _urlOrOptions = { url: _urlOrOptions } end if _urlOrOptions.key? :url goto_url _urlOrOptions[:url] elsif _urlOrOptions.key? :frame goto_frame _urlOrOptions[:frame] else raise ArgumentError.new "Must provide a valid target when calling 'goto'" end end self end
refresh()
click to toggle source
# File lib/pincers/core/root_context.rb, line 83 def refresh wrap_errors { backend.refresh_document } self end
root()
click to toggle source
# File lib/pincers/core/root_context.rb, line 16 def root self end
root?()
click to toggle source
# File lib/pincers/core/root_context.rb, line 20 def root? true end
title()
click to toggle source
# File lib/pincers/core/root_context.rb, line 48 def title wrap_errors { backend.document_title } end
uri()
click to toggle source
# File lib/pincers/core/root_context.rb, line 44 def uri Pincers::Http::Utils.parse_uri url end
url()
click to toggle source
# File lib/pincers/core/root_context.rb, line 40 def url wrap_errors { backend.document_url } end
Private Instance Methods
goto_frame(_frame)
click to toggle source
# File lib/pincers/core/root_context.rb, line 131 def goto_frame(_frame) case _frame when :top backend.switch_to_top_frame when :parent backend.switch_to_parent_frame when String backend.switch_to_frame search(_frame).element! when SearchContext backend.switch_to_frame _frame.element! else raise ArgumentError.new "Invalid :frame option #{_frame.inspect}" end end
goto_url(_url)
click to toggle source
# File lib/pincers/core/root_context.rb, line 127 def goto_url(_url) backend.navigate_to _url end
wrap_siblings(_elements)
click to toggle source
# File lib/pincers/core/root_context.rb, line 122 def wrap_siblings(_elements) # root node siblings behave like childs SearchContext.new _elements, self, nil end