Skip to content

Commit 169ce63

Browse files
authored
[py] Remove support for GLOBAL_DEFAULT_TIMEOUT environment variable (#15673)
1 parent e8331d1 commit 169ce63

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

py/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@ def clean_driver(request):
399399

400400
@pytest.fixture
401401
def firefox_options(request):
402+
try:
403+
driver_option = request.config.option.drivers[0]
404+
except (AttributeError, TypeError):
405+
raise Exception("This test requires a --driver to be specified")
406+
# skip tests in the 'remote' directory if run with a local driver
407+
if request.node.path.parts[-2] == "remote" and get_driver_class(driver_option) != "Remote":
408+
pytest.skip(f"Remote tests can't be run with driver '{driver_option}'")
402409
options = webdriver.FirefoxOptions()
403410
if request.config.option.headless:
404411
options.add_argument("-headless")

py/selenium/webdriver/remote/client_config.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
import base64
1819
import os
1920
import socket
@@ -96,24 +97,14 @@ def __init__(
9697
self.proxy = proxy
9798
self.ignore_certificates = ignore_certificates
9899
self.init_args_for_pool_manager = init_args_for_pool_manager or {}
99-
self.timeout = timeout
100+
self.timeout = socket.getdefaulttimeout() if timeout is None else timeout
100101
self.username = username
101102
self.password = password
102103
self.auth_type = auth_type
103104
self.token = token
104105
self.user_agent = user_agent
105106
self.extra_headers = extra_headers
106107

107-
self.timeout = (
108-
(
109-
float(os.getenv("GLOBAL_DEFAULT_TIMEOUT", str(socket.getdefaulttimeout())))
110-
if os.getenv("GLOBAL_DEFAULT_TIMEOUT") is not None
111-
else socket.getdefaulttimeout()
112-
)
113-
if timeout is None
114-
else timeout
115-
)
116-
117108
self.ca_certs = (
118109
(os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where())
119110
if ca_certs is None

py/selenium/webdriver/remote/remote_connection.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ class RemoteConnection:
152152

153153
import certifi
154154

155-
_timeout = (
156-
float(os.getenv("GLOBAL_DEFAULT_TIMEOUT", str(socket.getdefaulttimeout())))
157-
if os.getenv("GLOBAL_DEFAULT_TIMEOUT") is not None
158-
else socket.getdefaulttimeout()
159-
)
155+
_timeout = socket.getdefaulttimeout()
160156
_ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where()
161157
_client_config: ClientConfig = None
162158

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

+23
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
import base64
1919

2020
import filetype
21+
import pytest
22+
from urllib3.exceptions import ReadTimeoutError
23+
24+
from selenium import webdriver
25+
from selenium.webdriver.common.by import By
26+
from selenium.webdriver.remote.client_config import ClientConfig
2127

2228

2329
def test_browser_specific_method(driver, pages):
@@ -27,3 +33,20 @@ def test_browser_specific_method(driver, pages):
2733
result = base64.b64decode(screenshot)
2834
kind = filetype.guess(result)
2935
assert kind is not None and kind.mime == "image/png"
36+
37+
38+
def test_remote_webdriver_with_http_timeout(firefox_options, webserver):
39+
"""This test starts a remote webdriver with an http client timeout
40+
set less than the implicit wait timeout, and verifies the http timeout
41+
is triggered first when waiting for an element.
42+
"""
43+
http_timeout = 6
44+
wait_timeout = 8
45+
server_addr = f"http://{webserver.host}:{webserver.port}"
46+
client_config = ClientConfig(remote_server_addr=server_addr, timeout=http_timeout)
47+
assert client_config.timeout == http_timeout
48+
with webdriver.Remote(options=firefox_options, client_config=client_config) as driver:
49+
driver.get(f"{server_addr}/simpleTest.html")
50+
driver.implicitly_wait(wait_timeout)
51+
with pytest.raises(ReadTimeoutError):
52+
driver.find_element(By.ID, "no_element_to_be_found")

0 commit comments

Comments
 (0)