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
|
# 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.common.exceptions import InvalidArgumentException
from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.options import Options
@pytest.fixture
def options():
return Options()
def test_set_binary_with_firefox_binary(options):
binary = FirefoxBinary("foo")
options.binary = binary
assert options.binary_location == "foo"
def test_set_binary_with_path(options):
options.binary = "/foo"
assert options.binary_location == "/foo"
def test_get_binary(options):
options.binary = "/foo"
assert options.binary._start_cmd == "/foo"
def test_set_binary_location(options):
options.binary_location = "/foo"
assert options.binary_location == "/foo"
def test_get_binary_location(options):
options._binary_location = "/foo"
assert options.binary_location == "/foo"
def test_set_preference(options):
options.set_preference("foo", "bar")
assert options._preferences["foo"] == "bar"
def test_get_preferences(options):
options._preferences = {"foo": "bar"}
assert options.preferences["foo"] == "bar"
def test_set_proxy(options):
proxy = Proxy({"proxyType": ProxyType.MANUAL})
options.proxy = proxy
assert options._proxy == proxy
def test_set_proxy_isnt_in_moz_prefix(options):
proxy = Proxy({"proxyType": ProxyType.MANUAL})
options.proxy = proxy
caps = options.to_capabilities()
assert caps["proxy"]["proxyType"] == "manual"
assert caps.get("moz:firefoxOptions") == {"prefs": {"remote.active-protocols": 3}}
def test_raises_exception_if_proxy_is_not_proxy_object(options):
with pytest.raises(InvalidArgumentException):
options.proxy = "foo"
def test_get_proxy(options):
options._proxy = "foo"
assert options.proxy == "foo"
def test_set_profile_with_firefox_profile(options):
profile = FirefoxProfile()
options.profile = profile
assert options._profile == profile
def test_set_profile_with_path(options):
options.profile = None
assert isinstance(options._profile, FirefoxProfile)
def test_get_profile(options):
options._profile = "foo"
assert options.profile == "foo"
def test_add_arguments(options):
options.add_argument("foo")
assert "foo" in options._arguments
def test_get_arguments(options):
options._arguments = ["foo"]
assert "foo" in options.arguments
def test_raises_exception_if_argument_is_falsy(options):
with pytest.raises(ValueError):
options.add_argument(None)
def test_set_log_level(options):
options.log.level = "debug"
assert options.log.level == "debug"
def test_creates_capabilities(options):
profile = FirefoxProfile()
options._arguments = ["foo"]
options._binary_location = "/bar"
options._preferences = {"foo": "bar"}
options.proxy = Proxy({"proxyType": ProxyType.MANUAL})
options._profile = profile
options.log.level = "debug"
caps = options.to_capabilities()
opts = caps.get(Options.KEY)
assert opts
assert "foo" in opts["args"]
assert opts["binary"] == "/bar"
assert opts["prefs"]["foo"] == "bar"
assert isinstance(opts["profile"], str) and opts["profile"]
assert caps["proxy"]["proxyType"] == "manual"
assert opts["log"]["level"] == "debug"
def test_starts_with_default_capabilities(options):
from selenium.webdriver import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX.copy()
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert options._caps == caps
def test_is_a_baseoptions(options):
from selenium.webdriver.common.options import BaseOptions
assert isinstance(options, BaseOptions)
def test_raises_exception_with_invalid_page_load_strategy(options):
with pytest.raises(ValueError):
options.page_load_strategy = "never"
def test_set_page_load_strategy(options):
options.page_load_strategy = PageLoadStrategy.normal
assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal
def test_get_page_load_strategy(options):
options._page_load_strategy = PageLoadStrategy.normal
assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal
def test_creates_capabilities_with_page_load_strategy(options):
options.page_load_strategy = PageLoadStrategy.eager
caps = options.to_capabilities()
assert caps["pageLoadStrategy"] == PageLoadStrategy.eager
def test_enables_firefox_mobile(options):
options.enable_mobile()
result_caps = options.to_capabilities()
assert result_caps["moz:firefoxOptions"]["androidPackage"] == "org.mozilla.firefox"
|