Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/safari/driver_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 Driver do
26
let(:service) do
27
instance_double(Service, launch: service_manager, executable_path: nil, 'executable_path=': nil,
28
class: Safari::Service)
29
end
30
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
31
let(:valid_response) do
32
{status: 200,
33
body: {value: {sessionId: 0, capabilities: {browserName: 'safari'}}}.to_json,
34
headers: {content_type: 'application/json'}}
35
end
36
let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }
37
38
def expect_request(body: nil, endpoint: nil)
39
body = (body || {capabilities: {alwaysMatch: {browserName: 'safari'}}}).to_json
40
endpoint ||= "#{service_manager.uri}/session"
41
stub_request(:post, endpoint).with(body: body).to_return(valid_response)
42
end
43
44
before do
45
allow(Service).to receive_messages(new: service)
46
end
47
48
it 'uses DriverFinder when provided Service without path' do
49
allow(DriverFinder).to receive(:new).and_return(finder)
50
expect_request
51
options = Options.new
52
53
described_class.new(service: service, options: options)
54
expect(finder).to have_received(:driver_path)
55
end
56
57
it 'does not use DriverFinder when provided Service with path' do
58
expect_request
59
allow(service).to receive(:executable_path).and_return('path')
60
allow(DriverFinder).to receive(:new).and_return(finder)
61
62
described_class.new(service: service)
63
expect(finder).not_to have_received(:driver_path)
64
end
65
66
it 'does not require any parameters' do
67
allow(DriverFinder).to receive(:new).and_return(finder)
68
expect_request
69
70
expect { described_class.new }.not_to raise_exception
71
end
72
73
it 'accepts provided Options as sole parameter' do
74
allow(DriverFinder).to receive(:new).and_return(finder)
75
opts = {automatic_inspection: true}
76
expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari',
77
'safari:automaticInspection': true}}})
78
79
expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception
80
end
81
82
it 'does not accept Options of the wrong class' do
83
expect {
84
described_class.new(options: Options.chrome)
85
}.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::Safari::Options')
86
end
87
end
88
end # Safari
89
end # WebDriver
90
end # Selenium
91
92