Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/ie/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 IE
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: '11',
33
platform_name: 'win10',
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,
42
args: %w[foo bar],
43
browser_attach_timeout: 30000,
44
element_scroll_behavior: Options::SCROLL_BOTTOM,
45
full_page_screenshot: true,
46
ensure_clean_session: true,
47
file_upload_dialog_timeout: 30000,
48
force_create_process_api: true,
49
force_shell_windows_api: true,
50
ignore_protected_mode_settings: true,
51
ignore_zoom_level: true,
52
initial_browser_url: 'http://google.com',
53
native_events: false,
54
persistent_hover: true,
55
require_window_focus: true,
56
use_per_process_proxy: true,
57
use_legacy_file_upload_dialog_handling: true,
58
attach_to_edge_chrome: true,
59
edge_executable_path: '/path/to/edge',
60
silent: true,
61
'custom:options': {foo: 'bar'})
62
63
expect(opts.args.to_a).to eq(%w[foo bar])
64
expect(opts.browser_attach_timeout).to eq(30000)
65
expect(opts.element_scroll_behavior).to eq(1)
66
expect(opts.full_page_screenshot).to be(true)
67
expect(opts.ensure_clean_session).to be(true)
68
expect(opts.file_upload_dialog_timeout).to eq(30000)
69
expect(opts.force_create_process_api).to be(true)
70
expect(opts.force_shell_windows_api).to be(true)
71
expect(opts.ignore_protected_mode_settings).to be(true)
72
expect(opts.ignore_zoom_level).to be(true)
73
expect(opts.initial_browser_url).to eq('http://google.com')
74
expect(opts.native_events).to be(false)
75
expect(opts.persistent_hover).to be(true)
76
expect(opts.require_window_focus).to be(true)
77
expect(opts.use_per_process_proxy).to be(true)
78
expect(opts.use_legacy_file_upload_dialog_handling).to be(true)
79
expect(opts.attach_to_edge_chrome).to be(true)
80
expect(opts.edge_executable_path).to eq('/path/to/edge')
81
expect(opts.browser_name).to eq('internet explorer')
82
expect(opts.browser_version).to eq('11')
83
expect(opts.platform_name).to eq('win10')
84
expect(opts.accept_insecure_certs).to be(false)
85
expect(opts.page_load_strategy).to eq('eager')
86
expect(opts.unhandled_prompt_behavior).to eq('accept')
87
expect(opts.strict_file_interactability).to be(true)
88
expect(opts.timeouts).to eq(script: 40000, page_load: 400000, implicit: 1)
89
expect(opts.set_window_rect).to be(false)
90
expect(opts.options[:'custom:options']).to eq(foo: 'bar')
91
expect(opts.silent).to be_truthy
92
end
93
94
it 'has native events on by default' do
95
expect(options.native_events).to be(true)
96
end
97
end
98
99
describe '#add_argument' do
100
it 'adds a command-line argument' do
101
options.add_argument('foo')
102
expect(options.args.to_a).to eq(['foo'])
103
end
104
end
105
106
describe '#add_option' do
107
it 'adds vendor namespaced options with ordered pairs' do
108
options.add_option('foo:bar', {bar: 'foo'})
109
expect(options.instance_variable_get(:@options)['foo:bar']).to eq({bar: 'foo'})
110
end
111
112
it 'adds vendor namespaced options with Hash' do
113
options.add_option('foo:bar' => {bar: 'foo'})
114
expect(options.instance_variable_get(:@options)['foo:bar']).to eq({bar: 'foo'})
115
end
116
end
117
118
describe '#as_json' do
119
it 'returns empty options by default' do
120
expect(options.as_json).to eq('browserName' => 'internet explorer',
121
'se:ieOptions' => {'nativeEvents' => true})
122
end
123
124
it 'returns added options' do
125
options.add_option('foo:bar', {foo: 'bar'})
126
expect(options.as_json).to eq('browserName' => 'internet explorer',
127
'foo:bar' => {'foo' => 'bar'},
128
'se:ieOptions' => {'nativeEvents' => true})
129
end
130
131
it 'returns a JSON hash' do
132
opts = described_class.new(browser_version: '11',
133
platform_name: 'win10',
134
accept_insecure_certs: false,
135
page_load_strategy: 'eager',
136
silent: true,
137
unhandled_prompt_behavior: 'accept',
138
strict_file_interactability: true,
139
timeouts: {script: 40000,
140
page_load: 400000,
141
implicit: 1},
142
set_window_rect: false,
143
args: %w[foo bar],
144
browser_attach_timeout: 30000,
145
element_scroll_behavior: Options::SCROLL_BOTTOM,
146
full_page_screenshot: true,
147
ensure_clean_session: true,
148
file_upload_dialog_timeout: 30000,
149
force_create_process_api: true,
150
force_shell_windows_api: true,
151
ignore_protected_mode_settings: true,
152
ignore_zoom_level: true,
153
initial_browser_url: 'http://google.com',
154
native_events: false,
155
persistent_hover: true,
156
require_window_focus: true,
157
use_per_process_proxy: true,
158
use_legacy_file_upload_dialog_handling: true,
159
attach_to_edge_chrome: true,
160
edge_executable_path: '/path/to/edge',
161
'custom:options': {foo: 'bar'})
162
163
key = 'se:ieOptions'
164
expect(opts.as_json).to eq('browserName' => 'internet explorer',
165
'browserVersion' => '11',
166
'platformName' => 'win10',
167
'acceptInsecureCerts' => false,
168
'pageLoadStrategy' => 'eager',
169
'unhandledPromptBehavior' => 'accept',
170
'strictFileInteractability' => true,
171
'timeouts' => {'script' => 40000,
172
'pageLoad' => 400000,
173
'implicit' => 1},
174
'setWindowRect' => false,
175
'custom:options' => {'foo' => 'bar'},
176
key => {'ie.browserCommandLineSwitches' => 'foo bar',
177
'browserAttachTimeout' => 30000,
178
'elementScrollBehavior' => 1,
179
'ie.enableFullPageScreenshot' => true,
180
'ie.ensureCleanSession' => true,
181
'ie.fileUploadDialogTimeout' => 30000,
182
'ie.forceCreateProcessApi' => true,
183
'ie.forceShellWindowsApi' => true,
184
'ignoreProtectedModeSettings' => true,
185
'ignoreZoomSetting' => true,
186
'initialBrowserUrl' => 'http://google.com',
187
'nativeEvents' => false,
188
'enablePersistentHover' => true,
189
'requireWindowFocus' => true,
190
'ie.usePerProcessProxy' => true,
191
'ie.useLegacyFileUploadDialogHandling' => true,
192
'ie.edgechromium' => true,
193
'ie.edgepath' => '/path/to/edge',
194
'silent' => true})
195
end
196
end
197
end # Options
198
end # IE
199
end # WebDriver
200
end # Selenium
201
202