Path: blob/trunk/py/test/selenium/webdriver/common/driver_finder_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.16from pathlib import Path17from unittest import mock1819import pytest2021from selenium import webdriver22from selenium.common.exceptions import NoSuchDriverException23from selenium.webdriver.common.driver_finder import DriverFinder242526def test_get_results_with_valid_path():27options = webdriver.ChromeOptions()28service = webdriver.ChromeService(executable_path="/valid/path/to/driver")2930with mock.patch.object(Path, "is_file", return_value=True):31result = DriverFinder(service, options).get_driver_path()32assert result == "/valid/path/to/driver"333435def test_errors_with_invalid_path():36options = webdriver.ChromeOptions()37service = webdriver.ChromeService(executable_path="/invalid/path/to/driver")3839with mock.patch.object(Path, "is_file", return_value=False):40with pytest.raises(NoSuchDriverException) as excinfo:41DriverFinder(service, options).get_driver_path()42assert "Unable to obtain driver for chrome; For documentation on this error" in str(excinfo.value)434445def test_wraps_error_from_se_manager():46options = webdriver.ChromeOptions()47service = webdriver.ChromeService(executable_path="/valid/path/to/driver")4849lib_path = "selenium.webdriver.common.selenium_manager.SeleniumManager"50with mock.patch(lib_path + ".binary_paths", side_effect=Exception("Error")):51with pytest.raises(NoSuchDriverException):52DriverFinder(service, options).get_driver_path()535455def test_get_results_from_se_manager(monkeypatch):56executable_path = "/invalid/path/to/driver"57options = webdriver.ChromeOptions()58service = webdriver.ChromeService(executable_path=executable_path)59monkeypatch.setattr(Path, "is_file", lambda _: True)6061lib_path = "selenium.webdriver.common.selenium_manager.SeleniumManager"62with mock.patch(lib_path + ".binary_paths", return_value=executable_path):63path = DriverFinder(service, options).get_driver_path()64assert path == executable_path656667