From e6cb40b66e61cc699abb4731733188e43a71d04d Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 23 Nov 2008 15:44:49 -0500 Subject: [PATCH] Adding methods to start and stop the selenium server java process --- lib/webrat/selenium.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index 5343b43..63f25fc 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -2,4 +2,30 @@ gem "selenium-client", ">=1.2.9" require "selenium/client" require "webrat/selenium/selenium_session" -Webrat.configuration.mode = :selenium \ No newline at end of file +Webrat.configuration.mode = :selenium + +module Webrat + + def self.with_selenium_server + start_selenium_server + yield + stop_selenium_server + end + + def self.start_selenium_server + 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 + puts "Waiting for Remote Control to be up and running..." + TCPSocket.wait_for_service :host => "0.0.0.0", :port => 4444 + puts "Selenium Remote Control at 0.0.0.0:4444 ready" + end + + def self.stop_selenium_server + puts "Stopping Selenium Remote Control running at 0.0.0.0:4444..." + remote_control = Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5) + remote_control.stop + puts "Stopped Selenium Remote Control running at 0.0.0.0:4444" + end + +end \ No newline at end of file