class SeleniumRC::Server

Attributes

args[RW]
host[RW]
port[RW]
timeout[RW]

Public Class Methods

boot(*args) click to toggle source
# File lib/selenium_rc/server.rb, line 10
def boot(*args)
  new(*args).boot
end
jar_path() click to toggle source
# File lib/selenium_rc/server.rb, line 14
def jar_path
  File.expand_path("#{File.dirname(__FILE__)}/../../vendor/selenium-server.jar")
end
new(host, port = nil, options = {}) click to toggle source
# File lib/selenium_rc/server.rb, line 19
def initialize(host, port = nil, options = {})
  @host = host
  @port = port || 4444
  @args = options[:args] || []
  @timeout = options[:timeout] || 60
end

Public Instance Methods

boot() click to toggle source
# File lib/selenium_rc/server.rb, line 26
def boot
  start
  wait
  at_exit { stop }
  self
end
fail() click to toggle source
# File lib/selenium_rc/server.rb, line 57
def fail
  $stderr.puts
  $stderr.puts
  $stderr.puts "==> Failed to boot the Selenium Server... exiting!"
  exit
end
ready?() click to toggle source
# File lib/selenium_rc/server.rb, line 68
def ready?
  begin
    selenium_command('testComplete') == 'OK'
  rescue Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EPIPE, Net::HTTPBadResponse
    false
  end
end
start() click to toggle source
# File lib/selenium_rc/server.rb, line 33
def start
  command = "java -jar \"#{self.class.jar_path}\""
  command << " -port #{port}"
  command << " #{args.join(' ')}" unless args.empty?
  begin
    fork do
      system(command)
      at_exit { exit!(0) }
    end
  rescue NotImplementedError
    Thread.start do
      system(command)
    end
  end
end
stop() click to toggle source
# File lib/selenium_rc/server.rb, line 64
def stop
  selenium_command('shutDownSeleniumServer')
end
wait() click to toggle source
# File lib/selenium_rc/server.rb, line 49
def wait
  $stderr.print "==> Waiting for Selenium Server on port #{port}... "
  wait_for_service_with_timeout
  $stderr.print "Ready!\n"
rescue ServerNotStarted
  fail
end

Protected Instance Methods

selenium_command(command) click to toggle source
# File lib/selenium_rc/server.rb, line 78
def selenium_command(command)
  Net::HTTP.get(host, "/selenium-server/driver/?cmd=#{command}", port)
end
wait_for_service_with_timeout() click to toggle source
# File lib/selenium_rc/server.rb, line 82
def wait_for_service_with_timeout
  start_time = Time.now
  until ready?
    sleep 0.1
    if @timeout && (Time.now > (start_time + @timeout))
      raise ServerNotStarted.new("Selenium Server was not ready for connections after #{@timeout} seconds")
    end
  end
end