Path: blob/trunk/py/test/selenium/webdriver/remote/remote_connection_tests.py
4014 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import base6418import time1920import filetype21import pytest22from urllib3.exceptions import ReadTimeoutError2324from selenium import webdriver25from selenium.webdriver.common.by import By26from selenium.webdriver.remote.client_config import ClientConfig2728pytestmark = pytest.mark.xfail(reason="Tests not working as intended")293031def test_browser_specific_method(firefox_options, webserver, server, request):32"""Uses Firefox specific method."""33with webdriver.Remote(options=firefox_options) as driver:34driver.get(f"{webserver}/simpleTest.html")35screenshot = driver.execute("FULL_PAGE_SCREENSHOT")["value"]36result = base64.b64decode(screenshot)37kind = filetype.guess(result)38assert kind is not None39assert kind.mime == "image/png"404142def test_remote_webdriver_with_http_timeout(clean_options, webserver, server):43"""This test starts a remote webdriver with an http client timeout.4445It verifies the http timeout is triggered first when waiting for an element,46with the timeout set less than the implicit wait timeout.47"""48http_timeout = 449wait_timeout = 650server_addr = server.status_url.removesuffix("/status")51client_config = ClientConfig(remote_server_addr=server_addr, timeout=http_timeout)52with webdriver.Remote(options=clean_options, client_config=client_config) as driver:53driver.get(f"{webserver.where_is('simpleTest.html')}")54driver.implicitly_wait(wait_timeout)55with pytest.raises(ReadTimeoutError):56driver.find_element(By.ID, "no_element_to_be_found")575859def test_remote_webdriver_with_websocket_timeout(clean_options, webserver, server):60"""This test starts a remote webdriver that uses websockets, and has a websocket client timeout.6162It verifies the websocket times out according to this value.63"""64websocket_timeout = 2.065websocket_interval = 1.06667server_addr = server.status_url.removesuffix("/status")68client_config = ClientConfig(69remote_server_addr=server_addr, websocket_timeout=websocket_timeout, websocket_interval=websocket_interval70)71assert client_config.websocket_timeout == websocket_timeout72clean_options.enable_bidi = True73with webdriver.Remote(options=clean_options, client_config=client_config) as driver:74assert driver._websocket_connection.response_wait_timeout == websocket_timeout75assert driver._websocket_connection.response_wait_interval == websocket_interval76start = time.time()77driver._websocket_connection.close()78elapsed = time.time() - start79assert elapsed >= websocket_timeout80assert elapsed < websocket_timeout + 10818283