1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00
capybara-webkit/lib/capybara/driver/webkit.rb

145 lines
2.4 KiB
Ruby
Raw Normal View History

2011-02-18 22:53:06 -05:00
require "capybara"
require "capybara/driver/webkit/version"
2011-02-18 22:53:06 -05:00
require "capybara/driver/webkit/node"
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"
require "capybara/driver/webkit/cookie_jar"
2011-02-18 22:53:06 -05:00
class Capybara::Driver::Webkit
class WebkitInvalidResponseError < StandardError
end
class WebkitNoResponseError < StandardError
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
@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
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
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)
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
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
def resize_window(width, height)
browser.resize_window(width, height)
end
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?
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
def render(path, options={})
options[:width] ||= 1000
options[:height] ||= 10
browser.render path, options[:width], options[:height]
end
def server_port
@rack_server.port
end
def cookies
2011-10-14 15:22:33 -04:00
@cookie_jar ||= CookieJar.new(browser)
end
def invalid_element_errors
[]
end
2011-02-18 22:53:06 -05:00
private
def url(path)
@rack_server.url(path)
end
end