Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/unit/selenium/webdriver/ie/test_ie_options.py
1990 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
19
import pytest
20
21
from selenium.webdriver.common.options import PageLoadStrategy
22
from selenium.webdriver.ie.options import ElementScrollBehavior, Options
23
24
TIMEOUT = 30
25
26
27
@pytest.fixture
28
def opts():
29
yield Options()
30
31
32
def test_arguments(opts):
33
arg1 = "-k"
34
arg2 = "-private"
35
opts.add_argument(arg1)
36
opts.add_argument(arg2)
37
assert arg1 in opts.arguments
38
assert arg2 in opts.arguments
39
40
41
def test_browser_attach_timeout(opts):
42
opts.browser_attach_timeout = TIMEOUT
43
assert opts.browser_attach_timeout == TIMEOUT
44
assert opts.options.get(Options.BROWSER_ATTACH_TIMEOUT) == TIMEOUT
45
46
47
def test_raises_exception_for_invalid_browser_attach_timeout(opts):
48
with pytest.raises(ValueError):
49
opts.browser_attach_timeout = "foo"
50
51
52
def test_element_scroll_behavior(opts):
53
opts.element_scroll_behavior = ElementScrollBehavior.BOTTOM
54
assert opts.element_scroll_behavior == ElementScrollBehavior.BOTTOM
55
assert opts.options.get(Options.ELEMENT_SCROLL_BEHAVIOR) == ElementScrollBehavior.BOTTOM
56
57
58
def test_ensure_clean_session(opts):
59
opts.ensure_clean_session = True
60
assert opts.ensure_clean_session is True
61
assert opts.options.get(Options.ENSURE_CLEAN_SESSION) is True
62
63
64
def test_file_upload_dialog_timeout(opts):
65
opts.file_upload_dialog_timeout = TIMEOUT
66
assert opts.file_upload_dialog_timeout is TIMEOUT
67
assert opts.options.get(Options.FILE_UPLOAD_DIALOG_TIMEOUT) is TIMEOUT
68
69
70
def test_raises_exception_for_file_upload_dialog_timeout(opts):
71
with pytest.raises(ValueError):
72
opts.file_upload_dialog_timeout = "foo"
73
74
75
def test_force_create_process_api(opts):
76
opts.force_create_process_api = True
77
assert opts.force_create_process_api is True
78
assert opts.options.get(Options.FORCE_CREATE_PROCESS_API) is True
79
80
81
def test_force_shell_windows_api(opts):
82
opts.force_shell_windows_api = True
83
assert opts.force_shell_windows_api is True
84
assert opts.options.get(Options.FORCE_SHELL_WINDOWS_API) is True
85
86
87
def test_full_page_screenshot(opts):
88
opts.full_page_screenshot = True
89
assert opts.full_page_screenshot is True
90
assert opts.options.get(Options.FULL_PAGE_SCREENSHOT) is True
91
92
93
def test_ignore_protected_mode_settings(opts):
94
opts.ignore_protected_mode_settings = True
95
assert opts.ignore_protected_mode_settings is True
96
assert opts.options.get(Options.IGNORE_PROTECTED_MODE_SETTINGS) is True
97
98
99
def test_ignore_zoom_level(opts):
100
opts.ignore_zoom_level = True
101
assert opts.ignore_zoom_level is True
102
assert opts.options.get(Options.IGNORE_ZOOM_LEVEL) is True
103
104
105
def test_initial_browser_url(opts):
106
url = "http://www.selenium.dev"
107
opts.initial_browser_url = url
108
assert opts.initial_browser_url == url
109
assert opts.options.get(Options.INITIAL_BROWSER_URL) == url
110
111
112
def test_native_events(opts):
113
opts.native_events = True
114
assert opts.native_events is True
115
assert opts.options.get(Options.NATIVE_EVENTS) is True
116
117
118
def test_persistent_hover(opts):
119
opts.persistent_hover = True
120
assert opts.persistent_hover is True
121
assert opts.options.get(Options.PERSISTENT_HOVER) is True
122
123
124
def test_require_window_focus(opts):
125
opts.require_window_focus = True
126
assert opts.require_window_focus is True
127
assert opts.options.get(Options.REQUIRE_WINDOW_FOCUS) is True
128
129
130
def test_use_per_process_proxy(opts):
131
opts.use_per_process_proxy = True
132
assert opts.use_per_process_proxy is True
133
assert opts.options.get(Options.USE_PER_PROCESS_PROXY) is True
134
135
136
def test_use_legacy_file_upload_dialog_handling(opts):
137
opts.use_legacy_file_upload_dialog_handling = True
138
assert opts.use_legacy_file_upload_dialog_handling is True
139
assert opts.options.get(Options.USE_LEGACY_FILE_UPLOAD_DIALOG_HANDLING) is True
140
141
142
def test_attach_to_edge_chrome(opts):
143
opts.attach_to_edge_chrome = True
144
assert opts.attach_to_edge_chrome is True
145
assert opts.options.get(Options.ATTACH_TO_EDGE_CHROME) is True
146
147
148
def test_edge_executable_path(opts):
149
path = "/path/to/edge"
150
opts.edge_executable_path = path
151
assert opts.edge_executable_path == path
152
assert opts.options.get(Options.EDGE_EXECUTABLE_PATH) == path
153
154
155
def test_additional_options(opts):
156
opts.add_additional_option("foo", "bar")
157
assert opts.additional_options.get("foo") == "bar"
158
159
160
def test_to_capabilities(opts):
161
opts._options["foo"] = "bar"
162
assert Options.KEY in opts.to_capabilities()
163
assert opts.to_capabilities().get(Options.KEY) == opts._options
164
165
166
def test_to_capabilities_arguments(opts):
167
arg = "-k"
168
opts.add_argument(arg)
169
caps_opts = opts.to_capabilities().get(Options.KEY)
170
assert caps_opts.get(Options.SWITCHES) == arg
171
172
173
def test_to_capabilities_additional_options(opts):
174
name = "foo"
175
value = "bar"
176
opts.add_additional_option(name, value)
177
caps_opts = opts.to_capabilities().get(Options.KEY)
178
assert caps_opts.get(name) == value
179
180
181
def test_to_capabilities_should_not_modify_set_options(opts):
182
opts._options["foo"] = "bar"
183
arg = "-k"
184
opts.add_argument(arg)
185
opts.add_additional_option("baz", "qux")
186
opts.to_capabilities().get(Options.KEY)
187
assert opts.options.get("foo") == "bar"
188
assert opts.arguments[0] == arg
189
assert opts.additional_options.get("baz") == "qux"
190
191
192
def test_starts_with_default_capabilities(opts):
193
from selenium.webdriver import DesiredCapabilities
194
195
caps = DesiredCapabilities.INTERNETEXPLORER.copy()
196
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
197
assert opts._caps == caps
198
199
200
def test_is_a_baseoptions(opts):
201
from selenium.webdriver.common.options import BaseOptions
202
203
assert isinstance(opts, BaseOptions)
204
205