Class: SeleniumRC::Server
- Inherits:
-
Object
- Object
- SeleniumRC::Server
- Defined in:
- lib/selenium_rc/server.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #boot ⇒ Object
- #fail ⇒ Object
-
#initialize(host, port = nil, options = {}) ⇒ Server
constructor
A new instance of Server.
- #jar_path ⇒ Object
- #log(string) ⇒ Object
- #service_is_running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
- #stop_at_exit ⇒ Object
- #wait ⇒ Object
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, = {}) @host = host @port = port || 4444 @args = [:args] || [] @timeout = [:timeout] end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/selenium_rc/server.rb', line 6 def args @args end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/selenium_rc/server.rb', line 4 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/selenium_rc/server.rb', line 5 def port @port end |
#timeout ⇒ Object
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
#boot ⇒ Object
20 21 22 23 24 25 |
# File 'lib/selenium_rc/server.rb', line 20 def boot start wait stop_at_exit self end |
#fail ⇒ Object
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_path ⇒ Object
53 54 55 |
# File 'lib/selenium_rc/server.rb', line 53 def jar_path File.("#{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
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 |
#start ⇒ Object
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 |
#stop ⇒ Object
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_exit ⇒ Object
47 48 49 50 51 |
# File 'lib/selenium_rc/server.rb', line 47 def stop_at_exit at_exit do stop end end |
#wait ⇒ Object
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 |