lib/capybara/poltergeist/browser.rb in poltergeist-1.0.3 vs lib/capybara/poltergeist/browser.rb in poltergeist-1.1.0
- old
+ new
@@ -1,22 +1,23 @@
-require 'multi_json'
+require 'json'
require 'time'
module Capybara::Poltergeist
class Browser
- attr_reader :server, :client, :logger, :js_errors
+ attr_reader :server, :client, :logger
- def initialize(server, client, logger = nil, js_errors = true)
- @server = server
- @client = client
- @logger = logger
- @js_errors = js_errors
+ def initialize(server, client, logger = nil)
+ @server = server
+ @client = client
+ @logger = logger
end
def restart
server.restart
client.restart
+
+ self.debug = @debug if @debug
end
def visit(url)
command 'visit', url
end
@@ -72,10 +73,14 @@
def visible?(page_id, id)
command 'visible', page_id, id
end
+ def click_coordinates(x, y)
+ command 'click_coordinates', x, y
+ end
+
def evaluate(script)
command 'evaluate', script
end
def execute(script)
@@ -98,10 +103,14 @@
def click(page_id, id)
command 'click', page_id, id
end
+ def double_click(page_id, id)
+ command 'double_click', page_id, id
+ end
+
def drag(page_id, id, other_id)
command 'drag', page_id, id, other_id
end
def select(page_id, id, value)
@@ -148,35 +157,45 @@
def cookies
Hash[command('cookies').map { |cookie| [cookie['name'], Cookie.new(cookie)] }]
end
def set_cookie(cookie)
- if cookie[:expires].respond_to?(:httpdate)
- cookie[:expires] = cookie[:expires].httpdate
+ if cookie[:expires]
+ cookie[:expires] = cookie[:expires].to_i * 1000
end
command 'set_cookie', cookie
end
def remove_cookie(name)
command 'remove_cookie', name
end
+ def js_errors=(val)
+ command 'set_js_errors', !!val
+ end
+
+ def extensions=(names)
+ Array(names).each do |name|
+ command 'add_extension', name
+ end
+ end
+
+ def debug=(val)
+ @debug = val
+ command 'set_debug', !!val
+ end
+
def command(name, *args)
message = { 'name' => name, 'args' => args }
log message.inspect
- json = JSON.load(server.send(JSON.dump(message)))
+ json = JSON.load(server.send(JSON.generate(message)))
log json.inspect
if json['error']
if json['error']['name'] == 'Poltergeist.JavascriptError'
- error = JavascriptError.new(json['error'])
- if js_errors
- raise error
- else
- log error
- end
+ raise JavascriptError.new(json['error'])
else
raise BrowserError.new(json['error'])
end
end
json['response']