Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/integration/selenium/server_spec.rb
1864 views
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
72
73