Path: blob/trunk/rb/spec/unit/selenium/webdriver/safari/service_spec.rb
1865 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 File.expand_path('../spec_helper', __dir__)2021module Selenium22module WebDriver23module Safari24describe Service do25describe '#new' do26let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }2728before do29allow(Platform).to receive(:assert_executable)30end3132it 'does not allow log' do33expect {34described_class.new(log: 'anywhere')35}.to raise_exception(Error::WebDriverError, 'Safari Service does not support setting log output')36end3738it 'uses default port and nil path' do39service = described_class.new4041expect(service.port).to eq Service::DEFAULT_PORT42expect(service.host).to eq Platform.localhost43expect(service.executable_path).to be_nil44end4546it 'uses provided path and port' do47path = 'foo'48port = 56784950service = described_class.new(path: path, port: port)5152expect(service.executable_path).to eq path53expect(service.port).to eq port54expect(service.host).to eq Platform.localhost55end5657it 'does not create args by default' do58service = described_class.new5960expect(service.extra_args).to be_empty61end6263it 'does not allow log=' do64service = described_class.new65expect {66service.log = 'anywhere'67}.to raise_exception(Error::WebDriverError, 'Safari Service does not support setting log output')68end6970it 'uses provided args' do71service = described_class.new(args: ['--foo', '--bar'])7273expect(service.extra_args).to eq ['--foo', '--bar']74end75end7677context 'when initializing driver' do78let(:driver) { Safari::Driver }79let(:service) do80instance_double(described_class, launch: service_manager, executable_path: nil, 'executable_path=': nil,81class: described_class)82end83let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }84let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }85let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }8687before do88allow(Remote::Bridge).to receive(:new).and_return(bridge)89allow(ServiceManager).to receive(:new).and_return(service_manager)90allow(bridge).to receive(:browser).and_return(:safari)91end9293it 'is not created when :url is provided' do94expect {95driver.new(url: 'http://example.com:4321')96}.to raise_error(ArgumentError, "Can't initialize Selenium::WebDriver::Safari::Driver with :url")97end9899it 'is created when :url is not provided' do100allow(DriverFinder).to receive(:new).and_return(finder)101allow(described_class).to receive(:new).and_return(service)102103driver.new104105expect(described_class).to have_received(:new).with(no_args)106end107108it 'accepts :service without creating a new instance' do109allow(DriverFinder).to receive(:new).and_return(finder)110allow(described_class).to receive(:new)111112driver.new(service: service)113114expect(described_class).not_to have_received(:new)115end116117context 'with a path env variable' do118let(:service) { described_class.new }119let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }120121before do122ENV['SE_SAFARIDRIVER'] = service_path123end124125after { ENV.delete('SE_SAFARIDRIVER') }126127it 'uses the path from the environment' do128expect(service.executable_path).to match(/safaridriver/)129end130131it 'updates the path after setting the environment variable' do132ENV['SE_SAFARIDRIVER'] = '/foo/bar'133service.executable_path = service_path134135expect(service.executable_path).to match(/safaridriver/)136end137end138end139end140end # Safari141end # WebDriver142end # Selenium143144145