Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/firefox/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 Firefox
25
describe Options do
26
subject(:options) { described_class.new }
27
28
describe '#initialize' do
29
it 'sets provided parameters' do
30
profile = Profile.new
31
allow(profile).to receive(:encoded).and_return('encoded_profile')
32
33
opts = described_class.new(browser_version: '66',
34
platform_name: 'win10',
35
accept_insecure_certs: false,
36
page_load_strategy: 'eager',
37
unhandled_prompt_behavior: 'accept',
38
strict_file_interactability: true,
39
timeouts: {script: 40000,
40
page_load: 400000,
41
implicit: 1},
42
set_window_rect: false,
43
args: %w[foo bar],
44
binary: '/foo/bar',
45
prefs: {foo: 'bar'},
46
env: {'FOO' => 'bar'},
47
foo: 'bar',
48
profile: profile,
49
log_level: :debug,
50
android_package: 'package',
51
android_activity: 'activity',
52
android_device_serial: '123',
53
android_intent_arguments: %w[foo bar],
54
'custom:options': {foo: 'bar'})
55
56
expect(opts.args.to_a).to eq(%w[foo bar])
57
expect(opts.binary).to eq('/foo/bar')
58
expect(opts.prefs[:foo]).to eq('bar')
59
expect(opts.env['FOO']).to eq('bar')
60
expect(opts.instance_variable_get(:@options)[:foo]).to eq('bar')
61
expect(opts.profile).to eq(profile)
62
expect(opts.log_level).to eq(:debug)
63
expect(opts.browser_name).to eq('firefox')
64
expect(opts.browser_version).to eq('66')
65
expect(opts.platform_name).to eq('win10')
66
expect(opts.accept_insecure_certs).to be(false)
67
expect(opts.page_load_strategy).to eq('eager')
68
expect(opts.unhandled_prompt_behavior).to eq('accept')
69
expect(opts.strict_file_interactability).to be(true)
70
expect(opts.timeouts).to eq(script: 40000, page_load: 400000, implicit: 1)
71
expect(opts.set_window_rect).to be(false)
72
expect(opts.android_package).to eq('package')
73
expect(opts.android_activity).to eq('activity')
74
expect(opts.android_device_serial).to eq('123')
75
expect(opts.android_intent_arguments).to eq(%w[foo bar])
76
expect(opts.options[:'custom:options']).to eq(foo: 'bar')
77
end
78
end
79
80
describe 'accessors' do
81
it 'adds a command-line argument' do
82
options.args << 'foo'
83
expect(options.args).to eq(['foo'])
84
end
85
86
it 'sets the binary path' do
87
options.binary = '/foo/bar'
88
expect(options.binary).to eq('/foo/bar')
89
end
90
91
it 'adds a preference' do
92
options.prefs[:foo] = 'bar'
93
expect(options.prefs[:foo]).to eq('bar')
94
end
95
96
it 'adds an ENV' do
97
options.env['FOO'] = 'bar'
98
expect(options.env['FOO']).to eq('bar')
99
end
100
end
101
102
describe '#log_level=' do
103
it 'sets the log level' do
104
options.log_level = :debug
105
expect(options.log_level).to eq(:debug)
106
end
107
end
108
109
describe '#profile=' do
110
it 'sets a new profile' do
111
profile = Profile.new
112
allow(profile).to receive(:encoded).and_return('encoded_profile')
113
114
options.profile = profile
115
expect(options.profile).to eq(profile)
116
end
117
118
it 'sets an existing profile' do
119
profile = Profile.new
120
allow(profile).to receive(:encoded).and_return('encoded_profile')
121
122
allow(Profile).to receive(:from_name).with('custom_profile_name').and_return(profile)
123
options.profile = 'custom_profile_name'
124
expect(options.profile).to eq(profile)
125
end
126
end
127
128
describe '#add_argument' do
129
it 'adds a command-line argument' do
130
options.add_argument('foo')
131
expect(options.args.to_a).to eq(['foo'])
132
end
133
end
134
135
describe '#add_option' do
136
it 'adds vendor namespaced options with ordered pairs' do
137
options.add_option('foo:bar', {bar: 'foo'})
138
expect(options.instance_variable_get(:@options)['foo:bar']).to eq({bar: 'foo'})
139
end
140
141
it 'adds vendor namespaced options with Hash' do
142
options.add_option('foo:bar' => {bar: 'foo'})
143
expect(options.instance_variable_get(:@options)['foo:bar']).to eq({bar: 'foo'})
144
end
145
end
146
147
describe '#add_preference' do
148
it 'adds a preference' do
149
options.add_preference(:foo, 'bar')
150
expect(options.prefs[:foo]).to eq('bar')
151
end
152
153
it 'does not camelize preferences' do
154
options.add_preference('intl.accepted_languages', 'en-US')
155
156
prefs = options.as_json['moz:firefoxOptions']['prefs']
157
expected = {'intl.accepted_languages' => 'en-US', 'remote.active-protocols' => 1}
158
expect(prefs).to eq(expected)
159
end
160
end
161
162
describe '#enable_android' do
163
it 'adds default android settings' do
164
options.enable_android
165
166
expect(options.android_package).to eq('org.mozilla.firefox')
167
expect(options.android_activity).to be_nil
168
expect(options.android_device_serial).to be_nil
169
expect(options.android_intent_arguments).to be_nil
170
end
171
172
it 'accepts parameters' do
173
options.enable_android(package: 'foo',
174
serial_number: '123',
175
activity: 'qualified',
176
intent_arguments: %w[foo bar])
177
expect(options.android_package).to eq('foo')
178
expect(options.android_activity).to eq('qualified')
179
expect(options.android_device_serial).to eq('123')
180
expect(options.android_intent_arguments).to eq(%w[foo bar])
181
end
182
end
183
184
describe '#as_json' do
185
it 'returns empty options by default' do
186
expect(options.as_json).to eq('browserName' => 'firefox',
187
'acceptInsecureCerts' => true,
188
'moz:firefoxOptions' => {'prefs' => {'remote.active-protocols' => 1}},
189
'moz:debuggerAddress' => true)
190
end
191
192
it 'returns added options' do
193
options.add_option('foo:bar', {foo: 'bar'})
194
expect(options.as_json).to eq('acceptInsecureCerts' => true,
195
'browserName' => 'firefox',
196
'foo:bar' => {'foo' => 'bar'},
197
'moz:debuggerAddress' => true,
198
'moz:firefoxOptions' => {'prefs' => {'remote.active-protocols' => 1}})
199
end
200
201
it 'converts to a json hash' do
202
profile = Profile.new
203
allow(profile).to receive(:as_json).and_return('encoded_profile')
204
205
opts = described_class.new(browser_version: '66',
206
platform_name: 'win10',
207
accept_insecure_certs: false,
208
page_load_strategy: 'eager',
209
unhandled_prompt_behavior: 'accept',
210
strict_file_interactability: true,
211
timeouts: {script: 40000,
212
page_load: 400000,
213
implicit: 1},
214
set_window_rect: false,
215
args: %w[foo bar],
216
binary: '/foo/bar',
217
prefs: {foo: 'bar'},
218
env: {'FOO' => 'bar'},
219
profile: profile,
220
log_level: :debug,
221
android_package: 'package',
222
android_activity: 'activity',
223
android_device_serial: '123',
224
android_intent_arguments: %w[foo bar],
225
'custom:options': {foo: 'bar'})
226
227
key = 'moz:firefoxOptions'
228
expect(opts.as_json).to eq('browserName' => 'firefox',
229
'browserVersion' => '66',
230
'platformName' => 'win10',
231
'acceptInsecureCerts' => false,
232
'pageLoadStrategy' => 'eager',
233
'unhandledPromptBehavior' => 'accept',
234
'strictFileInteractability' => true,
235
'timeouts' => {'script' => 40000,
236
'pageLoad' => 400000,
237
'implicit' => 1},
238
'setWindowRect' => false,
239
'custom:options' => {'foo' => 'bar'},
240
'moz:debuggerAddress' => true,
241
key => {'args' => %w[foo bar],
242
'binary' => '/foo/bar',
243
'prefs' => {'foo' => 'bar', 'remote.active-protocols' => 1},
244
'env' => {'FOO' => 'bar'},
245
'profile' => 'encoded_profile',
246
'log' => {'level' => 'debug'},
247
'androidPackage' => 'package',
248
'androidActivity' => 'activity',
249
'androidDeviceSerial' => '123',
250
'androidIntentArguments' => %w[foo bar]})
251
end
252
end
253
end # Options
254
end # Chrome
255
end # WebDriver
256
end # Selenium
257
258