Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/ie/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 IE
25
describe Driver do
26
let(:service) do
27
instance_double(Service, launch: service_manager, executable_path: nil, 'executable_path=': nil,
28
class: IE::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: 'internet explorer'}}}.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: 'internet explorer',
40
'se:ieOptions': {nativeEvents: true}}}}).to_json
41
endpoint ||= "#{service_manager.uri}/session"
42
stub_request(:post, endpoint).with(body: body).to_return(valid_response)
43
end
44
45
before do
46
allow(Service).to receive_messages(new: service)
47
end
48
49
it 'uses DriverFinder when provided Service without path' do
50
expect_request
51
allow(DriverFinder).to receive(:new).and_return(finder)
52
options = Options.new
53
54
described_class.new(service: service, options: options)
55
expect(finder).to have_received(:driver_path)
56
end
57
58
it 'does not use DriverFinder when provided Service with path' do
59
expect_request
60
allow(service).to receive(:executable_path).and_return('path')
61
allow(DriverFinder).to receive(:new).and_return(finder)
62
63
described_class.new(service: service)
64
expect(finder).not_to have_received(:driver_path)
65
end
66
67
it 'does not require any parameters' do
68
allow(DriverFinder).to receive(:new).and_return(finder)
69
expect_request
70
71
expect { described_class.new }.not_to raise_exception
72
end
73
74
it 'accepts provided Options as sole parameter' do
75
allow(DriverFinder).to receive(:new).and_return(finder)
76
opts = {args: ['-f']}
77
expect_request(body: {capabilities: {alwaysMatch: {browserName: 'internet explorer',
78
'se:ieOptions': {nativeEvents: true,
79
'ie.browserCommandLineSwitches': '-f'}}}})
80
81
expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception
82
end
83
84
it 'does not accept Options of the wrong class' do
85
expect {
86
described_class.new(options: Options.chrome)
87
}.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::IE::Options')
88
end
89
end
90
end # IE
91
end # WebDriver
92
end # Selenium
93
94