Path: blob/trunk/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py
1990 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import pytest1819from selenium.common.exceptions import InvalidArgumentException20from selenium.webdriver.common.options import PageLoadStrategy21from selenium.webdriver.common.proxy import Proxy, ProxyType22from selenium.webdriver.firefox.firefox_binary import FirefoxBinary23from selenium.webdriver.firefox.firefox_profile import FirefoxProfile24from selenium.webdriver.firefox.options import Options252627@pytest.fixture28def options():29return Options()303132def test_set_binary_with_firefox_binary(options):33binary = FirefoxBinary("foo")34options.binary = binary35assert options.binary_location == "foo"363738def test_set_binary_with_path(options):39options.binary = "/foo"40assert options.binary_location == "/foo"414243def test_get_binary(options):44options.binary = "/foo"45assert options.binary._start_cmd == "/foo"464748def test_set_binary_location(options):49options.binary_location = "/foo"50assert options.binary_location == "/foo"515253def test_get_binary_location(options):54options._binary_location = "/foo"55assert options.binary_location == "/foo"565758def test_set_preference(options):59options.set_preference("foo", "bar")60assert options._preferences["foo"] == "bar"616263def test_get_preferences(options):64options._preferences = {"foo": "bar"}65assert options.preferences["foo"] == "bar"666768def test_set_proxy(options):69proxy = Proxy({"proxyType": ProxyType.MANUAL})70options.proxy = proxy71assert options._proxy == proxy727374def test_set_proxy_isnt_in_moz_prefix(options):75proxy = Proxy({"proxyType": ProxyType.MANUAL})76options.proxy = proxy7778caps = options.to_capabilities()79assert caps["proxy"]["proxyType"] == "manual"80assert caps.get("moz:firefoxOptions") == {"prefs": {"remote.active-protocols": 1}}818283def test_raises_exception_if_proxy_is_not_proxy_object(options):84with pytest.raises(InvalidArgumentException):85options.proxy = "foo"868788def test_get_proxy(options):89options._proxy = "foo"90assert options.proxy == "foo"919293def test_set_profile_with_firefox_profile(options):94profile = FirefoxProfile()95options.profile = profile96assert options._profile == profile979899def test_set_profile_with_path(options):100options.profile = None101assert isinstance(options._profile, FirefoxProfile)102103104def test_get_profile(options):105options._profile = "foo"106assert options.profile == "foo"107108109def test_add_arguments(options):110options.add_argument("foo")111assert "foo" in options._arguments112113114def test_get_arguments(options):115options._arguments = ["foo"]116assert "foo" in options.arguments117118119def test_raises_exception_if_argument_is_falsy(options):120with pytest.raises(ValueError):121options.add_argument(None)122123124def test_set_log_level(options):125options.log.level = "debug"126assert options.log.level == "debug"127128129def test_creates_capabilities(options):130profile = FirefoxProfile()131options._arguments = ["foo"]132options._binary_location = "/bar"133options._preferences = {"foo": "bar"}134options.proxy = Proxy({"proxyType": ProxyType.MANUAL})135options._profile = profile136options.log.level = "debug"137caps = options.to_capabilities()138opts = caps.get(Options.KEY)139assert opts140assert "foo" in opts["args"]141assert opts["binary"] == "/bar"142assert opts["prefs"]["foo"] == "bar"143assert isinstance(opts["profile"], str) and opts["profile"]144assert caps["proxy"]["proxyType"] == "manual"145assert opts["log"]["level"] == "debug"146147148def test_starts_with_default_capabilities(options):149from selenium.webdriver import DesiredCapabilities150151caps = DesiredCapabilities.FIREFOX.copy()152caps.update({"pageLoadStrategy": PageLoadStrategy.normal})153assert options._caps == caps154155156def test_is_a_baseoptions(options):157from selenium.webdriver.common.options import BaseOptions158159assert isinstance(options, BaseOptions)160161162def test_raises_exception_with_invalid_page_load_strategy(options):163with pytest.raises(ValueError):164options.page_load_strategy = "never"165166167def test_set_page_load_strategy(options):168options.page_load_strategy = PageLoadStrategy.normal169assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal170171172def test_get_page_load_strategy(options):173options._page_load_strategy = PageLoadStrategy.normal174assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal175176177def test_creates_capabilities_with_page_load_strategy(options):178options.page_load_strategy = PageLoadStrategy.eager179caps = options.to_capabilities()180assert caps["pageLoadStrategy"] == PageLoadStrategy.eager181182183def test_enables_firefox_mobile(options):184options.enable_mobile()185result_caps = options.to_capabilities()186assert result_caps["moz:firefoxOptions"]["androidPackage"] == "org.mozilla.firefox"187188189