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.



19
20
21
22
23
24
# 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

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



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

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

.jar_pathObject



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

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

Instance Method Details

#bootObject



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

def boot
  start
  wait
  at_exit { stop }
  self
end

#failObject



57
58
59
60
61
62
# 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?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# 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

#startObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

#stopObject



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

def stop
  selenium_command('shutDownSeleniumServer')
end

#waitObject



49
50
51
52
53
54
55
# 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