Skip to content

Commit e8331d1

Browse files
authored
[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
1 parent 3ff6f9a commit e8331d1

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

py/selenium/webdriver/remote/remote_connection.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ class RemoteConnection:
168168
extra_headers = None
169169
user_agent = f"selenium/{__version__} (python {system})"
170170

171+
@property
172+
def client_config(self):
173+
return self._client_config
174+
171175
@classmethod
172176
def get_timeout(cls):
173177
""":Returns:
@@ -176,7 +180,7 @@ def get_timeout(cls):
176180
Remote Connection
177181
"""
178182
warnings.warn(
179-
"get_timeout() in RemoteConnection is deprecated, get timeout from ClientConfig instance instead",
183+
"get_timeout() in RemoteConnection is deprecated, get timeout from client_config instead",
180184
DeprecationWarning,
181185
stacklevel=2,
182186
)
@@ -190,7 +194,7 @@ def set_timeout(cls, timeout):
190194
- timeout - timeout value for http requests in seconds
191195
"""
192196
warnings.warn(
193-
"set_timeout() in RemoteConnection is deprecated, set timeout to ClientConfig instance in constructor instead",
197+
"set_timeout() in RemoteConnection is deprecated, set timeout in client_config instead",
194198
DeprecationWarning,
195199
stacklevel=2,
196200
)
@@ -200,7 +204,7 @@ def set_timeout(cls, timeout):
200204
def reset_timeout(cls):
201205
"""Reset the http request timeout to socket._GLOBAL_DEFAULT_TIMEOUT."""
202206
warnings.warn(
203-
"reset_timeout() in RemoteConnection is deprecated, use reset_timeout() in ClientConfig instance instead",
207+
"reset_timeout() in RemoteConnection is deprecated, use reset_timeout() in client_config instead",
204208
DeprecationWarning,
205209
stacklevel=2,
206210
)
@@ -215,7 +219,7 @@ def get_certificate_bundle_path(cls):
215219
REQUESTS_CA_BUNDLE env variable if set.
216220
"""
217221
warnings.warn(
218-
"get_certificate_bundle_path() in RemoteConnection is deprecated, get ca_certs from ClientConfig instance instead",
222+
"get_certificate_bundle_path() in RemoteConnection is deprecated, get ca_certs from client_config instead",
219223
DeprecationWarning,
220224
stacklevel=2,
221225
)
@@ -231,7 +235,7 @@ def set_certificate_bundle_path(cls, path):
231235
- path - path of a .pem encoded certificate chain.
232236
"""
233237
warnings.warn(
234-
"set_certificate_bundle_path() in RemoteConnection is deprecated, set ca_certs to ClientConfig instance in constructor instead",
238+
"set_certificate_bundle_path() in RemoteConnection is deprecated, set ca_certs in client_config instead",
235239
DeprecationWarning,
236240
stacklevel=2,
237241
)
@@ -328,35 +332,35 @@ def __init__(
328332

329333
if remote_server_addr:
330334
warnings.warn(
331-
"setting remote_server_addr in RemoteConnection() is deprecated, set in ClientConfig instance instead",
335+
"setting remote_server_addr in RemoteConnection() is deprecated, set in client_config instead",
332336
DeprecationWarning,
333337
stacklevel=2,
334338
)
335339

336340
if not keep_alive:
337341
warnings.warn(
338-
"setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance instead",
342+
"setting keep_alive in RemoteConnection() is deprecated, set in client_config instead",
339343
DeprecationWarning,
340344
stacklevel=2,
341345
)
342346

343347
if ignore_certificates:
344348
warnings.warn(
345-
"setting ignore_certificates in RemoteConnection() is deprecated, set in ClientConfig instance instead",
349+
"setting ignore_certificates in RemoteConnection() is deprecated, set in client_config instead",
346350
DeprecationWarning,
347351
stacklevel=2,
348352
)
349353

350354
if init_args_for_pool_manager:
351355
warnings.warn(
352-
"setting init_args_for_pool_manager in RemoteConnection() is deprecated, set in ClientConfig instance instead",
356+
"setting init_args_for_pool_manager in RemoteConnection() is deprecated, set in client_config instead",
353357
DeprecationWarning,
354358
stacklevel=2,
355359
)
356360

357361
if ignore_proxy:
358362
warnings.warn(
359-
"setting ignore_proxy in RemoteConnection() is deprecated, set in ClientConfig instance instead",
363+
"setting ignore_proxy in RemoteConnection() is deprecated, set in client_config instead",
360364
DeprecationWarning,
361365
stacklevel=2,
362366
)

py/test/selenium/webdriver/common/timeout_tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
1918
import pytest
2019

2120
from selenium.webdriver.common.timeouts import Timeouts

py/test/selenium/webdriver/common/webdriverwait_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import time
1919

2020
import pytest
21+
from urllib3.exceptions import ReadTimeoutError
2122

2223
from selenium.common.exceptions import InvalidElementStateException
2324
from selenium.common.exceptions import InvalidSelectorException
@@ -357,3 +358,14 @@ def test_expected_condition_attribute_to_be_include_in_element(driver, pages):
357358
WebDriverWait(driver, 0.01).until(EC.element_attribute_to_include((By.ID, "inputRequired"), "test"))
358359
value = WebDriverWait(driver, 5).until(EC.element_attribute_to_include((By.ID, "inputRequired"), "value"))
359360
assert value is not None
361+
362+
363+
def test_driver_with_http_timeout(driver, pages):
364+
"""This test starts a webdriver with an http client timeout set less than the implicit
365+
wait, and verifies the http timeout is triggered first when waiting for an element.
366+
"""
367+
pages.load("simpleTest.html")
368+
driver.command_executor.client_config.timeout = 6
369+
driver.implicitly_wait(8)
370+
with pytest.raises(ReadTimeoutError):
371+
driver.find_element(By.ID, "no_element_to_be_found")

py/test/unit/selenium/webdriver/remote/remote_connection_tests.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_get_remote_connection_headers_adds_keep_alive_if_requested():
8787
def test_get_proxy_url_http(mock_proxy_settings):
8888
proxy = "http://http_proxy.com:8080"
8989
remote_connection = RemoteConnection("http://remote", keep_alive=False)
90-
proxy_url = remote_connection._client_config.get_proxy_url()
90+
proxy_url = remote_connection.client_config.get_proxy_url()
9191
assert proxy_url == proxy
9292

9393

@@ -96,7 +96,7 @@ def test_get_auth_header_if_client_config_pass_basic_auth():
9696
remote_server_addr="http://remote", keep_alive=True, username="user", password="pass", auth_type=AuthType.BASIC
9797
)
9898
remote_connection = RemoteConnection(custom_config.remote_server_addr, client_config=custom_config)
99-
headers = remote_connection._client_config.get_auth_header()
99+
headers = remote_connection.client_config.get_auth_header()
100100
assert headers.get("Authorization") == "Basic dXNlcjpwYXNz"
101101

102102

@@ -105,7 +105,7 @@ def test_get_auth_header_if_client_config_pass_bearer_token():
105105
remote_server_addr="http://remote", keep_alive=True, auth_type=AuthType.BEARER, token="dXNlcjpwYXNz"
106106
)
107107
remote_connection = RemoteConnection(custom_config.remote_server_addr, client_config=custom_config)
108-
headers = remote_connection._client_config.get_auth_header()
108+
headers = remote_connection.client_config.get_auth_header()
109109
assert headers.get("Authorization") == "Bearer dXNlcjpwYXNz"
110110

111111

@@ -114,14 +114,14 @@ def test_get_auth_header_if_client_config_pass_x_api_key():
114114
remote_server_addr="http://remote", keep_alive=True, auth_type=AuthType.X_API_KEY, token="abcdefgh123456789"
115115
)
116116
remote_connection = RemoteConnection(custom_config.remote_server_addr, client_config=custom_config)
117-
headers = remote_connection._client_config.get_auth_header()
117+
headers = remote_connection.client_config.get_auth_header()
118118
assert headers.get("X-API-Key") == "abcdefgh123456789"
119119

120120

121121
def test_get_proxy_url_https(mock_proxy_settings):
122122
proxy = "http://https_proxy.com:8080"
123123
remote_connection = RemoteConnection("https://remote", keep_alive=False)
124-
proxy_url = remote_connection._client_config.get_proxy_url()
124+
proxy_url = remote_connection.client_config.get_proxy_url()
125125
assert proxy_url == proxy
126126

127127

@@ -162,7 +162,7 @@ def test_get_proxy_direct_via_client_config():
162162
remote_connection = RemoteConnection(client_config=client_config)
163163
conn = remote_connection._get_connection_manager()
164164
assert isinstance(conn, urllib3.PoolManager)
165-
proxy_url = remote_connection._client_config.get_proxy_url()
165+
proxy_url = remote_connection.client_config.get_proxy_url()
166166
assert proxy_url is None
167167

168168

@@ -176,19 +176,19 @@ def test_get_proxy_system_matches_no_proxy_via_client_config():
176176
remote_connection = RemoteConnection(client_config=client_config)
177177
conn = remote_connection._get_connection_manager()
178178
assert isinstance(conn, urllib3.PoolManager)
179-
proxy_url = remote_connection._client_config.get_proxy_url()
179+
proxy_url = remote_connection.client_config.get_proxy_url()
180180
assert proxy_url is None
181181

182182

183183
def test_get_proxy_url_none(mock_proxy_settings_missing):
184184
remote_connection = RemoteConnection("https://remote", keep_alive=False)
185-
proxy_url = remote_connection._client_config.get_proxy_url()
185+
proxy_url = remote_connection.client_config.get_proxy_url()
186186
assert proxy_url is None
187187

188188

189189
def test_get_proxy_url_http_auth(mock_proxy_auth_settings):
190190
remote_connection = RemoteConnection("http://remote", keep_alive=False)
191-
proxy_url = remote_connection._client_config.get_proxy_url()
191+
proxy_url = remote_connection.client_config.get_proxy_url()
192192
raw_proxy_url, basic_auth_string = remote_connection._separate_http_proxy_auth()
193193
assert proxy_url == "http://user:password@http_proxy.com:8080"
194194
assert raw_proxy_url == "http://http_proxy.com:8080"
@@ -197,7 +197,7 @@ def test_get_proxy_url_http_auth(mock_proxy_auth_settings):
197197

198198
def test_get_proxy_url_https_auth(mock_proxy_auth_settings):
199199
remote_connection = RemoteConnection("https://remote", keep_alive=False)
200-
proxy_url = remote_connection._client_config.get_proxy_url()
200+
proxy_url = remote_connection.client_config.get_proxy_url()
201201
raw_proxy_url, basic_auth_string = remote_connection._separate_http_proxy_auth()
202202
assert proxy_url == "https://user:password@https_proxy.com:8080"
203203
assert raw_proxy_url == "https://https_proxy.com:8080"
@@ -489,7 +489,6 @@ def test_get_connection_manager_ignores_certificates():
489489
assert conn.connection_pool_kw["timeout"] == 10
490490
assert conn.connection_pool_kw["cert_reqs"] == "CERT_NONE"
491491
assert isinstance(conn, urllib3.PoolManager)
492-
493492
remote_connection.reset_timeout()
494493
assert remote_connection.get_timeout() is None
495494

0 commit comments

Comments
 (0)