Class: SeleniumRC::Server
- Inherits:
-
Object
- Object
- SeleniumRC::Server
- Defined in:
- lib/selenium_rc/server.rb
Class Method Summary collapse
Instance Method Summary collapse
- #boot(*argv) ⇒ Object
- #fail ⇒ Object
- #host ⇒ Object
- #jar_path ⇒ Object
- #log(string) ⇒ Object
- #port ⇒ Object
- #service_is_running? ⇒ Boolean
- #start(*argv) ⇒ Object
- #stop ⇒ Object
- #stop_at_exit ⇒ Object
- #wait ⇒ Object
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 |
.host ⇒ Object
11 12 13 |
# File 'lib/selenium_rc/server.rb', line 11 def host ENV["SELENIUM_SERVER_HOST"] || "0.0.0.0" end |
.port ⇒ Object
15 16 17 |
# File 'lib/selenium_rc/server.rb', line 15 def port ENV["SELENIUM_SERVER_PORT"] || "4444" end |
.service_is_running? ⇒ 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 |
#fail ⇒ Object
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 |
#host ⇒ Object
87 88 89 |
# File 'lib/selenium_rc/server.rb', line 87 def host self.class.host end |
#jar_path ⇒ Object
64 65 66 |
# File 'lib/selenium_rc/server.rb', line 64 def jar_path File.("#{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 |
#port ⇒ Object
91 92 93 |
# File 'lib/selenium_rc/server.rb', line 91 def port self.class.port end |
#service_is_running? ⇒ 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 |
#stop ⇒ Object
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_exit ⇒ Object
58 59 60 61 62 |
# File 'lib/selenium_rc/server.rb', line 58 def stop_at_exit at_exit do stop end end |
#wait ⇒ Object
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 |