Path: blob/trunk/rb/spec/unit/selenium/webdriver/ie/service_spec.rb
4136 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 IE24describe Service do25describe '#new' do26let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }2728before do29allow(Platform).to receive(:assert_executable)30allow(WebDriver.logger).to receive(:debug?).and_return(false)31end3233it 'uses default port and nil path' do34service = described_class.new3536expect(service.port).to eq Service::DEFAULT_PORT37expect(service.host).to eq Platform.localhost38expect(service.executable_path).to be_nil39end4041it 'uses provided path and port' do42path = 'foo'43port = 56784445service = described_class.new(path: path, port: port)4647expect(service.executable_path).to eq path48expect(service.port).to eq port49expect(service.host).to eq Platform.localhost50end5152it 'does not create args by default' do53service = described_class.new5455expect(service.extra_args).to be_empty56end5758it 'uses sets log path to stdout' do59service = described_class.new(log: :stdout)6061expect(service.log).to eq $stdout62end6364it 'uses sets log path to stderr' do65service = described_class.new(log: :stderr)6667expect(service.log).to eq $stderr68end6970it 'sets log path as file location' do71service = described_class.new(log: '/path/to/log.txt')7273expect(service.log).to eq '/path/to/log.txt'74end7576it 'uses provided args' do77service = described_class.new(args: ['--foo', '--bar'])7879expect(service.extra_args).to eq ['--foo', '--bar']80end8182context 'when SE_DEBUG is set' do83around do |example|84ENV['SE_DEBUG'] = '1'85example.run86ensure87ENV.delete('SE_DEBUG')88end8990it 'adds --log-level=DEBUG flag' do91service = described_class.new9293expect(service.extra_args).to include('--log-level=DEBUG')94end9596it 'removes conflicting --log-level args' do97service = described_class.new(args: ['--log-level=INFO'])9899expect(service.extra_args).to include('--log-level=DEBUG')100expect(service.extra_args).not_to include('--log-level=INFO')101end102103it 'removes conflicting --silent args' do104service = described_class.new(args: ['--silent'])105106expect(service.extra_args).to include('--log-level=DEBUG')107expect(service.extra_args).not_to include('--silent')108end109end110end111112context 'when initializing driver' do113let(:driver) { IE::Driver }114let(:service) do115instance_double(described_class, launch: service_manager, executable_path: nil, 'executable_path=': nil,116class: described_class)117end118let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }119let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }120let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }121122before do123allow(Remote::Bridge).to receive(:new).and_return(bridge)124allow(ServiceManager).to receive(:new).and_return(service_manager)125allow(bridge).to receive(:browser).and_return(:internet_explorer)126end127128it 'is not created when :url is provided' do129expect {130driver.new(url: 'http://example.com:4321')131}.to raise_error(ArgumentError, "Can't initialize Selenium::WebDriver::IE::Driver with :url")132end133134it 'is created when :url is not provided' do135allow(DriverFinder).to receive(:new).and_return(finder)136allow(described_class).to receive(:new).and_return(service)137138driver.new139140expect(described_class).to have_received(:new).with(no_args)141end142143it 'accepts :service without creating a new instance' do144allow(DriverFinder).to receive(:new).and_return(finder)145allow(described_class).to receive(:new)146147driver.new(service: service)148149expect(described_class).not_to have_received(:new)150end151152context 'with a path env variable' do153let(:service) { described_class.new }154let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }155156before do157ENV['SE_IEDRIVER'] = service_path158end159160after { ENV.delete('SE_IEDRIVER') }161162it 'uses the path from the environment' do163expect(service.executable_path).to match(/IEDriver/)164end165166it 'updates the path after setting the environment variable' do167ENV['SE_IEDRIVER'] = '/foo/bar'168service.executable_path = service_path169170expect(service.executable_path).to match(/IEDriver/)171end172end173end174end175end # IE176end # WebDriver177end # Selenium178179180