From 3a3c46b3c144b0a350dea3598481edd2761f11c5 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Thu, 31 Oct 2024 15:45:18 +0000 Subject: [PATCH] [py] Add backward compatibility for AppiumConnection (#14696) Signed-off-by: Viet Nguyen Duc --- py/selenium/webdriver/remote/remote_connection.py | 15 +++++++++++++++ .../webdriver/remote/remote_connection_tests.py | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 72bd37d76a46c..04786c39c2673 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -136,6 +136,18 @@ class RemoteConnection: """ browser_name = None + # Keep backward compatibility for AppiumConnection - https://github.com/SeleniumHQ/selenium/issues/14694 + import os + import socket + + import certifi + + _timeout = ( + float(os.getenv("GLOBAL_DEFAULT_TIMEOUT", str(socket.getdefaulttimeout()))) + if os.getenv("GLOBAL_DEFAULT_TIMEOUT") is not None + else socket.getdefaulttimeout() + ) + _ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where() _client_config: ClientConfig = None system = platform.system().lower() @@ -296,6 +308,9 @@ def __init__( init_args_for_pool_manager=init_args_for_pool_manager, ) + # Keep backward compatibility for AppiumConnection - https://github.com/SeleniumHQ/selenium/issues/14694 + RemoteConnection._timeout = self._client_config.timeout + RemoteConnection._ca_certs = self._client_config.ca_certs RemoteConnection._client_config = self._client_config if remote_server_addr: diff --git a/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py b/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py index e3d8e29f38e69..ea6281607b4be 100644 --- a/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py +++ b/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py @@ -307,6 +307,19 @@ def test_register_extra_headers(mock_request, remote_connection): assert headers["Foo"] == "bar" +def test_backwards_compatibility_with_appium_connection(): + # Keep backward compatibility for AppiumConnection - https://github.com/SeleniumHQ/selenium/issues/14694 + client_config = ClientConfig(remote_server_addr="http://remote", ca_certs="/path/to/cacert.pem", timeout=300) + remote_connection = RemoteConnection(client_config=client_config) + assert remote_connection._ca_certs == "/path/to/cacert.pem" + assert remote_connection._timeout == 300 + assert remote_connection._client_config == client_config + remote_connection.set_timeout(120) + assert remote_connection.get_timeout() == 120 + remote_connection.set_certificate_bundle_path("/path/to/cacert2.pem") + assert remote_connection.get_certificate_bundle_path() == "/path/to/cacert2.pem" + + def test_get_connection_manager_with_timeout_from_client_config(): remote_connection = RemoteConnection(remote_server_addr="http://remote", keep_alive=False) remote_connection.set_timeout(10)