Class: Selenium::Server
- Inherits:
-
Object
- Object
- Selenium::Server
- Defined in:
- rb/lib/selenium/server.rb
Overview
Wraps the remote server jar
Usage:
server = Selenium::Server.new('/path/to/selenium-server-standalone.jar')
server.start
Automatically download the given version:
server = Selenium::Server.get '2.6.0'
server.start
or the latest version:
server = Selenium::Server.get :latest
server.start
Run the server in the background:
server = Selenium::Server.new(jar, :background => true)
server.start
Add additional arguments:
server = Selenium::Server.new(jar)
server << ["--additional", "args"]
server.start
Defined Under Namespace
Classes: Error
Constant Summary
- CL_RESET =
WebDriver::Platform.windows? ? '' : "\r\e[0K"
Instance Attribute Summary (collapse)
-
- (Object) background
Whether to launch the server in the background.
-
- (Object) log
Path to log file, or 'true' for stdout.
-
- (Object) port
The server port.
-
- (Object) timeout
The server timeout.
Class Method Summary (collapse)
-
+ (Object) download(required_version)
Download the given version of the selenium-server-standalone jar.
- + (Object) get(required_version, opts = {})
-
+ (Object) latest
Ask Google Code what the latest selenium-server-standalone version is.
Instance Method Summary (collapse)
- - (Object) <<(arg)
-
- (Server) initialize(jar, opts = {})
constructor
A new instance of Server.
- - (Object) start
- - (Object) stop
- - (Object) webdriver_url
Constructor Details
- (Server) initialize(jar, opts = {})
Returns a new instance of Server
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'rb/lib/selenium/server.rb', line 140 def initialize(jar, opts = {}) raise Errno::ENOENT, jar unless File.exist?(jar) @jar = jar @host = "127.0.0.1" @port = opts.fetch(:port, 4444) @timeout = opts.fetch(:timeout, 30) @background = opts.fetch(:background, false) @log = opts[:log] @additional_args = [] end |
Instance Attribute Details
- (Object) background
Whether to launch the server in the background
120 121 122 |
# File 'rb/lib/selenium/server.rb', line 120 def background @background end |
- (Object) log
Path to log file, or 'true' for stdout.
126 127 128 |
# File 'rb/lib/selenium/server.rb', line 126 def log @log end |
- (Object) port
The server port
108 109 110 |
# File 'rb/lib/selenium/server.rb', line 108 def port @port end |
- (Object) timeout
The server timeout
114 115 116 |
# File 'rb/lib/selenium/server.rb', line 114 def timeout @timeout end |
Class Method Details
+ (Object) download(required_version)
Download the given version of the selenium-server-standalone jar.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'rb/lib/selenium/server.rb', line 50 def self.download(required_version) required_version = latest if required_version == :latest download_file_name = "selenium-server-standalone-#{required_version}.jar" if File.exists? download_file_name return download_file_name end begin open(download_file_name, "wb") do |destination| net_http.start("selenium.googlecode.com") do |http| resp = http.request_get("/files/#{download_file_name}") do |response| total = response.content_length progress = 0 segment_count = 0 response.read_body do |segment| progress += segment.length segment_count += 1 if segment_count % 15 == 0 percent = (progress.to_f / total.to_f) * 100 print "#{CL_RESET}Downloading #{download_file_name}: #{percent.to_i}% (#{progress} / #{total})" segment_count = 0 end destination.write(segment) end end unless resp.kind_of? Net::HTTPSuccess raise Error, "#{resp.code} for #{download_file_name}" end end end rescue FileUtils.rm download_file_name if File.exists? download_file_name raise end download_file_name end |
+ (Object) get(required_version, opts = {})
42 43 44 |
# File 'rb/lib/selenium/server.rb', line 42 def self.get(required_version, opts = {}) new(download(required_version), opts) end |
+ (Object) latest
Ask Google Code what the latest selenium-server-standalone version is.
97 98 99 100 101 102 |
# File 'rb/lib/selenium/server.rb', line 97 def self.latest net_http.start("code.google.com") do |http| resp = http.get("/p/selenium/downloads/list") resp.body.to_s[/selenium-server-standalone-(\d+.\d+.\d+).jar/, 1] end end |
Instance Method Details
- (Object) <<(arg)
176 177 178 179 180 181 182 |
# File 'rb/lib/selenium/server.rb', line 176 def <<(arg) if arg.kind_of?(Array) @additional_args += arg else @additional_args << arg.to_s end end |
- (Object) start
153 154 155 156 157 158 |
# File 'rb/lib/selenium/server.rb', line 153 def start process.start poll_for_service process.wait unless @background end |
- (Object) stop
160 161 162 163 164 165 166 167 168 169 170 |
# File 'rb/lib/selenium/server.rb', line 160 def stop begin Net::HTTP.get(@host, "/selenium-server/driver/?cmd=shutDownSeleniumServer", @port) rescue Errno::ECONNREFUSED end stop_process if @process poll_for_shutdown @log_file.close if @log_file end |
- (Object) webdriver_url
172 173 174 |
# File 'rb/lib/selenium/server.rb', line 172 def webdriver_url "http://#{@host}:#{@port}/wd/hub" end |