lib/capybara/poltergeist/browser.rb in poltergeist-1.3.0 vs lib/capybara/poltergeist/browser.rb in poltergeist-1.4.0

- old
+ new

@@ -1,7 +1,7 @@ require "capybara/poltergeist/errors" -require 'json' +require 'multi_json' require 'time' module Capybara::Poltergeist class Browser ERROR_MAPPINGS = { @@ -116,10 +116,14 @@ yield ensure command 'pop_frame' end + def window_handles + command 'pages' + end + def within_window(name, &block) command 'push_window', name yield ensure command 'pop_window' @@ -151,14 +155,24 @@ def reset command 'reset' end + def scroll_to(left, top) + command 'scroll_to', left, top + end + def render(path, options = {}) - command 'render', path.to_s, !!options[:full] + check_render_options!(options) + command 'render', path.to_s, !!options[:full], options[:selector] end + def render_base64(format, options = {}) + check_render_options!(options) + command 'render_base64', format.to_s, !!options[:full], options[:selector] + end + def resize(width, height) command 'resize', width, height end def network_traffic @@ -172,14 +186,26 @@ def equals(page_id, id, other_id) command('equals', page_id, id, other_id) end + def get_headers + command 'get_headers' + end + def set_headers(headers) command 'set_headers', headers end + def add_headers(headers) + command 'add_headers', headers + end + + def add_header(header, permanent) + command 'add_header', header, permanent + end + def response_headers command 'response_headers' end def cookies @@ -219,11 +245,11 @@ def command(name, *args) message = { 'name' => name, 'args' => args } log message.inspect - json = JSON.load(server.send(JSON.generate(message))) + json = JSON.load(server.send(JSON.dump(message))) log json.inspect if json['error'] klass = ERROR_MAPPINGS[json['error']['name']] || BrowserError raise klass.new(json['error']) @@ -237,8 +263,15 @@ private def log(message) logger.puts message if logger + end + + def check_render_options!(options) + if !!options[:full] && options.has_key?(:selector) + warn "Ignoring :selector in #render since :full => true was given at #{caller.first}" + options.delete(:selector) + end end end end