Path: blob/trunk/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py
4062 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_profile import FirefoxProfile23from selenium.webdriver.firefox.options import Options242526@pytest.fixture27def options():28return Options()293031def test_set_binary_location(options):32options.binary_location = "/foo"33assert options.binary_location == "/foo"343536def test_get_binary_location(options):37options._binary_location = "/foo"38assert options.binary_location == "/foo"394041def test_set_preference(options):42options.set_preference("foo", "bar")43assert options._preferences["foo"] == "bar"444546def test_get_preferences(options):47options._preferences = {"foo": "bar"}48assert options.preferences["foo"] == "bar"495051def test_set_proxy(options):52proxy = Proxy({"proxyType": ProxyType.MANUAL})53options.proxy = proxy54assert options._proxy == proxy555657def test_set_proxy_isnt_in_moz_prefix(options):58proxy = Proxy({"proxyType": ProxyType.MANUAL})59options.proxy = proxy6061caps = options.to_capabilities()62assert caps["proxy"]["proxyType"] == "manual"63assert caps.get("moz:firefoxOptions") == {"prefs": {"remote.active-protocols": 1}}646566def test_raises_exception_if_proxy_is_not_proxy_object(options):67with pytest.raises(InvalidArgumentException):68options.proxy = "foo"697071def test_get_proxy(options):72options._proxy = "foo"73assert options.proxy == "foo"747576def test_set_profile_with_firefox_profile(options):77profile = FirefoxProfile()78options.profile = profile79assert options._profile == profile808182def test_set_profile_with_path(options):83options.profile = None84assert isinstance(options._profile, FirefoxProfile)858687def test_get_profile(options):88options._profile = "foo"89assert options.profile == "foo"909192def test_add_arguments(options):93options.add_argument("foo")94assert "foo" in options._arguments959697def test_get_arguments(options):98options._arguments = ["foo"]99assert "foo" in options.arguments100101102def test_raises_exception_if_argument_is_falsy(options):103with pytest.raises(ValueError):104options.add_argument(None)105106107def test_set_log_level(options):108options.log.level = "debug"109assert options.log.level == "debug"110111112def test_creates_capabilities(options):113profile = FirefoxProfile()114options._arguments = ["foo"]115options._binary_location = "/bar"116options._preferences = {"foo": "bar"}117options.proxy = Proxy({"proxyType": ProxyType.MANUAL})118options._profile = profile119options.log.level = "debug"120caps = options.to_capabilities()121opts = caps.get(Options.KEY)122assert opts123assert "foo" in opts["args"]124assert opts["binary"] == "/bar"125assert opts["prefs"]["foo"] == "bar"126assert isinstance(opts["profile"], str)127assert caps["proxy"]["proxyType"] == "manual"128assert opts["log"]["level"] == "debug"129130131def test_starts_with_default_capabilities(options):132from selenium.webdriver import DesiredCapabilities133134caps = DesiredCapabilities.FIREFOX.copy()135caps.update({"pageLoadStrategy": PageLoadStrategy.normal})136assert options._caps == caps137138139def test_is_a_baseoptions(options):140from selenium.webdriver.common.options import BaseOptions141142assert isinstance(options, BaseOptions)143144145def test_raises_exception_with_invalid_page_load_strategy(options):146with pytest.raises(ValueError):147options.page_load_strategy = "never"148149150def test_set_page_load_strategy(options):151options.page_load_strategy = PageLoadStrategy.normal152assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal153154155def test_get_page_load_strategy(options):156options._page_load_strategy = PageLoadStrategy.normal157assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal158159160def test_creates_capabilities_with_page_load_strategy(options):161options.page_load_strategy = PageLoadStrategy.eager162caps = options.to_capabilities()163assert caps["pageLoadStrategy"] == PageLoadStrategy.eager164165166def test_enables_firefox_mobile(options):167options.enable_mobile()168result_caps = options.to_capabilities()169assert result_caps["moz:firefoxOptions"]["androidPackage"] == "org.mozilla.firefox"170171172