Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/ie/service_spec.rb
4136 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
module IE
25
describe Service do
26
describe '#new' do
27
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }
28
29
before do
30
allow(Platform).to receive(:assert_executable)
31
allow(WebDriver.logger).to receive(:debug?).and_return(false)
32
end
33
34
it 'uses default port and nil path' do
35
service = described_class.new
36
37
expect(service.port).to eq Service::DEFAULT_PORT
38
expect(service.host).to eq Platform.localhost
39
expect(service.executable_path).to be_nil
40
end
41
42
it 'uses provided path and port' do
43
path = 'foo'
44
port = 5678
45
46
service = described_class.new(path: path, port: port)
47
48
expect(service.executable_path).to eq path
49
expect(service.port).to eq port
50
expect(service.host).to eq Platform.localhost
51
end
52
53
it 'does not create args by default' do
54
service = described_class.new
55
56
expect(service.extra_args).to be_empty
57
end
58
59
it 'uses sets log path to stdout' do
60
service = described_class.new(log: :stdout)
61
62
expect(service.log).to eq $stdout
63
end
64
65
it 'uses sets log path to stderr' do
66
service = described_class.new(log: :stderr)
67
68
expect(service.log).to eq $stderr
69
end
70
71
it 'sets log path as file location' do
72
service = described_class.new(log: '/path/to/log.txt')
73
74
expect(service.log).to eq '/path/to/log.txt'
75
end
76
77
it 'uses provided args' do
78
service = described_class.new(args: ['--foo', '--bar'])
79
80
expect(service.extra_args).to eq ['--foo', '--bar']
81
end
82
83
context 'when SE_DEBUG is set' do
84
around do |example|
85
ENV['SE_DEBUG'] = '1'
86
example.run
87
ensure
88
ENV.delete('SE_DEBUG')
89
end
90
91
it 'adds --log-level=DEBUG flag' do
92
service = described_class.new
93
94
expect(service.extra_args).to include('--log-level=DEBUG')
95
end
96
97
it 'removes conflicting --log-level args' do
98
service = described_class.new(args: ['--log-level=INFO'])
99
100
expect(service.extra_args).to include('--log-level=DEBUG')
101
expect(service.extra_args).not_to include('--log-level=INFO')
102
end
103
104
it 'removes conflicting --silent args' do
105
service = described_class.new(args: ['--silent'])
106
107
expect(service.extra_args).to include('--log-level=DEBUG')
108
expect(service.extra_args).not_to include('--silent')
109
end
110
end
111
end
112
113
context 'when initializing driver' do
114
let(:driver) { IE::Driver }
115
let(:service) do
116
instance_double(described_class, launch: service_manager, executable_path: nil, 'executable_path=': nil,
117
class: described_class)
118
end
119
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
120
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
121
let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }
122
123
before do
124
allow(Remote::Bridge).to receive(:new).and_return(bridge)
125
allow(ServiceManager).to receive(:new).and_return(service_manager)
126
allow(bridge).to receive(:browser).and_return(:internet_explorer)
127
end
128
129
it 'is not created when :url is provided' do
130
expect {
131
driver.new(url: 'http://example.com:4321')
132
}.to raise_error(ArgumentError, "Can't initialize Selenium::WebDriver::IE::Driver with :url")
133
end
134
135
it 'is created when :url is not provided' do
136
allow(DriverFinder).to receive(:new).and_return(finder)
137
allow(described_class).to receive(:new).and_return(service)
138
139
driver.new
140
141
expect(described_class).to have_received(:new).with(no_args)
142
end
143
144
it 'accepts :service without creating a new instance' do
145
allow(DriverFinder).to receive(:new).and_return(finder)
146
allow(described_class).to receive(:new)
147
148
driver.new(service: service)
149
150
expect(described_class).not_to have_received(:new)
151
end
152
153
context 'with a path env variable' do
154
let(:service) { described_class.new }
155
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }
156
157
before do
158
ENV['SE_IEDRIVER'] = service_path
159
end
160
161
after { ENV.delete('SE_IEDRIVER') }
162
163
it 'uses the path from the environment' do
164
expect(service.executable_path).to match(/IEDriver/)
165
end
166
167
it 'updates the path after setting the environment variable' do
168
ENV['SE_IEDRIVER'] = '/foo/bar'
169
service.executable_path = service_path
170
171
expect(service.executable_path).to match(/IEDriver/)
172
end
173
end
174
end
175
end
176
end # IE
177
end # WebDriver
178
end # Selenium
179
180