Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/driver_finder_spec.rb
1865 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 File.expand_path('../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
describe DriverFinder do
25
it 'class path accepts a String without calling Selenium Manager' do
26
allow(Chrome::Service).to receive(:driver_path).and_return('path')
27
allow(SeleniumManager).to receive(:binary_paths)
28
allow(Platform).to receive(:assert_executable).with('path').and_return(true)
29
30
described_class.new(Options.chrome, Service.chrome).driver_path
31
32
expect(SeleniumManager).not_to have_received(:binary_paths)
33
expect(Platform).to have_received(:assert_executable).with('path')
34
end
35
36
it 'class path accepts a proc without calling Selenium Manager' do
37
allow(Chrome::Service).to receive(:driver_path).and_return(proc { 'path' })
38
allow(SeleniumManager).to receive(:binary_paths)
39
allow(Platform).to receive(:assert_executable).with('path').and_return(true)
40
41
described_class.new(Options.chrome, Service.chrome).driver_path
42
43
expect(SeleniumManager).not_to have_received(:binary_paths)
44
expect(Platform).to have_received(:assert_executable).with('path')
45
end
46
47
it 'validates all returned files' do
48
allow(SeleniumManager).to receive(:binary_paths).and_return({'browser_path' => '/path/to/browser',
49
'driver_path' => '/path/to/driver'})
50
allow(Platform).to receive(:assert_executable).with('/path/to/browser').and_return(true)
51
allow(Platform).to receive(:assert_executable).with('/path/to/driver').and_return(true)
52
53
described_class.new(Options.chrome, Service.chrome).driver_path
54
55
expect(Platform).to have_received(:assert_executable).with('/path/to/browser')
56
expect(Platform).to have_received(:assert_executable).with('/path/to/driver')
57
end
58
59
it 'wraps error with NoSuchDriverError' do
60
allow(SeleniumManager).to receive(:binary_paths).and_raise(Error::WebDriverError, 'this error')
61
62
expect {
63
expect {
64
described_class.new(Options.chrome, Service.chrome).driver_path
65
}.to output(/Exception occurred: this error/).to_stderr_from_any_process
66
}.to raise_error(WebDriver::Error::NoSuchDriverError, /driver_location/)
67
end
68
69
it 'creates arguments' do
70
allow(SeleniumManager).to receive(:binary_paths).and_return({'browser_path' => '/path/to/browser',
71
'driver_path' => '/path/to/driver'})
72
proxy = instance_double(Proxy, ssl: 'proxy')
73
options = Options.chrome(browser_version: 'stable', proxy: proxy, binary: 'path/to/browser')
74
allow(Platform).to receive(:assert_executable).with('/path/to/browser').and_return(true)
75
allow(Platform).to receive(:assert_executable).with('/path/to/driver').and_return(true)
76
77
described_class.new(options, Service.chrome).driver_path
78
79
expect(SeleniumManager).to have_received(:binary_paths).with('--browser',
80
options.browser_name,
81
'--browser-version',
82
options.browser_version,
83
'--browser-path',
84
options.binary,
85
'--proxy',
86
options.proxy.ssl)
87
end
88
end
89
end
90
end
91
92