2011-02-18 22:53:06 -05:00
|
|
|
require "capybara"
|
2011-11-11 20:31:21 -05:00
|
|
|
require "capybara/driver/webkit/version"
|
2011-02-18 22:53:06 -05:00
|
|
|
require "capybara/driver/webkit/node"
|
2012-05-04 15:50:30 -04:00
|
|
|
require "capybara/driver/webkit/connection"
|
2011-02-18 22:53:06 -05:00
|
|
|
require "capybara/driver/webkit/browser"
|
2011-07-22 14:21:15 -04:00
|
|
|
require "capybara/driver/webkit/socket_debugger"
|
2011-10-06 06:13:06 -04:00
|
|
|
require "capybara/driver/webkit/cookie_jar"
|
2011-02-18 22:53:06 -05:00
|
|
|
|
|
|
|
class Capybara::Driver::Webkit
|
2011-07-12 15:31:10 -04:00
|
|
|
class WebkitInvalidResponseError < StandardError
|
|
|
|
end
|
|
|
|
|
|
|
|
class WebkitNoResponseError < StandardError
|
2011-02-24 23:22:56 -05:00
|
|
|
end
|
|
|
|
|
2011-09-30 17:13:54 -04:00
|
|
|
class NodeNotAttachedError < Capybara::ElementNotFound
|
|
|
|
end
|
|
|
|
|
2011-02-25 00:15:08 -05:00
|
|
|
attr_reader :browser
|
|
|
|
|
2011-02-18 22:53:06 -05:00
|
|
|
def initialize(app, options={})
|
|
|
|
@app = app
|
|
|
|
@options = options
|
|
|
|
@rack_server = Capybara::Server.new(@app)
|
|
|
|
@rack_server.boot if Capybara.run_server
|
2012-05-04 15:50:30 -04:00
|
|
|
@browser = options[:browser] || Browser.new(Connection.new(options))
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def current_url
|
2012-02-05 11:43:48 -05:00
|
|
|
browser.current_url
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
2011-11-15 21:11:37 -05:00
|
|
|
def requested_url
|
|
|
|
browser.requested_url
|
|
|
|
end
|
|
|
|
|
2011-02-18 22:53:06 -05:00
|
|
|
def visit(path)
|
2011-02-25 00:15:08 -05:00
|
|
|
browser.visit(url(path))
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def find(query)
|
2011-02-25 00:15:08 -05:00
|
|
|
browser.find(query).map { |native| Node.new(self, native) }
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def source
|
2011-02-25 18:04:23 -05:00
|
|
|
browser.source
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
2011-07-29 15:00:13 -04:00
|
|
|
browser.body
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
2011-06-08 05:36:45 -04:00
|
|
|
def header(key, value)
|
|
|
|
browser.header(key, value)
|
|
|
|
end
|
|
|
|
|
2011-02-18 22:53:06 -05:00
|
|
|
def execute_script(script)
|
2011-07-29 15:00:13 -04:00
|
|
|
value = browser.execute_script script
|
|
|
|
value.empty? ? nil : value
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def evaluate_script(script)
|
2011-02-26 13:02:43 -05:00
|
|
|
browser.evaluate_script script
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
2011-10-31 13:53:57 -04:00
|
|
|
def console_messages
|
|
|
|
browser.console_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_messages
|
|
|
|
browser.error_messages
|
|
|
|
end
|
|
|
|
|
2011-02-18 22:53:06 -05:00
|
|
|
def response_headers
|
2011-08-19 11:57:39 -04:00
|
|
|
browser.response_headers
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def status_code
|
2011-08-12 16:50:43 -04:00
|
|
|
browser.status_code
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
2012-03-29 12:59:43 -04:00
|
|
|
def resize_window(width, height)
|
|
|
|
browser.resize_window(width, height)
|
|
|
|
end
|
|
|
|
|
2011-04-20 01:42:20 -04:00
|
|
|
def within_frame(frame_id_or_index)
|
|
|
|
browser.frame_focus(frame_id_or_index)
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
browser.frame_focus
|
|
|
|
end
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def within_window(handle)
|
2012-03-26 18:41:33 -04:00
|
|
|
browser.window_focus(handle)
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
browser.window_focus
|
|
|
|
end
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def wait?
|
2011-04-14 10:16:56 -04:00
|
|
|
true
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def wait_until(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset!
|
2011-02-25 00:15:08 -05:00
|
|
|
browser.reset!
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def has_shortcircuit_timeout?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2011-05-26 15:05:16 -04:00
|
|
|
def render(path, options={})
|
|
|
|
options[:width] ||= 1000
|
|
|
|
options[:height] ||= 10
|
|
|
|
|
|
|
|
browser.render path, options[:width], options[:height]
|
|
|
|
end
|
|
|
|
|
2011-07-07 21:17:14 -04:00
|
|
|
def server_port
|
|
|
|
@rack_server.port
|
|
|
|
end
|
2011-07-29 15:00:13 -04:00
|
|
|
|
2011-10-06 06:13:06 -04:00
|
|
|
def cookies
|
2011-10-14 15:22:33 -04:00
|
|
|
@cookie_jar ||= CookieJar.new(browser)
|
2011-10-06 06:13:06 -04:00
|
|
|
end
|
|
|
|
|
2012-03-06 17:25:24 -05:00
|
|
|
def invalid_element_errors
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
2011-02-18 22:53:06 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def url(path)
|
|
|
|
@rack_server.url(path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|