module SeleniumTestHelper require 'action_controller/test_process' # Override some methods for use with Selenium tests %w{type select}.each do |method| define_method(method) do |*arguments| append_selenium_command(method, *arguments) end end %w{open assert_location}.each do |method| define_method(method) do |url| append_selenium_command(method, url_for(url)) end end def url_for(options) case options when String then options when Hash then @url_rewriter ||= ActionController::UrlRewriter.new(ActionController::TestRequest.new, nil) @url_rewriter.rewrite(options.update(:only_path => true)) end end def pause(seconds) method_missing(:pause, seconds * 1000) end def method_missing(*arguments) append_selenium_command(*arguments) end def selenium_commands @selenium_commands ||= [] @selenium_commands.insert 0, ['open', '/selenium/setup'] @selenium_commands << ['open', '/selenium/teardown'] end def append_selenium_command(*arguments) arguments[0] = arguments[0].to_s.gsub(/(_(\w))/) { $2.upcase } (@selenium_commands ||= []) << arguments end end module Test::Unit::Assertions def assert_block(message = nil) raise "tryed to use Test::Unit assertion in Selenium tests" end end