Class: SeleniumRC::Server

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = nil, options = {}) ⇒ Server

Returns a new instance of Server.



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

def initialize(host, port = nil, options = {})
  @host = host
  @port = port || 4444
  @args = options[:args] || []
  @timeout = options[:timeout]
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



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

def args
  @args
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/selenium_rc/server.rb', line 4

def host
  @host
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Class Method Details

.boot(*args) ⇒ Object



9
10
11
# File 'lib/selenium_rc/server.rb', line 9

def self.boot(*args)
  new(*args).boot
end

Instance Method Details

#bootObject



20
21
22
23
24
25
# File 'lib/selenium_rc/server.rb', line 20

def boot
  start
  wait
  stop_at_exit
  self
end

#failObject



65
66
67
68
69
70
# File 'lib/selenium_rc/server.rb', line 65

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

#jar_pathObject



53
54
55
# File 'lib/selenium_rc/server.rb', line 53

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

#log(string) ⇒ Object



27
28
29
# File 'lib/selenium_rc/server.rb', line 27

def log(string)
  puts string
end

#service_is_running?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/selenium_rc/server.rb', line 76

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

#startObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/selenium_rc/server.rb', line 31

def start
  command = "java -jar \"#{jar_path}\""
  command << " -port #{port}"
  command << " #{args.join(' ')}" unless args.empty?
  log "Running: #{command}"
  begin
    fork do
      system(command)
    end
  rescue NotImplementedError
    Thread.start do
      system(command)
    end
  end
end

#stopObject



72
73
74
# File 'lib/selenium_rc/server.rb', line 72

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

#stop_at_exitObject



47
48
49
50
51
# File 'lib/selenium_rc/server.rb', line 47

def stop_at_exit
  at_exit do
    stop
  end
end

#waitObject



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

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