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