Class: Undead::Browser
- Inherits:
-
Object
- Object
- Undead::Browser
- 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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #body ⇒ Object
- #command(name, *args) ⇒ Object
- #debug=(val) ⇒ Object
-
#initialize(server, client, logger = nil) ⇒ Browser
constructor
A new instance of Browser.
- #js_errors=(val) ⇒ Object
- #visit(url) ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
16 17 18 |
# File 'lib/undead/browser.rb', line 16 def client @client end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
16 17 18 |
# File 'lib/undead/browser.rb', line 16 def logger @logger end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
16 17 18 |
# File 'lib/undead/browser.rb', line 16 def server @server end |
Instance Method Details
#body ⇒ Object
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. 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 |