2011-02-18 22:53:06 -05:00
|
|
|
require "capybara"
|
|
|
|
require "capybara/driver/webkit/node"
|
|
|
|
require "capybara/driver/webkit/browser"
|
|
|
|
|
|
|
|
class Capybara::Driver::Webkit
|
2011-02-24 23:22:56 -05:00
|
|
|
class WebkitError < StandardError
|
|
|
|
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
|
2011-02-25 23:47:55 -05:00
|
|
|
@browser = options[:browser] || Browser.new
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def current_url
|
2011-02-25 17:53:36 -05:00
|
|
|
browser.url
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
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-02-26 10:19:24 -05:00
|
|
|
source
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute_script(script)
|
2011-02-26 14:03:30 -05:00
|
|
|
browser.execute_script script
|
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
|
|
|
|
|
|
|
|
def response_headers
|
|
|
|
raise Capybara::NotSupportedByDriverError
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_code
|
|
|
|
raise Capybara::NotSupportedByDriverError
|
|
|
|
end
|
|
|
|
|
|
|
|
def within_frame(frame_id)
|
|
|
|
raise Capybara::NotSupportedByDriverError
|
|
|
|
end
|
|
|
|
|
|
|
|
def within_window(handle)
|
|
|
|
raise Capybara::NotSupportedByDriverError
|
|
|
|
end
|
|
|
|
|
|
|
|
def wait?
|
|
|
|
false
|
|
|
|
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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def url(path)
|
|
|
|
@rack_server.url(path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|