Path: blob/trunk/rb/spec/integration/selenium/server_spec.rb
1864 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require_relative 'webdriver/spec_helper'20require 'selenium/server'2122module Selenium23describe Server do24after do25File.delete(@location) if @location && File.exist?(@location)26end2728it 'downloads latest version' do29@location = described_class.download3031expect(File.exist?(@location)).to be true32expect(@location).to eq("selenium-server-#{current_version}.jar")33end3435it 'downloads specified version' do36@location = described_class.download('4.9.0')3738expect(File.exist?(@location)).to be true39expect(@location).to eq('selenium-server-4.9.0.jar')40end4142it 'starts and stops server' do43@location = described_class.download44@server = described_class.new(@location, background: true)45@server.start46status = server_status("http://#{@server.host}:#{@server.port}")47expect(status.code).to eq 2004849@server.stop50expect {51server_status("http://#{@server.host}:#{@server.port}")52}.to raise_error(Errno::ECONNREFUSED)53ensure54@server&.stop55end5657def server_status(url)58client = WebDriver::Remote::Http::Default.new59client.server_url = URI.parse(url)60client.send(:request, :get, URI.parse("#{url}/status"), {}, nil)61end6263# Ruby Selenium is tagged one version ahead of release to support nightly gem64def current_version65selenium_version = Gem::Version.new(Selenium::WebDriver::VERSION).segments66selenium_version[1] = selenium_version[1] - 167selenium_version.join('.')68end69end70end717273