| 21 | require 'selenium/server' |
| 22 | |
| 23 | module Selenium |
| 24 | describe Server do |
| 25 | after do |
| 26 | File.delete(@location) if @location && File.exist?(@location) |
| 27 | end |
| 28 | |
| 29 | it 'downloads latest version' do |
| 30 | @location = described_class.download |
| 31 | |
| 32 | expect(File.exist?(@location)).to be true |
| 33 | expect(@location).to eq("selenium-server-#{current_version}.jar") |
| 34 | end |
| 35 | |
| 36 | it 'downloads specified version' do |
| 37 | @location = described_class.download('4.9.0') |
| 38 | |
| 39 | expect(File.exist?(@location)).to be true |
| 40 | expect(@location).to eq('selenium-server-4.9.0.jar') |
| 41 | end |
| 42 | |
| 43 | it 'starts and stops server' do |
| 44 | @location = described_class.download |
| 45 | @server = described_class.new(@location, background: true) |
| 46 | @server.start |
| 47 | status = server_status("http://#{@server.host}:#{@server.port}") |
| 48 | expect(status.code).to eq 200 |
| 49 | |
| 50 | @server.stop |
| 51 | expect { |
| 52 | server_status("http://#{@server.host}:#{@server.port}") |
| 53 | }.to raise_error(Errno::ECONNREFUSED) |
| 54 | ensure |
| 55 | @server&.stop |
| 56 | end |
| 57 | |
| 58 | def server_status(url) |
| 59 | client = WebDriver::Remote::Http::Default.new |
| 60 | client.server_url = URI.parse(url) |
| 61 | client.send(:request, :get, URI.parse("#{url}/status"), {}, nil) |
| 62 | end |
| 63 | |
| 64 | # Ruby Selenium is tagged one version ahead of release to support nightly gem |
| 65 | def current_version |
| 66 | selenium_version = Gem::Version.new(Selenium::WebDriver::VERSION).segments |
| 67 | selenium_version[1] = selenium_version[1] - 1 |
| 68 | selenium_version.join('.') |
| 69 | end |
| 70 | end |
| 71 | end |