lib/capybara/poltergeist/browser.rb in poltergeist-1.6.0 vs lib/capybara/poltergeist/browser.rb in poltergeist-1.7.0

- old
+ new

@@ -22,11 +22,13 @@ def restart server.restart client.restart - self.debug = @debug if @debug + self.debug = @debug if defined?(@debug) + self.js_errors = @js_errors if defined?(@js_errors) + self.extensions = @extensions if @extensions end def visit(url) command 'visit', url end @@ -181,10 +183,14 @@ def drag(page_id, id, other_id) command 'drag', page_id, id, other_id end + def drag_by(page_id, id, x, y) + command 'drag_by', page_id, id, x, y + end + def select(page_id, id, value) command 'select', page_id, id, value end def trigger(page_id, id, event) @@ -223,10 +229,14 @@ def send_keys(page_id, id, keys) command 'send_keys', page_id, id, normalize_keys(keys) end + def path(page_id, id) + command 'path', page_id, id + end + def network_traffic command('network_traffic').values.map do |event| NetworkTraffic::Request.new( event['request'], event['responseParts'].map { |response| NetworkTraffic::Response.new(response) } @@ -289,14 +299,16 @@ def set_http_auth(user, password) command 'set_http_auth', user, password end def js_errors=(val) + @js_errors = val command 'set_js_errors', !!val end def extensions=(names) + @extensions = names Array(names).each do |name| command 'add_extension', name end end @@ -335,10 +347,36 @@ def go_forward command 'go_forward' end + def accept_confirm + command 'set_confirm_process', true + end + + def dismiss_confirm + command 'set_confirm_process', false + end + + # + # press "OK" with text (response) or default value + # + def accept_prompt(response) + command 'set_prompt_response', response || false + end + + # + # press "Cancel" + # + def dismiss_prompt + command 'set_prompt_response', nil + end + + def modal_message + command 'modal_message' + end + private def log(message) logger.puts message if logger end @@ -352,14 +390,18 @@ def normalize_keys(keys) keys.map do |key| case key when Array - # String itself with modifiers like :alt, :shift, etc - raise Error, 'PhantomJS behaviour for key modifiers is currently ' \ - 'broken, we will add this in later versions' + # [:Shift, "s"] => { modifier: "shift", key: "S" } + # [:Ctrl, :Left] => { modifier: "ctrl", key: :Left } + # [:Ctrl, :Shift, :Left] => { modifier: "ctrl,shift", key: :Left } + letter = key.pop + symbol = key.map { |k| k.to_s.downcase }.join(',') + + { modifier: symbol.to_s.downcase, key: letter.capitalize } when Symbol - { key: key } # Return a known sequence for PhantomJS + { key: key.capitalize } # Return a known sequence for PhantomJS when String key # Plain string, nothing to do end end end