Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/driver_finder_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 WebDriver23describe DriverFinder do24it 'class path accepts a String without calling Selenium Manager' do25allow(Chrome::Service).to receive(:driver_path).and_return('path')26allow(SeleniumManager).to receive(:binary_paths)27allow(Platform).to receive(:assert_executable).with('path').and_return(true)2829described_class.new(Options.chrome, Service.chrome).driver_path3031expect(SeleniumManager).not_to have_received(:binary_paths)32expect(Platform).to have_received(:assert_executable).with('path')33end3435it 'class path accepts a proc without calling Selenium Manager' do36allow(Chrome::Service).to receive(:driver_path).and_return(proc { 'path' })37allow(SeleniumManager).to receive(:binary_paths)38allow(Platform).to receive(:assert_executable).with('path').and_return(true)3940described_class.new(Options.chrome, Service.chrome).driver_path4142expect(SeleniumManager).not_to have_received(:binary_paths)43expect(Platform).to have_received(:assert_executable).with('path')44end4546it 'validates all returned files' do47allow(SeleniumManager).to receive(:binary_paths).and_return({'browser_path' => '/path/to/browser',48'driver_path' => '/path/to/driver'})49allow(Platform).to receive(:assert_executable).with('/path/to/browser').and_return(true)50allow(Platform).to receive(:assert_executable).with('/path/to/driver').and_return(true)5152described_class.new(Options.chrome, Service.chrome).driver_path5354expect(Platform).to have_received(:assert_executable).with('/path/to/browser')55expect(Platform).to have_received(:assert_executable).with('/path/to/driver')56end5758it 'wraps error with NoSuchDriverError' do59allow(SeleniumManager).to receive(:binary_paths).and_raise(Error::WebDriverError, 'this error')6061expect {62expect {63described_class.new(Options.chrome, Service.chrome).driver_path64}.to output(/Exception occurred: this error/).to_stderr_from_any_process65}.to raise_error(WebDriver::Error::NoSuchDriverError, /driver_location/)66end6768it 'creates arguments' do69allow(SeleniumManager).to receive(:binary_paths).and_return({'browser_path' => '/path/to/browser',70'driver_path' => '/path/to/driver'})71proxy = instance_double(Proxy, ssl: 'proxy')72options = Options.chrome(browser_version: 'stable', proxy: proxy, binary: 'path/to/browser')73allow(Platform).to receive(:assert_executable).with('/path/to/browser').and_return(true)74allow(Platform).to receive(:assert_executable).with('/path/to/driver').and_return(true)7576described_class.new(options, Service.chrome).driver_path7778expect(SeleniumManager).to have_received(:binary_paths).with('--browser',79options.browser_name,80'--browser-version',81options.browser_version,82'--browser-path',83options.binary,84'--proxy',85options.proxy.ssl)86end87end88end89end909192