diff --git a/lib/webrat/core/configuration.rb b/lib/webrat/core/configuration.rb index fe7471d..0e4c522 100755 --- a/lib/webrat/core/configuration.rb +++ b/lib/webrat/core/configuration.rb @@ -46,13 +46,17 @@ module Webrat # 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.application_environment = :selenium self.application_port = 3001 - self.application_address = "localhost" + self.application_address = 'localhost' self.selenium_server_port = 4444 + self.selenium_browser_key = '*firefox' end def parse_with_nokogiri? #:nodoc: diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index c8f9e58..90fdf39 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -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 diff --git a/spec/private/core/configuration_spec.rb b/spec/private/core/configuration_spec.rb index dcc7be2..1b5ee98 100755 --- a/spec/private/core/configuration_spec.rb +++ b/spec/private/core/configuration_spec.rb @@ -71,6 +71,10 @@ describe Webrat::Configuration do 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 diff --git a/spec/private/selenium/selenium_session_spec.rb b/spec/private/selenium/selenium_session_spec.rb new file mode 100644 index 0000000..d92e497 --- /dev/null +++ b/spec/private/selenium/selenium_session_spec.rb @@ -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 \ No newline at end of file