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