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