diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 1bc432084b6e2..7c3475bbedb27 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -168,6 +168,10 @@ class RemoteConnection: 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 @@ def get_timeout(cls): 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 @@ def set_timeout(cls, timeout): - 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 set_timeout(cls, timeout): 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 @@ def get_certificate_bundle_path(cls): 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 @@ def set_certificate_bundle_path(cls, path): - 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 @@ def __init__( 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 6cf22d5e010c1..785ecd617e7c5 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 e2091b64871e7..51e96ffca3907 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 @@ def test_expected_condition_attribute_to_be_include_in_element(driver, pages): 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 d7d8583300a59..1bc07e04eb800 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_remote_connection_headers_adds_keep_alive_if_requested(): 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 @@ def test_get_auth_header_if_client_config_pass_basic_auth(): 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 @@ def test_get_auth_header_if_client_config_pass_bearer_token(): 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 @@ def test_get_auth_header_if_client_config_pass_x_api_key(): 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 @@ def test_get_proxy_direct_via_client_config(): 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 @@ def test_get_proxy_system_matches_no_proxy_via_client_config(): 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_http_auth(mock_proxy_auth_settings): 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 @@ def test_get_connection_manager_ignores_certificates(): 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