Sha256: d5869c3171cc1910d732502982f1ed6d6c367b5a3df602a50cc303e0c1ed208a
Contents?: true
Size: 1.98 KB
Versions: 1
Compression:
Stored size: 1.98 KB
Contents
module SeleniumRC class Server class << self def boot(*argv) new.boot(argv) end def host ENV["SELENIUM_SERVER_HOST"] || "0.0.0.0" end def port ENV["SELENIUM_SERVER_PORT"] || "4444" end def service_is_running? begin socket = TCPSocket.new(host, port) socket.close unless socket.nil? true rescue Errno::ECONNREFUSED, Errno::EBADF # Windows false end end end def boot(*argv) start(argv) wait stop_at_exit end def log(string) puts string end def start(*argv) command = "java -jar \"#{jar_path}\"" command << " -port #{self.class.port}" command << " #{argv.join(' ')}" if argv.length > 0 log "Running: #{command}" Thread.start do system(command) end end def stop_at_exit at_exit do stop end end def jar_path File.expand_path("#{File.dirname(__FILE__)}/../../vendor/selenium-server.jar") end def wait $stderr.print "==> Waiting for Selenium RC server on port #{port}... " wait_for_service_with_timeout $stderr.print "Ready!\n" rescue SocketError fail end def fail $stderr.puts $stderr.puts $stderr.puts "==> Failed to boot the Selenium RC server... exiting!" exit end def stop Net::HTTP.get(host, '/selenium-server/driver/?cmd=shutDown', port) end def host self.class.host end def port self.class.port end def service_is_running? self.class.service_is_running? end protected def wait_for_service_with_timeout start_time = Time.now timeout = 15 until self.class.service_is_running? if timeout && (Time.now > (start_time + timeout)) raise SocketError.new("Socket did not open within #{timeout} seconds") end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pivotal-selenium-rc-1.6.20090512 | lib/selenium_rc/server.rb |