diff --git a/py/conftest.py b/py/conftest.py index b076e18313e71..b1a3e7ca8afd0 100644 --- a/py/conftest.py +++ b/py/conftest.py @@ -399,6 +399,13 @@ def clean_driver(request): @pytest.fixture def firefox_options(request): + try: + driver_option = request.config.option.drivers[0] + except (AttributeError, TypeError): + raise Exception("This test requires a --driver to be specified") + # skip tests in the 'remote' directory if run with a local driver + if request.node.path.parts[-2] == "remote" and get_driver_class(driver_option) != "Remote": + pytest.skip(f"Remote tests can't be run with driver '{driver_option}'") options = webdriver.FirefoxOptions() if request.config.option.headless: options.add_argument("-headless") diff --git a/py/selenium/webdriver/remote/client_config.py b/py/selenium/webdriver/remote/client_config.py index f5eec5aaf9251..3157e63b6cf70 100644 --- a/py/selenium/webdriver/remote/client_config.py +++ b/py/selenium/webdriver/remote/client_config.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + import base64 import os import socket @@ -96,7 +97,7 @@ def __init__( self.proxy = proxy self.ignore_certificates = ignore_certificates self.init_args_for_pool_manager = init_args_for_pool_manager or {} - self.timeout = timeout + self.timeout = socket.getdefaulttimeout() if timeout is None else timeout self.username = username self.password = password self.auth_type = auth_type @@ -104,16 +105,6 @@ def __init__( self.user_agent = user_agent self.extra_headers = extra_headers - self.timeout = ( - ( - float(os.getenv("GLOBAL_DEFAULT_TIMEOUT", str(socket.getdefaulttimeout()))) - if os.getenv("GLOBAL_DEFAULT_TIMEOUT") is not None - else socket.getdefaulttimeout() - ) - if timeout is None - else timeout - ) - self.ca_certs = ( (os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where()) if ca_certs is None diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 1bc432084b6e2..a70981da0e0d6 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -152,11 +152,7 @@ class RemoteConnection: import certifi - _timeout = ( - float(os.getenv("GLOBAL_DEFAULT_TIMEOUT", str(socket.getdefaulttimeout()))) - if os.getenv("GLOBAL_DEFAULT_TIMEOUT") is not None - else socket.getdefaulttimeout() - ) + _timeout = socket.getdefaulttimeout() _ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where() _client_config: ClientConfig = None diff --git a/py/test/selenium/webdriver/remote/remote_connection_tests.py b/py/test/selenium/webdriver/remote/remote_connection_tests.py index 438bc26cb0c42..2ca8d57a7ec04 100644 --- a/py/test/selenium/webdriver/remote/remote_connection_tests.py +++ b/py/test/selenium/webdriver/remote/remote_connection_tests.py @@ -18,6 +18,12 @@ import base64 import filetype +import pytest +from urllib3.exceptions import ReadTimeoutError + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.remote.client_config import ClientConfig def test_browser_specific_method(driver, pages): @@ -27,3 +33,20 @@ def test_browser_specific_method(driver, pages): result = base64.b64decode(screenshot) kind = filetype.guess(result) assert kind is not None and kind.mime == "image/png" + + +def test_remote_webdriver_with_http_timeout(firefox_options, webserver): + """This test starts a remote webdriver with an http client timeout + set less than the implicit wait timeout, and verifies the http timeout + is triggered first when waiting for an element. + """ + http_timeout = 6 + wait_timeout = 8 + server_addr = f"http://{webserver.host}:{webserver.port}" + client_config = ClientConfig(remote_server_addr=server_addr, timeout=http_timeout) + assert client_config.timeout == http_timeout + with webdriver.Remote(options=firefox_options, client_config=client_config) as driver: + driver.get(f"{server_addr}/simpleTest.html") + driver.implicitly_wait(wait_timeout) + with pytest.raises(ReadTimeoutError): + driver.find_element(By.ID, "no_element_to_be_found")