added selenium_browser_key to allow running on more than firefox, and completed the ability to configure to work with selenium grid."
"
This commit is contained in:
parent
e49c341fc0
commit
c79d2216b2
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
44
spec/private/selenium/selenium_session_spec.rb
Normal file
44
spec/private/selenium/selenium_session_spec.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user