Class: Pincers::Core::RootContext

Inherits:
SearchContext show all
Defined in:
lib/pincers/core/root_context.rb

Constant Summary

Constants included from Extension::Queries

Extension::Queries::TEXT_INPUTS

Instance Attribute Summary collapse

Attributes inherited from SearchContext

#parent, #query

Instance Method Summary collapse

Methods inherited from SearchContext

#[], #[]=, #attribute, #click, #double_click, #drag_to, #each, #element!, #first, #first!, #frozen?, #hover, #last, #reload, #replicate, #right_click, #search, #set_text, #submit, #tag, #text, #to_html, #wait, #wait?

Methods included from Extension::Labs

#readonly

Methods included from Extension::Actions

#set

Methods included from Extension::Queries

#checked, #classes, #id, #input_mode, #selected, #value

Constructor Details

#initialize(_backend, _config = {}) ⇒ RootContext

Returns a new instance of RootContext.



10
11
12
13
14
# 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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/pincers/core/root_context.rb', line 8

def config
  @config
end

Instance Method Details

#advanced_mode?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/pincers/core/root_context.rb', line 101

def advanced_mode?
  @config[:advanced_mode]
end

#as_http_client(&_block) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# 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) ⇒ Object



78
79
80
81
# File 'lib/pincers/core/root_context.rb', line 78

def back(_steps=1)
  wrap_errors { backend.navigate_back _steps }
  self
end

#backendObject



36
37
38
# File 'lib/pincers/core/root_context.rb', line 36

def backend
  @backend
end

#closeObject



88
89
90
91
# File 'lib/pincers/core/root_context.rb', line 88

def close
  wrap_errors { backend.close_document }
  self
end

#cookiesObject



52
53
54
# File 'lib/pincers/core/root_context.rb', line 52

def cookies
  @cookies ||= Cookies.new backend
end

#default_intervalObject



97
98
99
# File 'lib/pincers/core/root_context.rb', line 97

def default_interval
  @config[:wait_interval]
end

#default_timeoutObject



93
94
95
# File 'lib/pincers/core/root_context.rb', line 93

def default_timeout
  @config[:wait_timeout]
end

#documentObject



32
33
34
# File 'lib/pincers/core/root_context.rb', line 32

def document
  @backend.document
end

#download(_url) ⇒ Object



105
106
107
# File 'lib/pincers/core/root_context.rb', line 105

def download(_url)
  as_http_client.get(_url).document
end

#elementObject



28
29
30
# File 'lib/pincers/core/root_context.rb', line 28

def element
  @backend.document_root.first
end

#elementsObject



24
25
26
# File 'lib/pincers/core/root_context.rb', line 24

def elements
  @backend.document_root
end

#forward(_steps = 1) ⇒ Object



73
74
75
76
# File 'lib/pincers/core/root_context.rb', line 73

def forward(_steps=1)
  wrap_errors { backend.navigate_forward _steps }
  self
end

#goto(_urlOrOptions) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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

#refreshObject



83
84
85
86
# File 'lib/pincers/core/root_context.rb', line 83

def refresh
  wrap_errors { backend.refresh_document }
  self
end

#rootObject



16
17
18
# File 'lib/pincers/core/root_context.rb', line 16

def root
  self
end

#root?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/pincers/core/root_context.rb', line 20

def root?
  true
end

#titleObject



48
49
50
# File 'lib/pincers/core/root_context.rb', line 48

def title
  wrap_errors { backend.document_title }
end

#uriObject



44
45
46
# File 'lib/pincers/core/root_context.rb', line 44

def uri
  Pincers::Http::Utils.parse_uri url
end

#urlObject



40
41
42
# File 'lib/pincers/core/root_context.rb', line 40

def url
  wrap_errors { backend.document_url }
end