Path: blob/trunk/py/test/selenium/webdriver/marionette/mn_options_tests.py
1865 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.webdriver.common.by import By20from selenium.webdriver.common.desired_capabilities import DesiredCapabilities21from selenium.webdriver.common.options import PageLoadStrategy22from selenium.webdriver.firefox.firefox_binary import FirefoxBinary23from selenium.webdriver.firefox.firefox_profile import FirefoxProfile24from selenium.webdriver.firefox.options import Log, Options252627@pytest.fixture28def driver_kwargs(driver_kwargs):29driver_kwargs["options"] = Options()30return driver_kwargs313233class TestIntegration:34def test_we_can_pass_options(self, driver, pages):35pages.load("formPage.html")36driver.find_element(By.ID, "cheese")373839class TestUnit:40def test_ctor(self):41opts = Options()42assert opts.binary_location == ""43assert opts._preferences == {"remote.active-protocols": 1}44assert opts._profile is None45assert not opts._arguments46assert isinstance(opts.log, Log)4748def test_binary(self):49opts = Options()50assert opts.binary_location == ""5152other_binary = FirefoxBinary()53assert other_binary != opts.binary_location54opts.binary = other_binary55assert other_binary._start_cmd == opts.binary_location5657path = "/path/to/binary"58opts.binary = path59assert isinstance(opts.binary, FirefoxBinary)60assert opts.binary._start_cmd == path6162def test_prefs(self):63opts = Options()64assert len(opts.preferences) == 165assert isinstance(opts.preferences, dict)6667opts.set_preference("spam", "ham")68assert len(opts.preferences) == 269opts.set_preference("eggs", True)70assert len(opts.preferences) == 371opts.set_preference("spam", "spam")72assert len(opts.preferences) == 373assert opts.preferences == {"eggs": True, "remote.active-protocols": 1, "spam": "spam"}7475def test_profile(self, tmpdir_factory):76opts = Options()77assert opts.profile is None7879other_profile = FirefoxProfile()80assert other_profile != opts.profile81opts.profile = other_profile82assert other_profile == opts.profile8384opts.profile = str(tmpdir_factory.mktemp("profile"))85assert isinstance(opts.profile, FirefoxProfile)8687def test_arguments(self):88opts = Options()89assert len(opts.arguments) == 09091opts.add_argument("--foo")92assert len(opts.arguments) == 193opts.arguments.append("--bar")94assert len(opts.arguments) == 295assert opts.arguments == ["--foo", "--bar"]9697def test_to_capabilities(self):98opts = Options()99firefox_caps = DesiredCapabilities.FIREFOX.copy()100firefox_caps.update(101{102"pageLoadStrategy": PageLoadStrategy.normal,103"moz:firefoxOptions": {"prefs": {"remote.active-protocols": 1}},104}105)106assert opts.to_capabilities() == firefox_caps107108profile = FirefoxProfile()109opts.profile = profile110caps = opts.to_capabilities()111assert "moz:firefoxOptions" in caps112assert "profile" in caps["moz:firefoxOptions"]113assert isinstance(caps["moz:firefoxOptions"]["profile"], str)114assert caps["moz:firefoxOptions"]["profile"] == profile.encoded115116opts.add_argument("--foo")117caps = opts.to_capabilities()118assert "moz:firefoxOptions" in caps119assert "args" in caps["moz:firefoxOptions"]120assert caps["moz:firefoxOptions"]["args"] == ["--foo"]121122binary = FirefoxBinary()123opts.binary = binary124caps = opts.to_capabilities()125assert "moz:firefoxOptions" in caps126assert "binary" in caps["moz:firefoxOptions"]127assert isinstance(caps["moz:firefoxOptions"]["binary"], str)128assert caps["moz:firefoxOptions"]["binary"] == binary._start_cmd129130opts.set_preference("spam", "ham")131caps = opts.to_capabilities()132assert "moz:firefoxOptions" in caps133assert "prefs" in caps["moz:firefoxOptions"]134assert isinstance(caps["moz:firefoxOptions"]["prefs"], dict)135assert caps["moz:firefoxOptions"]["prefs"]["spam"] == "ham"136137138