Class: SeleniumRC::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium_rc/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.boot(*argv) ⇒ Object



5
6
7
8
9
# File 'lib/selenium_rc/server.rb', line 5

def boot(*argv)
  instance = new
  instance.boot(argv)
  instance
end

.hostObject



11
12
13
# File 'lib/selenium_rc/server.rb', line 11

def host
  ENV["SELENIUM_SERVER_HOST"] || "0.0.0.0"
end

.portObject



15
16
17
# File 'lib/selenium_rc/server.rb', line 15

def port
  ENV["SELENIUM_SERVER_PORT"] || "4444"
end

.service_is_running?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/selenium_rc/server.rb', line 19

def service_is_running?
  begin
    socket = TCPSocket.new(host, port)
    socket.close unless socket.nil?
    true
  rescue Errno::ECONNREFUSED,
         Errno::EBADF,           # Windows
         Errno::EADDRNOTAVAIL    # Windows
    false
  end
end

Instance Method Details

#boot(*argv) ⇒ Object



32
33
34
35
36
# File 'lib/selenium_rc/server.rb', line 32

def boot(*argv)
  start(argv)
  wait
  stop_at_exit
end

#failObject



76
77
78
79
80
81
# File 'lib/selenium_rc/server.rb', line 76

def fail
  $stderr.puts
  $stderr.puts
  $stderr.puts "==> Failed to boot the Selenium RC server... exiting!"
  exit
end

#hostObject



87
88
89
# File 'lib/selenium_rc/server.rb', line 87

def host
  self.class.host
end

#jar_pathObject



64
65
66
# File 'lib/selenium_rc/server.rb', line 64

def jar_path
  File.expand_path("#{File.dirname(__FILE__)}/../../vendor/selenium-server.jar")
end

#log(string) ⇒ Object



38
39
40
# File 'lib/selenium_rc/server.rb', line 38

def log(string)
  puts string
end

#portObject



91
92
93
# File 'lib/selenium_rc/server.rb', line 91

def port
  self.class.port
end

#service_is_running?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/selenium_rc/server.rb', line 95

def service_is_running?
  self.class.service_is_running?
end

#start(*argv) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/selenium_rc/server.rb', line 42

def start(*argv)
  command = "java -jar \"#{jar_path}\""
  command << " -port #{self.class.port}"
  command << " #{argv.join(' ')}" if argv.length > 0
  log "Running: #{command}"
  begin
    fork do
      system(command)
    end
  rescue NotImplementedError
    Thread.start do
      system(command)
    end
  end
end

#stopObject



83
84
85
# File 'lib/selenium_rc/server.rb', line 83

def stop
  Net::HTTP.get(host, '/selenium-server/driver/?cmd=shutDownSeleniumServer', port)
end

#stop_at_exitObject



58
59
60
61
62
# File 'lib/selenium_rc/server.rb', line 58

def stop_at_exit
  at_exit do
    stop
  end
end

#waitObject



68
69
70
71
72
73
74
# File 'lib/selenium_rc/server.rb', line 68

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