Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py] moved static method get_path to SeleniumManager class #12554

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions py/selenium/webdriver/chromium/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# under the License.

from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.common.options import ArgOptions
from selenium.webdriver.common.selenium_manager import SeleniumManager
from selenium.webdriver.common.service import Service
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(

self.service = service

self.service.path = DriverFinder.get_path(self.service, options)
self.service.path = SeleniumManager.get_path(self.service, options)

self.service.start()

Expand Down
46 changes: 0 additions & 46 deletions py/selenium/webdriver/common/driver_finder.py

This file was deleted.

18 changes: 18 additions & 0 deletions py/selenium/webdriver/common/selenium_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
from pathlib import Path
from typing import List

from selenium.common import NoSuchDriverException
from selenium.common import WebDriverException
from selenium.webdriver.common.options import BaseOptions
from selenium.webdriver.common.service import Service

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -99,6 +101,22 @@ def driver_location(self, options: BaseOptions) -> str:

return driver_path

@staticmethod
def get_path(service: Service, options: BaseOptions) -> str:
"""Returns the path of the driver if it is present and executable."""

path = service.path
try:
path = SeleniumManager().driver_location(options) if path is None else path
except Exception as err:
msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
raise NoSuchDriverException(msg) from err

if path is None or not Path(path).is_file():
raise NoSuchDriverException(f"Unable to locate or obtain driver for {options.capabilities['browserName']}")

return path

@staticmethod
def run(args: List[str]) -> dict:
"""
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/firefox/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from contextlib import contextmanager
from io import BytesIO

from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.common.selenium_manager import SeleniumManager
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

from .options import Options
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(
self.service = service if service else Service()
options = options if options else Options()

self.service.path = DriverFinder.get_path(self.service, options)
self.service.path = SeleniumManager.get_path(self.service, options)
self.service.start()

executor = FirefoxRemoteConnection(
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/ie/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.common.selenium_manager import SeleniumManager
from selenium.webdriver.remote.remote_connection import RemoteConnection
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

Expand Down Expand Up @@ -46,7 +46,7 @@ def __init__(
self.service = service if service else Service()
options = options if options else Options()

self.service.path = DriverFinder.get_path(self.service, options)
self.service.path = SeleniumManager.get_path(self.service, options)
self.service.start()

executor = RemoteConnection(
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/safari/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

from ..common.driver_finder import DriverFinder
from ..common.selenium_manager import SeleniumManager
from .options import Options
from .remote_connection import SafariRemoteConnection
from .service import Service
Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(
self.service = service if service else Service()
options = options if options else Options()

self.service.path = DriverFinder.get_path(self.service, options)
self.service.path = SeleniumManager.get_path(self.service, options)

self._reuse_service = reuse_service and self.service.reuse_service
if not self._reuse_service:
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/webkitgtk/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import http.client as http_client

from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.common.selenium_manager import SeleniumManager
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

from .options import Options
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(
desired_capabilities = capabilities

self.service = Service(executable_path, port=port, log_path=service_log_path)
self.service.path = DriverFinder.get_path(self.service, options)
self.service.path = SeleniumManager.get_path(self.service, options)
self.service.start()

super().__init__(
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/wpewebkit/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import http.client as http_client

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.common.selenium_manager import SeleniumManager
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

from .options import Options
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(
options = Options()

self.service = Service(executable_path, port=port, log_path=service_log_path)
self.service.path = DriverFinder.get_path(self.service, options)
self.service.path = SeleniumManager.get_path(self.service, options)
self.service.start()

super().__init__(command_executor=self.service.service_url, desired_capabilities=desired_capabilities)
Expand Down
3 changes: 1 addition & 2 deletions py/test/selenium/webdriver/common/selenium_manager_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.selenium_manager import SeleniumManager

Expand Down Expand Up @@ -110,4 +109,4 @@ def test_driver_finder_error(mocker):
options = Options()
msg = r"Unable to locate or obtain driver for chrome.*errors\/driver_location"
with pytest.raises(WebDriverException, match=msg):
DriverFinder.get_path(service, options)
SeleniumManager.get_path(service, options)