Class: Undead::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/undead/browser.rb

Constant Summary collapse

ERROR_MAPPINGS =
{
  'Poltergeist.JavascriptError'   => Undead::JavascriptError,
  'Poltergeist.FrameNotFound'     => Undead::FrameNotFound,
  'Poltergeist.InvalidSelector'   => Undead::InvalidSelector,
  'Poltergeist.StatusFailError'   => Undead::StatusFailError,
  'Poltergeist.NoSuchWindowError' => Undead::NoSuchWindowError,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, client, logger = nil) ⇒ Browser

Returns a new instance of Browser.



18
19
20
21
22
# File 'lib/undead/browser.rb', line 18

def initialize(server, client, logger = nil)
  @server = server
  @client = client
  @logger = logger
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



16
17
18
# File 'lib/undead/browser.rb', line 16

def client
  @client
end

#loggerObject (readonly)

Returns the value of attribute logger.



16
17
18
# File 'lib/undead/browser.rb', line 16

def logger
  @logger
end

#serverObject (readonly)

Returns the value of attribute server.



16
17
18
# File 'lib/undead/browser.rb', line 16

def server
  @server
end

Instance Method Details

#bodyObject



28
29
30
# File 'lib/undead/browser.rb', line 28

def body
  command 'body'
end

#command(name, *args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/undead/browser.rb', line 42

def command(name, *args)
  cmd = Undead::Command.new(name, *args)
  log cmd.message

  response = server.send(cmd)
  log response

  json = JSON.load(response)

  if json['error']
    klass = ERROR_MAPPINGS[json['error']['name']] || Undead::BrowserError
    raise klass.new(json['error'])
  else
    json['response']
  end
rescue Undead::DeadClient
  restart
  raise
end

#debug=(val) ⇒ Object



37
38
39
40
# File 'lib/undead/browser.rb', line 37

def debug=(val)
  @debug = val
  command 'set_debug', !!val
end

#js_errors=(val) ⇒ Object



32
33
34
35
# File 'lib/undead/browser.rb', line 32

def js_errors=(val)
  @js_errors = val
  command 'set_js_errors', !!val
end

#visit(url) ⇒ Object



24
25
26
# File 'lib/undead/browser.rb', line 24

def visit(url)
  command 'visit', url
end