Class: Selenium::SeleniumServer
- Inherits:
-
Object
- Object
- Selenium::SeleniumServer
- Defined in:
- lib/selenium/selenium_server.rb
Overview
Selenium server driver that provides API to start/stop server and check if server is running. NOTE: The start does not return until the server shuts down.
Instance Attribute Summary collapse
-
#port_number ⇒ Object
readonly
Returns the value of attribute port_number.
-
#print_log ⇒ Object
Turn off INFO level server logs, only WARN and above message will be printed.
-
#request_timeout ⇒ Object
readonly
Returns the value of attribute request_timeout.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(port_number_to_use = 4444, request_timeout = 30) ⇒ SeleniumServer
constructor
Initialize the server driver with an opitonal port number (default to 4444) and request timeout (default to 30).
-
#ping ⇒ Object
ping the server to see if it is running, raises error if not returns the ping status.
-
#running? ⇒ Boolean
Check if the Selenium is running by sending a test_complete command with invalid session ID.
-
#start(*argv) ⇒ Object
Starts the Selenium server.
-
#stop ⇒ Object
Stops the Selenium server.
Constructor Details
#initialize(port_number_to_use = 4444, request_timeout = 30) ⇒ SeleniumServer
Initialize the server driver with an opitonal port number (default to 4444) and request timeout (default to 30)
42 43 44 45 46 47 |
# File 'lib/selenium/selenium_server.rb', line 42 def initialize(port_number_to_use = 4444, request_timeout=30) port_number_to_use = 4444 unless port_number_to_use @port_number = port_number_to_use @request_timeout = request_timeout @print_log = false end |
Instance Attribute Details
#port_number ⇒ Object (readonly)
Returns the value of attribute port_number.
36 37 38 |
# File 'lib/selenium/selenium_server.rb', line 36 def port_number @port_number end |
#print_log ⇒ Object
Turn off INFO level server logs, only WARN and above message will be printed
38 39 40 |
# File 'lib/selenium/selenium_server.rb', line 38 def print_log @print_log end |
#request_timeout ⇒ Object (readonly)
Returns the value of attribute request_timeout.
36 37 38 |
# File 'lib/selenium/selenium_server.rb', line 36 def request_timeout @request_timeout end |
Class Method Details
.run(argv, vmparameter = '') ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/selenium/selenium_server.rb', line 10 def SeleniumServer::run(argv, vmparameter='') jar_file = SeleniumServer.jar_file if (argv[0] == '-stop') server = SeleniumServer.new(argv[1]) puts "stopping server on port #{server.port_number}" server.stop elsif argv[0] == '-check' server = SeleniumServer.new(argv[1]) if (server.running?) puts "server running on #{server.port_number}" else puts "server not running on #{server.port_number}" end else command = "java #{vmparameter} -jar #{jar_file} #{argv.join(' ')}" puts command system(command) end end |
Instance Method Details
#ping ⇒ Object
ping the server to see if it is running, raises error if not returns the ping status
77 78 79 80 81 82 83 84 |
# File 'lib/selenium/selenium_server.rb', line 77 def ping url = URI.parse("http://localhost:#{@port_number}/selenium-server/driver/?cmd=testComplete&sessionId=smoketest") request = Net::HTTP::Get.new(url.path) Net::HTTP.start(url.host, url.port) {|http| http.read_timeout=5 http.request(request) } end |
#running? ⇒ Boolean
Check if the Selenium is running by sending a test_complete command with invalid session ID
66 67 68 69 70 71 72 73 |
# File 'lib/selenium/selenium_server.rb', line 66 def running? begin ping rescue Errno::EBADF, Errno::ECONNREFUSED => e return false end return true end |
#start(*argv) ⇒ Object
Starts the Selenium server. This does not return until the server is shutdown.
54 55 56 57 58 |
# File 'lib/selenium/selenium_server.rb', line 54 def start(*argv) logging_option = '' logging_option = '-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog -Dorg.apache.commons.logging.simplelog.defaultlog=warn' unless @print_log SeleniumServer.run(['-port', port_number.to_s, '-timeout', request_timeout.to_s] + argv, logging_option) end |
#stop ⇒ Object
Stops the Selenium server
61 62 63 |
# File 'lib/selenium/selenium_server.rb', line 61 def stop Net::HTTP.get('localhost', '/selenium-server/driver/?cmd=shutDownSeleniumServer', @port_number) end |