2008-11-24 00:46:37 +00:00
|
|
|
require "webrat"
|
2009-03-29 20:35:27 +00:00
|
|
|
gem "selenium-client", ">=1.2.14"
|
2008-11-20 21:07:18 +00:00
|
|
|
require "selenium/client"
|
2009-05-13 03:01:19 +00:00
|
|
|
|
|
|
|
# active_support already defines silence_stream, no need to do that again if it's already present.
|
|
|
|
# http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/kernel/reporting.rb
|
|
|
|
unless Kernel.respond_to?(:silence_stream)
|
|
|
|
require "webrat/selenium/silence_stream"
|
|
|
|
end
|
|
|
|
|
2008-10-25 16:59:21 +00:00
|
|
|
require "webrat/selenium/selenium_session"
|
2008-12-07 19:02:06 +00:00
|
|
|
require "webrat/selenium/matchers"
|
2009-04-06 16:14:14 +00:00
|
|
|
require "webrat/core_extensions/tcp_socket"
|
2008-06-16 05:11:02 +00:00
|
|
|
|
2008-11-23 20:44:49 +00:00
|
|
|
module Webrat
|
2008-12-03 00:57:10 +00:00
|
|
|
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
|
|
|
# Activate it with (for example, in your <tt>env.rb</tt>):
|
|
|
|
#
|
2008-12-27 19:05:19 +00:00
|
|
|
# require "webrat"
|
2009-01-12 18:13:22 +00:00
|
|
|
#
|
2008-12-27 19:05:19 +00:00
|
|
|
# Webrat.configure do |config|
|
|
|
|
# config.mode = :selenium
|
2008-12-03 00:57:10 +00:00
|
|
|
# end
|
|
|
|
#
|
|
|
|
# == Dropping down to the selenium-client API
|
|
|
|
#
|
|
|
|
# If you ever need to do something with Selenium not provided in the Webrat API,
|
|
|
|
# you can always drop down to the selenium-client API using the <tt>selenium</tt> method.
|
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# When "I drag the photo to the left" do
|
|
|
|
# selenium.dragdrop("id=photo_123", "+350, 0")
|
|
|
|
# end
|
|
|
|
#
|
2009-02-23 21:21:42 +00:00
|
|
|
# == Choosing the underlying framework to test
|
|
|
|
#
|
|
|
|
# Webrat assumes you're using rails by default but it can also work with sinatra
|
|
|
|
# and merb. To take advantage of this you can use the configuration block to
|
|
|
|
# set the application_framework variable.
|
|
|
|
# require "webrat"
|
|
|
|
#
|
|
|
|
# Webrat.configure do |config|
|
|
|
|
# config.mode = :selenium
|
|
|
|
# config.application_port = 4567
|
|
|
|
# config.application_framework = :sinatra # could also be :merb
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# == Auto-starting of the appserver and java server
|
2008-12-03 00:57:10 +00:00
|
|
|
#
|
|
|
|
# Webrat will automatically start the Selenium Java server process and an instance
|
|
|
|
# of Mongrel when a test is run. The Mongrel will run in the "selenium" environment
|
2009-02-23 21:21:42 +00:00
|
|
|
# instead of "test", so ensure you've got that defined, and will run on port
|
|
|
|
# Webrat.configuration.application_port.
|
2008-12-03 00:57:10 +00:00
|
|
|
#
|
|
|
|
# == Waiting
|
|
|
|
#
|
|
|
|
# In order to make writing Selenium tests as easy as possible, Webrat will automatically
|
|
|
|
# wait for the correct elements to exist on the page when trying to manipulate them
|
|
|
|
# with methods like <tt>fill_in</tt>, etc. In general, this means you should be able to write
|
|
|
|
# your Webrat::Selenium tests ignoring the concurrency issues that can plague in-browser
|
|
|
|
# testing, so long as you're using the Webrat API.
|
|
|
|
module Selenium
|
2008-12-27 19:05:19 +00:00
|
|
|
module Methods
|
|
|
|
def response
|
|
|
|
webrat_session.response
|
|
|
|
end
|
|
|
|
|
|
|
|
def wait_for(*args, &block)
|
|
|
|
webrat_session.wait_for(*args, &block)
|
|
|
|
end
|
2008-12-19 05:47:26 +00:00
|
|
|
|
2008-12-27 19:05:19 +00:00
|
|
|
def save_and_open_screengrab
|
|
|
|
webrat_session.save_and_open_screengrab
|
2008-11-24 00:46:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-04-06 18:00:14 +00:00
|
|
|
|
2009-02-15 21:37:38 +00:00
|
|
|
if defined?(ActionController::IntegrationTest)
|
|
|
|
module ActionController #:nodoc:
|
|
|
|
IntegrationTest.class_eval do
|
|
|
|
include Webrat::Methods
|
|
|
|
include Webrat::Selenium::Methods
|
|
|
|
include Webrat::Selenium::Matchers
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|