Path: blob/trunk/py/test/unit/selenium/webdriver/remote/new_session_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.161718from importlib import import_module1920import pytest2122from selenium.webdriver.chrome.options import Options as ChromeOptions23from selenium.webdriver.common.options import ArgOptions, PageLoadStrategy24from selenium.webdriver.common.proxy import Proxy, ProxyType25from selenium.webdriver.remote import webdriver26from selenium.webdriver.remote.command import Command27from selenium.webdriver.remote.webdriver import WebDriver282930def test_converts_proxy_type_value_to_lowercase_for_w3c(mocker):31mock = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.execute")32w3c_caps = {"pageLoadStrategy": "normal", "proxy": {"proxyType": "manual", "httpProxy": "foo"}}33options = ArgOptions()34proxy = Proxy({"proxyType": ProxyType.MANUAL, "httpProxy": "foo"})35options.proxy = proxy36WebDriver(options=options)37expected_params = {"capabilities": {"firstMatch": [{}], "alwaysMatch": w3c_caps}}38mock.assert_called_with(Command.NEW_SESSION, expected_params)394041def test_works_as_context_manager(mocker):42mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.execute")43quit_ = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.quit")4445with WebDriver(options=ChromeOptions()) as driver:46assert isinstance(driver, WebDriver)4748assert quit_.call_count == 1495051@pytest.mark.parametrize("browser_name", ["firefox", "chrome", "ie"])52def test_acepts_options_to_remote_driver(mocker, browser_name):53options = import_module(f"selenium.webdriver.{browser_name}.options")54mock = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.start_session")5556opts = options.Options()57opts.add_argument("foo")5859WebDriver(options=opts)6061expected_caps = opts.to_capabilities()62mock.assert_called_with(expected_caps)636465def test_always_match_if_2_of_the_same_options():66from selenium.webdriver.chrome.options import Options as ChromeOptions67from selenium.webdriver.chrome.options import Options as ChromeOptions26869co1 = ChromeOptions()70co1.add_argument("foo")71co2 = ChromeOptions2()72co2.add_argument("bar")7374expected = {75"capabilities": {76"alwaysMatch": {77"browserName": "chrome",78"pageLoadStrategy": PageLoadStrategy.normal,79},80"firstMatch": [81{"goog:chromeOptions": {"args": ["foo"], "extensions": []}},82{"goog:chromeOptions": {"args": ["bar"], "extensions": []}},83],84}85}86result = webdriver.create_matches([co1, co2])87assert expected == result888990def test_first_match_when_2_different_option_types():91from selenium.webdriver.chrome.options import Options as ChromeOptions92from selenium.webdriver.firefox.options import Options as FirefoxOptions9394expected = {95"capabilities": {96"alwaysMatch": {"pageLoadStrategy": PageLoadStrategy.normal},97"firstMatch": [98{"browserName": "chrome", "goog:chromeOptions": {"extensions": [], "args": []}},99{100"browserName": "firefox",101"acceptInsecureCerts": True,102"moz:debuggerAddress": True,103"moz:firefoxOptions": {"args": ["foo"], "prefs": {"remote.active-protocols": 1}},104},105],106}107}108109firefox_options = FirefoxOptions()110firefox_options.add_argument("foo")111result = webdriver.create_matches([ChromeOptions(), firefox_options])112assert expected == result113114115