Merge commit 'cornel/lh_110'

Conflicts:
	History.txt
This commit is contained in:
Bryan Helmkamp 2009-01-17 16:10:34 -05:00
commit 1731681e79
7 changed files with 263 additions and 119 deletions

View File

@ -16,6 +16,7 @@
* Major enhancements
* Added Selenium grid configuration and support. (Amos King && Cornel Borcean)
* Added select_time, select_date, and select_datetime to API. [#36] (Ben Mabey)
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)

View File

@ -1,3 +1,5 @@
require "webrat/core_extensions/deprecate"
module Webrat
# Configures Webrat. If this is not done, Webrat will be created
@ -22,22 +24,39 @@ module Webrat
attr_writer :parse_with_nokogiri
# Webrat's mode, set automatically when requiring webrat/rails, webrat/merb, etc.
attr_accessor :mode # :nodoc:
attr_reader :mode # :nodoc:
# Save and open pages with error status codes (500-599) in a browser? Defualts to true.
attr_writer :open_error_files
# Which environment should the selenium tests be run in? Defaults to selenium.
attr_accessor :selenium_environment
# Which rails environment should the selenium tests be run in? Defaults to selenium.
attr_accessor :application_environment
webrat_deprecate :selenium_environment, :application_environment
# Which port should the selenium tests be run on? Defaults to 3001.
attr_accessor :selenium_port
# Which port is the application running on for selenium testing? Defaults to 3001.
attr_accessor :application_port
webrat_deprecate :selenium_port, :application_port
# Which server the application is running on for selenium testing? Defaults to localhost
attr_accessor :application_address
# Which server Selenium server is running on. Defaults to nil(server starts in webrat process and runs locally)
attr_accessor :selenium_server_address
# Which server Selenium port is running on. Defaults to 4444
attr_accessor :selenium_server_port
# Set the key that Selenium uses to determine the browser running. Default *firefox
attr_accessor :selenium_browser_key
def initialize # :nodoc:
self.open_error_files = true
self.parse_with_nokogiri = !Webrat.on_java?
self.selenium_environment = :selenium
self.selenium_port = 3001
self.application_environment = :selenium
self.application_port = 3001
self.application_address = 'localhost'
self.selenium_server_port = 4444
self.selenium_browser_key = '*firefox'
end
def parse_with_nokogiri? #:nodoc:

View File

@ -13,21 +13,22 @@ module Webrat
end
def self.start_selenium_server #:nodoc:
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
remote_control.start :background => true
TCPSocket.wait_for_service :host => "0.0.0.0", :port => 4444
unless Webrat.configuration.selenium_server_address
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5)
remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
remote_control.start :background => true
end
TCPSocket.wait_for_service :host => (Webrat.configuration.selenium_server_address || "0.0.0.0"), :port => Webrat.configuration.selenium_server_port
end
def self.stop_selenium_server #:nodoc:
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
remote_control.stop
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address
end
def self.start_app_server #:nodoc:
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.selenium_port} --environment=#{Webrat.configuration.selenium_environment} --pid #{pid_file} &")
TCPSocket.wait_for_service :host => "0.0.0.0", :port => Webrat.configuration.selenium_port.to_i
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
end
def self.stop_app_server #:nodoc:

View File

@ -185,8 +185,7 @@ module Webrat
Webrat.start_app_server
end
$browser = ::Selenium::Client::Driver.new("localhost", 4444, "*firefox", "http://0.0.0.0:3001")
$browser.set_speed(0)
create_browser
$browser.start
teardown_at_exit
@ -195,6 +194,13 @@ module Webrat
$browser.window_maximize
end
def create_browser
$browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}")
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address
end
def teardown_at_exit #:nodoc:
at_exit do
silence_stream(STDOUT) do

View File

@ -25,16 +25,6 @@ describe Webrat::Configuration do
config.should open_error_files
end
it "should use 'selenium' as the selenium environment by default" do
config = Webrat::Configuration.new
config.selenium_environment.should == :selenium
end
it "should use 3001 as the selenium port by default" do
config = Webrat::Configuration.new
config.selenium_port.should == 3001
end
it "should be configurable with a block" do
Webrat.configure do |config|
config.open_error_files = false
@ -45,15 +35,46 @@ describe Webrat::Configuration do
end
[:rails,
:selenium,
:rack,
:sinatra,
:merb,
:mechanize].each do |mode|
:selenium,
:rack,
:sinatra,
:merb,
:mechanize].each do |mode|
it "should require correct lib when in #{mode} mode" do
config = Webrat::Configuration.new
config.should_receive(:require).with("webrat/#{mode}")
config.mode = mode
end
end
describe "Selenium" do
before :each do
@config = Webrat::Configuration.new
end
it "should use 'selenium' as the application environment by default" do
@config.application_environment.should == :selenium
end
it "should use 3001 as the application port by default" do
@config.application_port.should == 3001
end
it 'should default application address to localhost' do
@config.application_address.should == 'localhost'
end
it 'should default selenium server address to nil' do
@config.selenium_server_address.should be_nil
end
it 'should default selenium server port to 4444' do
@config.selenium_server_port.should == 4444
end
it 'should default selenium browser key to *firefox' do
@config.selenium_browser_key.should == '*firefox'
end
end
end

View File

@ -0,0 +1,44 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require "action_controller"
require "action_controller/integration"
require "webrat/selenium"
describe Webrat::SeleniumSession do
describe "create browser" do
it "should start the local selenium client and set speed to 0 when selenium_server_address is nil" do
selenium_session = Webrat::SeleniumSession.new
browser = mock "mock browser"
::Selenium::Client::Driver.should_receive(:new).with("localhost", Webrat.configuration.selenium_server_port, "*firefox", "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}").and_return browser
browser.should_receive(:set_speed).with(0)
selenium_session.send :create_browser
end
it "should start the remote selenium client when selenium_server_address is set" do
Webrat.configuration.selenium_server_address = 'foo address'
selenium_session = Webrat::SeleniumSession.new
browser = mock "mock browser"
::Selenium::Client::Driver.should_receive(:new).with(Webrat.configuration.selenium_server_address, Webrat.configuration.selenium_server_port, "*firefox", "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}").and_return browser
browser.should_not_receive(:set_speed)
selenium_session.send :create_browser
end
it "should use the config specifications" do
Webrat.configuration.selenium_server_port = 'selenium port'
Webrat.configuration.selenium_server_address = 'selenium address'
Webrat.configuration.application_port = 'app port'
Webrat.configuration.application_address = 'app address'
Webrat.configuration.selenium_browser_key = 'browser key'
selenium_session = Webrat::SeleniumSession.new
browser = mock "mock browser"
::Selenium::Client::Driver.should_receive(:new).with('selenium address',
'selenium port', 'browser key',
"http://app address:app port").and_return browser
browser.should_not_receive(:set_speed)
selenium_session.send :create_browser
end
end
end

View File

@ -0,0 +1,52 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require "action_controller"
require "action_controller/integration"
require "webrat/selenium"
RAILS_ROOT = "/"
describe Webrat, "Selenium" do
it "should start the app server with correct config options" do
pid_file = "file"
File.should_receive(:expand_path).with(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid").and_return pid_file
Webrat.should_receive(:system).with("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i)
Webrat.start_app_server
end
describe "start_selenium_server" do
it "should not start the local selenium server if the selenium_server_address is set" do
Webrat.configuration.selenium_server_address = 'foo address'
::Selenium::RemoteControl::RemoteControl.should_not_receive(:new)
TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.selenium_server_address, :port => Webrat.configuration.selenium_server_port)
Webrat.start_selenium_server
end
it "should start the local selenium server if the selenium_server_address is set" do
remote_control = mock "selenium remote control"
::Selenium::RemoteControl::RemoteControl.should_receive(:new).with("0.0.0.0", Webrat.configuration.selenium_server_port, 5).and_return remote_control
remote_control.should_receive(:jar_file=).with(/selenium-server\.jar/)
remote_control.should_receive(:start).with(:background => true)
TCPSocket.should_receive(:wait_for_service).with(:host => "0.0.0.0", :port => Webrat.configuration.selenium_server_port)
Webrat.start_selenium_server
end
end
describe "stop_selenium_server" do
it "should not attempt to stop the server if the selenium_server_address is set" do
Webrat.configuration.selenium_server_address = 'foo address'
::Selenium::RemoteControl::RemoteControl.should_not_receive(:new)
Webrat.stop_selenium_server
end
it "should stop the local server is the selenium_server_address is nil" do
remote_control = mock "selenium remote control"
::Selenium::RemoteControl::RemoteControl.should_receive(:new).with("0.0.0.0", Webrat.configuration.selenium_server_port, 5).and_return remote_control
remote_control.should_receive(:stop)
Webrat.stop_selenium_server
end
end
end