Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/safari/options_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 Options do
26
subject(:options) { described_class.new }
27
28
describe '#initialize' do
29
it 'accepts all defined parameters' do
30
allow(File).to receive(:directory?).and_return(true)
31
32
opts = described_class.new(browser_version: '12',
33
platform_name: 'mac_sierra',
34
accept_insecure_certs: false,
35
page_load_strategy: 'eager',
36
unhandled_prompt_behavior: 'accept',
37
strict_file_interactability: true,
38
timeouts: {script: 40000,
39
page_load: 400000,
40
implicit: 1},
41
set_window_rect: false, in_private: true,
42
automatic_profiling: false,
43
automatic_inspection: true,
44
'custom:options': {foo: 'bar'})
45
46
expect(opts.automatic_profiling).to be(false)
47
expect(opts.automatic_inspection).to be(true)
48
expect(opts.browser_name).to eq('safari')
49
expect(opts.browser_version).to eq('12')
50
expect(opts.platform_name).to eq('mac_sierra')
51
expect(opts.accept_insecure_certs).to be(false)
52
expect(opts.page_load_strategy).to eq('eager')
53
expect(opts.unhandled_prompt_behavior).to eq('accept')
54
expect(opts.strict_file_interactability).to be(true)
55
expect(opts.timeouts).to eq(script: 40000, page_load: 400000, implicit: 1)
56
expect(opts.set_window_rect).to be(false)
57
expect(opts.options[:'custom:options']).to eq(foo: 'bar')
58
end
59
end
60
61
describe '#add_option' do
62
context 'when namespaced' do
63
it 'adds an option with ordered pairs' do
64
options.add_option('safari:foo', 'bar')
65
expect(options.instance_variable_get(:@options)['safari:foo']).to eq('bar')
66
end
67
68
it 'adds an option with keyword' do
69
options.add_option('safari:foo': 'bar')
70
expect(options.instance_variable_get(:@options)[:'safari:foo']).to eq('bar')
71
end
72
end
73
74
context 'when not namespaced' do
75
it 'adds an option with ordered pairs' do
76
expect {
77
options.add_option(:foo, 'bar')
78
}.to raise_error(ArgumentError, /Safari does not support options that are not namespaced/)
79
end
80
81
it 'raises exception with keyword' do
82
expect {
83
options.add_option(foo: 'bar')
84
}.to raise_error(ArgumentError, /Safari does not support options that are not namespaced/)
85
end
86
end
87
end
88
89
describe '#as_json' do
90
it 'returns empty options by default' do
91
expect(options.as_json).to eq('browserName' => 'safari')
92
end
93
94
it 'returns added options' do
95
options.add_option('safari:foo', 'bar')
96
expect(options.as_json).to eq('browserName' => 'safari',
97
'safari:foo' => 'bar')
98
end
99
100
it 'returns JSON hash' do
101
opts = described_class.new(browser_version: '12',
102
platform_name: 'mac_sierra',
103
accept_insecure_certs: false,
104
page_load_strategy: 'eager',
105
unhandled_prompt_behavior: 'accept',
106
strict_file_interactability: true,
107
timeouts: {script: 40000,
108
page_load: 400000,
109
implicit: 1},
110
set_window_rect: false,
111
automatic_profiling: false,
112
automatic_inspection: true,
113
'safari:foo': 'foo')
114
115
expect(opts.as_json).to eq('browserName' => 'safari',
116
'browserVersion' => '12',
117
'platformName' => 'mac_sierra',
118
'acceptInsecureCerts' => false,
119
'pageLoadStrategy' => 'eager',
120
'unhandledPromptBehavior' => 'accept',
121
'strictFileInteractability' => true,
122
'timeouts' => {'script' => 40000,
123
'pageLoad' => 400000,
124
'implicit' => 1},
125
'setWindowRect' => false,
126
'safari:automaticInspection' => true,
127
'safari:automaticProfiling' => false,
128
'safari:foo' => 'foo')
129
end
130
end
131
end # Options
132
end # Safari
133
end # WebDriver
134
end # Selenium
135
136