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