Skip to content

Commit 6b00faa

Browse files
committed
[rb] add integration tests for Server class
1 parent 3bbbeb5 commit 6b00faa

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

rb/lib/selenium/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def download_server(uri, destination)
166166
# :standalone, #hub, #node
167167
#
168168

169-
attr_accessor :role, :port, :timeout, :background, :log
169+
attr_accessor :role, :host, :port, :timeout, :background, :log
170170

171171
#
172172
# @param [String] jar Path to the server jar.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# frozen_string_literal: true
2+
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
require_relative 'webdriver/spec_helper'
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

0 commit comments

Comments
 (0)