[py] Add client_config property and update deprecation messages (#15674)
* [py] Add client_config property and update deprecation messages
* [py] Add timeout test and update unit tests
diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py
index 1bc4320..7c3475b 100644
--- a/py/selenium/webdriver/remote/remote_connection.py
+++ b/py/selenium/webdriver/remote/remote_connection.py
@@ -168,6 +168,10 @@
extra_headers = None
user_agent = f"selenium/{__version__} (python {system})"
+ @property
+ def client_config(self):
+ return self._client_config
+
@classmethod
def get_timeout(cls):
""":Returns:
@@ -176,7 +180,7 @@
Remote Connection
"""
warnings.warn(
- "get_timeout() in RemoteConnection is deprecated, get timeout from ClientConfig instance instead",
+ "get_timeout() in RemoteConnection is deprecated, get timeout from client_config instead",
DeprecationWarning,
stacklevel=2,
)
@@ -190,7 +194,7 @@
- timeout - timeout value for http requests in seconds
"""
warnings.warn(
- "set_timeout() in RemoteConnection is deprecated, set timeout to ClientConfig instance in constructor instead",
+ "set_timeout() in RemoteConnection is deprecated, set timeout in client_config instead",
DeprecationWarning,
stacklevel=2,
)
@@ -200,7 +204,7 @@
def reset_timeout(cls):
"""Reset the http request timeout to socket._GLOBAL_DEFAULT_TIMEOUT."""
warnings.warn(
- "reset_timeout() in RemoteConnection is deprecated, use reset_timeout() in ClientConfig instance instead",
+ "reset_timeout() in RemoteConnection is deprecated, use reset_timeout() in client_config instead",
DeprecationWarning,
stacklevel=2,
)
@@ -215,7 +219,7 @@
REQUESTS_CA_BUNDLE env variable if set.
"""
warnings.warn(
- "get_certificate_bundle_path() in RemoteConnection is deprecated, get ca_certs from ClientConfig instance instead",
+ "get_certificate_bundle_path() in RemoteConnection is deprecated, get ca_certs from client_config instead",
DeprecationWarning,
stacklevel=2,
)
@@ -231,7 +235,7 @@
- path - path of a .pem encoded certificate chain.
"""
warnings.warn(
- "set_certificate_bundle_path() in RemoteConnection is deprecated, set ca_certs to ClientConfig instance in constructor instead",
+ "set_certificate_bundle_path() in RemoteConnection is deprecated, set ca_certs in client_config instead",
DeprecationWarning,
stacklevel=2,
)
@@ -328,35 +332,35 @@
if remote_server_addr:
warnings.warn(
- "setting remote_server_addr in RemoteConnection() is deprecated, set in ClientConfig instance instead",
+ "setting remote_server_addr in RemoteConnection() is deprecated, set in client_config instead",
DeprecationWarning,
stacklevel=2,
)
if not keep_alive:
warnings.warn(
- "setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance instead",
+ "setting keep_alive in RemoteConnection() is deprecated, set in client_config instead",
DeprecationWarning,
stacklevel=2,
)
if ignore_certificates:
warnings.warn(
- "setting ignore_certificates in RemoteConnection() is deprecated, set in ClientConfig instance instead",
+ "setting ignore_certificates in RemoteConnection() is deprecated, set in client_config instead",
DeprecationWarning,
stacklevel=2,
)
if init_args_for_pool_manager:
warnings.warn(
- "setting init_args_for_pool_manager in RemoteConnection() is deprecated, set in ClientConfig instance instead",
+ "setting init_args_for_pool_manager in RemoteConnection() is deprecated, set in client_config instead",
DeprecationWarning,
stacklevel=2,
)
if ignore_proxy:
warnings.warn(
- "setting ignore_proxy in RemoteConnection() is deprecated, set in ClientConfig instance instead",
+ "setting ignore_proxy in RemoteConnection() is deprecated, set in client_config instead",
DeprecationWarning,
stacklevel=2,
)
diff --git a/py/test/selenium/webdriver/common/timeout_tests.py b/py/test/selenium/webdriver/common/timeout_tests.py
index 6cf22d5..785ecd6 100644
--- a/py/test/selenium/webdriver/common/timeout_tests.py
+++ b/py/test/selenium/webdriver/common/timeout_tests.py
@@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-
import pytest
from selenium.webdriver.common.timeouts import Timeouts
diff --git a/py/test/selenium/webdriver/common/webdriverwait_tests.py b/py/test/selenium/webdriver/common/webdriverwait_tests.py
index e2091b6..51e96ff 100644
--- a/py/test/selenium/webdriver/common/webdriverwait_tests.py
+++ b/py/test/selenium/webdriver/common/webdriverwait_tests.py
@@ -18,6 +18,7 @@
import time
import pytest
+from urllib3.exceptions import ReadTimeoutError
from selenium.common.exceptions import InvalidElementStateException
from selenium.common.exceptions import InvalidSelectorException
@@ -357,3 +358,14 @@
WebDriverWait(driver, 0.01).until(EC.element_attribute_to_include((By.ID, "inputRequired"), "test"))
value = WebDriverWait(driver, 5).until(EC.element_attribute_to_include((By.ID, "inputRequired"), "value"))
assert value is not None
+
+
+def test_driver_with_http_timeout(driver, pages):
+ """This test starts a webdriver with an http client timeout set less than the implicit
+ wait, and verifies the http timeout is triggered first when waiting for an element.
+ """
+ pages.load("simpleTest.html")
+ driver.command_executor.client_config.timeout = 6
+ driver.implicitly_wait(8)
+ with pytest.raises(ReadTimeoutError):
+ driver.find_element(By.ID, "no_element_to_be_found")
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 d7d8583..1bc07e0 100644
--- a/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py
+++ b/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py
@@ -87,7 +87,7 @@
def test_get_proxy_url_http(mock_proxy_settings):
proxy = "http://http_proxy.com:8080"
remote_connection = RemoteConnection("http://remote", keep_alive=False)
- proxy_url = remote_connection._client_config.get_proxy_url()
+ proxy_url = remote_connection.client_config.get_proxy_url()
assert proxy_url == proxy
@@ -96,7 +96,7 @@
remote_server_addr="http://remote", keep_alive=True, username="user", password="pass", auth_type=AuthType.BASIC
)
remote_connection = RemoteConnection(custom_config.remote_server_addr, client_config=custom_config)
- headers = remote_connection._client_config.get_auth_header()
+ headers = remote_connection.client_config.get_auth_header()
assert headers.get("Authorization") == "Basic dXNlcjpwYXNz"
@@ -105,7 +105,7 @@
remote_server_addr="http://remote", keep_alive=True, auth_type=AuthType.BEARER, token="dXNlcjpwYXNz"
)
remote_connection = RemoteConnection(custom_config.remote_server_addr, client_config=custom_config)
- headers = remote_connection._client_config.get_auth_header()
+ headers = remote_connection.client_config.get_auth_header()
assert headers.get("Authorization") == "Bearer dXNlcjpwYXNz"
@@ -114,14 +114,14 @@
remote_server_addr="http://remote", keep_alive=True, auth_type=AuthType.X_API_KEY, token="abcdefgh123456789"
)
remote_connection = RemoteConnection(custom_config.remote_server_addr, client_config=custom_config)
- headers = remote_connection._client_config.get_auth_header()
+ headers = remote_connection.client_config.get_auth_header()
assert headers.get("X-API-Key") == "abcdefgh123456789"
def test_get_proxy_url_https(mock_proxy_settings):
proxy = "http://https_proxy.com:8080"
remote_connection = RemoteConnection("https://remote", keep_alive=False)
- proxy_url = remote_connection._client_config.get_proxy_url()
+ proxy_url = remote_connection.client_config.get_proxy_url()
assert proxy_url == proxy
@@ -162,7 +162,7 @@
remote_connection = RemoteConnection(client_config=client_config)
conn = remote_connection._get_connection_manager()
assert isinstance(conn, urllib3.PoolManager)
- proxy_url = remote_connection._client_config.get_proxy_url()
+ proxy_url = remote_connection.client_config.get_proxy_url()
assert proxy_url is None
@@ -176,19 +176,19 @@
remote_connection = RemoteConnection(client_config=client_config)
conn = remote_connection._get_connection_manager()
assert isinstance(conn, urllib3.PoolManager)
- proxy_url = remote_connection._client_config.get_proxy_url()
+ proxy_url = remote_connection.client_config.get_proxy_url()
assert proxy_url is None
def test_get_proxy_url_none(mock_proxy_settings_missing):
remote_connection = RemoteConnection("https://remote", keep_alive=False)
- proxy_url = remote_connection._client_config.get_proxy_url()
+ proxy_url = remote_connection.client_config.get_proxy_url()
assert proxy_url is None
def test_get_proxy_url_http_auth(mock_proxy_auth_settings):
remote_connection = RemoteConnection("http://remote", keep_alive=False)
- proxy_url = remote_connection._client_config.get_proxy_url()
+ proxy_url = remote_connection.client_config.get_proxy_url()
raw_proxy_url, basic_auth_string = remote_connection._separate_http_proxy_auth()
assert proxy_url == "http://user:password@http_proxy.com:8080"
assert raw_proxy_url == "http://http_proxy.com:8080"
@@ -197,7 +197,7 @@
def test_get_proxy_url_https_auth(mock_proxy_auth_settings):
remote_connection = RemoteConnection("https://remote", keep_alive=False)
- proxy_url = remote_connection._client_config.get_proxy_url()
+ proxy_url = remote_connection.client_config.get_proxy_url()
raw_proxy_url, basic_auth_string = remote_connection._separate_http_proxy_auth()
assert proxy_url == "https://user:password@https_proxy.com:8080"
assert raw_proxy_url == "https://https_proxy.com:8080"
@@ -489,7 +489,6 @@
assert conn.connection_pool_kw["timeout"] == 10
assert conn.connection_pool_kw["cert_reqs"] == "CERT_NONE"
assert isinstance(conn, urllib3.PoolManager)
-
remote_connection.reset_timeout()
assert remote_connection.get_timeout() is None