lib/capybara/poltergeist/browser.rb in poltergeist-1.7.0 vs lib/capybara/poltergeist/browser.rb in poltergeist-1.8.0
- old
+ new
@@ -1,6 +1,7 @@
require "capybara/poltergeist/errors"
+require "capybara/poltergeist/command"
require 'multi_json'
require 'time'
module Capybara::Poltergeist
class Browser
@@ -76,10 +77,14 @@
def delete_text(page_id, id)
command 'delete_text', page_id, id
end
+ def property(page_id, id, name)
+ command 'property', page_id, id, name.to_s
+ end
+
def attributes(page_id, id)
command 'attributes', page_id, id
end
def attribute(page_id, id, name)
@@ -122,11 +127,11 @@
command 'execute', script
end
def within_frame(handle, &block)
if handle.is_a?(Capybara::Node::Base)
- command 'push_frame', handle[:name] || handle[:id]
+ command 'push_frame', [handle.native.page_id, handle.native.id]
else
command 'push_frame', handle
end
yield
@@ -152,15 +157,21 @@
def close_window(handle)
command 'close_window', handle
end
- def within_window(name, &block)
+ def find_window_handle(locator)
+ return locator if window_handles.include? locator
+
+ handle = command 'window_handle', locator
+ raise noSuchWindowError unless handle
+ return handle
+ end
+
+ def within_window(locator, &block)
original = window_handle
- handle = command 'window_handle', name
- handle = name if handle.nil? && window_handles.include?(name)
- raise NoSuchWindowError unless handle
+ handle = find_window_handle(locator)
switch_to_window(handle)
yield
ensure
switch_to_window(original)
end
@@ -320,13 +331,13 @@
@debug = val
command 'set_debug', !!val
end
def command(name, *args)
- message = JSON.dump({ 'name' => name, 'args' => args })
- log message
+ cmd = Command.new(name, *args)
+ log cmd.message
- response = server.send(message)
+ response = server.send(cmd)
log response
json = JSON.load(response)
if json['error']