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
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 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
end
32
33
it 'uses default port and nil path' do
34
service = described_class.new
35
36
expect(service.port).to eq Service::DEFAULT_PORT
37
expect(service.host).to eq Platform.localhost
38
expect(service.executable_path).to be_nil
39
end
40
41
it 'uses provided path and port' do
42
path = 'foo'
43
port = 5678
44
45
service = described_class.new(path: path, port: port)
46
47
expect(service.executable_path).to eq path
48
expect(service.port).to eq port
49
expect(service.host).to eq Platform.localhost
50
end
51
52
it 'does not create args by default' do
53
service = described_class.new
54
55
expect(service.extra_args).to be_empty
56
end
57
58
it 'uses sets log path to stdout' do
59
service = described_class.new(log: :stdout)
60
61
expect(service.log).to eq $stdout
62
end
63
64
it 'uses sets log path to stderr' do
65
service = described_class.new(log: :stderr)
66
67
expect(service.log).to eq $stderr
68
end
69
70
it 'sets log path as file location' do
71
service = described_class.new(log: '/path/to/log.txt')
72
73
expect(service.log).to eq '/path/to/log.txt'
74
end
75
76
it 'uses provided args' do
77
service = described_class.new(args: ['--foo', '--bar'])
78
79
expect(service.extra_args).to eq ['--foo', '--bar']
80
end
81
end
82
83
context 'when initializing driver' do
84
let(:driver) { IE::Driver }
85
let(:service) do
86
instance_double(described_class, launch: service_manager, executable_path: nil, 'executable_path=': nil,
87
class: described_class)
88
end
89
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
90
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
91
let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }
92
93
before do
94
allow(Remote::Bridge).to receive(:new).and_return(bridge)
95
allow(ServiceManager).to receive(:new).and_return(service_manager)
96
allow(bridge).to receive(:browser).and_return(:internet_explorer)
97
end
98
99
it 'is not created when :url is provided' do
100
expect {
101
driver.new(url: 'http://example.com:4321')
102
}.to raise_error(ArgumentError, "Can't initialize Selenium::WebDriver::IE::Driver with :url")
103
end
104
105
it 'is created when :url is not provided' do
106
allow(DriverFinder).to receive(:new).and_return(finder)
107
allow(described_class).to receive(:new).and_return(service)
108
109
driver.new
110
111
expect(described_class).to have_received(:new).with(no_args)
112
end
113
114
it 'accepts :service without creating a new instance' do
115
allow(DriverFinder).to receive(:new).and_return(finder)
116
allow(described_class).to receive(:new)
117
118
driver.new(service: service)
119
120
expect(described_class).not_to have_received(:new)
121
end
122
123
context 'with a path env variable' do
124
let(:service) { described_class.new }
125
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }
126
127
before do
128
ENV['SE_IEDRIVER'] = service_path
129
end
130
131
after { ENV.delete('SE_IEDRIVER') }
132
133
it 'uses the path from the environment' do
134
expect(service.executable_path).to match(/IEDriver/)
135
end
136
137
it 'updates the path after setting the environment variable' do
138
ENV['SE_IEDRIVER'] = '/foo/bar'
139
service.executable_path = service_path
140
141
expect(service.executable_path).to match(/IEDriver/)
142
end
143
end
144
end
145
end
146
end # IE
147
end # WebDriver
148
end # Selenium
149
150