Class: Selenium::Server
- Inherits:
-
Object
- Object
- Selenium::Server
- Defined in:
- lib/selenium/server.rb
Overview
Constant Summary collapse
Class Method Summary collapse
-
.download(required_version) ⇒ Object
Download the given version of the selenium-server-standalone jar.
- .get(required_version, opts = {}) ⇒ Object
-
.latest ⇒ Object
Ask Google Code what the latest selenium-server-standalone version is.
Instance Method Summary collapse
- #<<(arg) ⇒ Object
-
#initialize(jar, opts = {}) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
- #stop ⇒ Object
- #webdriver_url ⇒ Object
Constructor Details
#initialize(jar, opts = {}) ⇒ Server
Returns a new instance of Server.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/selenium/server.rb', line 91 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 |
Class Method Details
.download(required_version) ⇒ Object
Download the given version of the selenium-server-standalone jar.
37 38 39 40 41 42 43 44 45 46 47 48 49 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 |
# File 'lib/selenium/server.rb', line 37 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 "#{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 |
.get(required_version, opts = {}) ⇒ Object
29 30 31 |
# File 'lib/selenium/server.rb', line 29 def self.get(required_version, opts = {}) new(download(required_version), opts) end |
.latest ⇒ Object
Ask Google Code what the latest selenium-server-standalone version is.
84 85 86 87 88 89 |
# File 'lib/selenium/server.rb', line 84 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
#<<(arg) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/selenium/server.rb', line 133 def <<(arg) if arg.kind_of?(Array) @additional_args += arg else @additional_args << arg.to_s end end |
#start ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/selenium/server.rb', line 104 def start process.start poll_for_service unless @background begin sleep 1 while process.alive? rescue Errno::ECHILD # no longer alive end end end |
#stop ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/selenium/server.rb', line 117 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 |
#webdriver_url ⇒ Object
129 130 131 |
# File 'lib/selenium/server.rb', line 129 def webdriver_url "http://#{@host}:#{@port}/wd/hub" end |