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
1865 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
20
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
27
28
29
def test_browser_specific_method(driver, pages):
30
"""This only works on Firefox"""
31
pages.load("simpleTest.html")
32
screenshot = driver.execute("FULL_PAGE_SCREENSHOT")["value"]
33
result = base64.b64decode(screenshot)
34
kind = filetype.guess(result)
35
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")
53
54