Skip to content

Commit

Permalink
[py] Add backward compatibility for AppiumConnection (#14696)
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Oct 31, 2024
1 parent bdfbb70 commit 3a3c46b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions py/selenium/webdriver/remote/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions py/test/unit/selenium/webdriver/remote/remote_connection_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3a3c46b

Please sign in to comment.