Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/remote/remote_connection_tests.py
4014 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
import base64
19
import time
20
21
import filetype
22
import pytest
23
from urllib3.exceptions import ReadTimeoutError
24
25
from selenium import webdriver
26
from selenium.webdriver.common.by import By
27
from selenium.webdriver.remote.client_config import ClientConfig
28
29
pytestmark = pytest.mark.xfail(reason="Tests not working as intended")
30
31
32
def test_browser_specific_method(firefox_options, webserver, server, request):
33
"""Uses Firefox specific method."""
34
with webdriver.Remote(options=firefox_options) as driver:
35
driver.get(f"{webserver}/simpleTest.html")
36
screenshot = driver.execute("FULL_PAGE_SCREENSHOT")["value"]
37
result = base64.b64decode(screenshot)
38
kind = filetype.guess(result)
39
assert kind is not None
40
assert kind.mime == "image/png"
41
42
43
def test_remote_webdriver_with_http_timeout(clean_options, webserver, server):
44
"""This test starts a remote webdriver with an http client timeout.
45
46
It verifies the http timeout is triggered first when waiting for an element,
47
with the timeout set less than the implicit wait timeout.
48
"""
49
http_timeout = 4
50
wait_timeout = 6
51
server_addr = server.status_url.removesuffix("/status")
52
client_config = ClientConfig(remote_server_addr=server_addr, timeout=http_timeout)
53
with webdriver.Remote(options=clean_options, client_config=client_config) as driver:
54
driver.get(f"{webserver.where_is('simpleTest.html')}")
55
driver.implicitly_wait(wait_timeout)
56
with pytest.raises(ReadTimeoutError):
57
driver.find_element(By.ID, "no_element_to_be_found")
58
59
60
def test_remote_webdriver_with_websocket_timeout(clean_options, webserver, server):
61
"""This test starts a remote webdriver that uses websockets, and has a websocket client timeout.
62
63
It verifies the websocket times out according to this value.
64
"""
65
websocket_timeout = 2.0
66
websocket_interval = 1.0
67
68
server_addr = server.status_url.removesuffix("/status")
69
client_config = ClientConfig(
70
remote_server_addr=server_addr, websocket_timeout=websocket_timeout, websocket_interval=websocket_interval
71
)
72
assert client_config.websocket_timeout == websocket_timeout
73
clean_options.enable_bidi = True
74
with webdriver.Remote(options=clean_options, client_config=client_config) as driver:
75
assert driver._websocket_connection.response_wait_timeout == websocket_timeout
76
assert driver._websocket_connection.response_wait_interval == websocket_interval
77
start = time.time()
78
driver._websocket_connection.close()
79
elapsed = time.time() - start
80
assert elapsed >= websocket_timeout
81
assert elapsed < websocket_timeout + 10
82
83