forked from SeleniumHQ/seleniumhq.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_network.py
More file actions
49 lines (36 loc) · 1.73 KB
/
test_network.py
File metadata and controls
49 lines (36 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import base64
import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.common.devtools.v145.network import Headers
@pytest.mark.trio
async def test_basic_auth(driver):
async with driver.bidi_connection() as connection:
await connection.session.execute(connection.devtools.network.enable())
credentials = base64.b64encode("admin:admin".encode()).decode()
auth = {'authorization': 'Basic ' + credentials}
await connection.session.execute(connection.devtools.network.set_extra_http_headers(Headers(auth)))
driver.get('https://the-internet.herokuapp.com/basic_auth')
success = driver.find_element(by=By.TAG_NAME, value='p')
assert success.text == 'Congratulations! You must have the proper credentials.'
@pytest.mark.trio
async def test_performance(driver):
driver.get('https://www.selenium.dev/selenium/web/frameset.html')
async with driver.bidi_connection() as connection:
await connection.session.execute(connection.devtools.performance.enable())
metric_list = await connection.session.execute(connection.devtools.performance.get_metrics())
metrics = {metric.name: metric.value for metric in metric_list}
assert metrics["DevToolsCommandDuration"] > 0
assert metrics["Frames"] == 12
@pytest.mark.trio
async def test_set_cookie(driver):
async with driver.bidi_connection() as connection:
execution = connection.devtools.network.set_cookie(
name="cheese",
value="gouda",
domain="www.selenium.dev",
secure=True
)
await connection.session.execute(execution)
driver.get("https://www.selenium.dev")
cheese = driver.get_cookie("cheese")
assert cheese["value"] == "gouda"