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
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
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
described_class.driver_path = nil
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.chrome(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.chrome(log: :stderr)
67
68
expect(service.log).to eq $stderr
69
end
70
71
it 'setting log output as a file converts to argument' do
72
service = described_class.chrome(log: '/path/to/log.txt')
73
74
expect(service.log).to be_nil
75
expect(service.args).to eq ['--log-path=/path/to/log.txt']
76
end
77
78
it 'uses provided args' do
79
service = described_class.new(args: ['--foo', '--bar'])
80
81
expect(service.extra_args).to eq ['--foo', '--bar']
82
end
83
end
84
85
context 'when initializing driver' do
86
let(:driver) { Edge::Driver }
87
let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }
88
let(:service) do
89
instance_double(described_class, launch: service_manager, executable_path: nil, 'executable_path=': nil,
90
class: described_class)
91
end
92
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
93
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
94
95
before do
96
allow(Remote::Bridge).to receive(:new).and_return(bridge)
97
allow(bridge).to receive(:browser).and_return(:msedge)
98
end
99
100
it 'is not created when :url is provided' do
101
allow(described_class).to receive(:new)
102
103
expect {
104
driver.new(url: 'http://example.com:4321')
105
}.to raise_error(ArgumentError, "Can't initialize Selenium::WebDriver::Edge::Driver with :url")
106
107
expect(described_class).not_to have_received(:new)
108
end
109
110
it 'is created when :url is not provided' do
111
allow(DriverFinder).to receive(:new).and_return(finder)
112
allow(described_class).to receive(:new).and_return(service)
113
114
driver.new
115
expect(described_class).to have_received(:new).with(no_args)
116
end
117
118
it 'accepts :service without creating a new instance' do
119
allow(DriverFinder).to receive(:new).and_return(finder)
120
allow(described_class).to receive(:new)
121
122
driver.new(service: service)
123
expect(described_class).not_to have_received(:new)
124
end
125
126
it 'setting log output as a file converts to argument' do
127
service = described_class.chrome(log: '/path/to/log.txt')
128
129
expect(service.log).to be_nil
130
expect(service.args).to eq ['--log-path=/path/to/log.txt']
131
end
132
133
context 'with a path env variable' do
134
let(:service) { described_class.new }
135
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }
136
137
before do
138
ENV['SE_EDGEDRIVER'] = service_path
139
end
140
141
after { ENV.delete('SE_EDGEDRIVER') }
142
143
it 'uses the path from the environment' do
144
expect(service.executable_path).to match(/edgedriver/)
145
end
146
147
it 'updates the path after setting the environment variable' do
148
ENV['SE_EDGEDRIVER'] = '/foo/bar'
149
service.executable_path = service_path
150
151
expect(service.executable_path).to match(/edgedriver/)
152
end
153
end
154
end
155
end
156
end # Edge
157
end # WebDriver
158
end # Selenium
159
160