Skip to content

Commit 0a4bea2

Browse files
committed
WIP
1 parent 1a919ad commit 0a4bea2

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/unit/a11y/test_utils.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from unittest.mock import AsyncMock, MagicMock, patch
2+
from typing import Any, TYPE_CHECKING
3+
4+
import pytest
5+
6+
from stagehand import StagehandPage
7+
from stagehand.a11y import get_accessibility_tree
8+
9+
if TYPE_CHECKING:
10+
from stagehand.logging import StagehandLogger
11+
else:
12+
StagehandLogger = Any
13+
14+
pytestmark = [pytest.mark.asyncio]
15+
16+
17+
@pytest.fixture
18+
def mock_stagehand_logger():
19+
with patch('stagehand.a11y.utils.StagehandLogger'):
20+
mock_logger = MagicMock()
21+
yield mock_logger
22+
23+
24+
class TestGetAccessibilityTree:
25+
async def test_empty_tree_result(self, mock_stagehand_page: StagehandPage, mock_stagehand_logger: StagehandLogger):
26+
mock_stagehand_page.send_cdp = AsyncMock(return_value={"nodes": []})
27+
actual = await get_accessibility_tree(mock_stagehand_page, mock_stagehand_logger)
28+
assert actual["simplified"] == ""
29+
assert actual["tree"] == []
30+
assert actual["iframes"] == []
31+
assert actual["idToUrl"] == {}
32+
33+
async def test_another(self, mock_stagehand_page: StagehandPage, mock_stagehand_logger: StagehandLogger):
34+
mock_stagehand_page.send_cdp = AsyncMock(return_value={"nodes": [
35+
{
36+
"backendNodeId": "",
37+
"role": "",
38+
"value": {},
39+
},
40+
41+
]})
42+
actual = await get_accessibility_tree(mock_stagehand_page, mock_stagehand_logger)
43+
assert actual["simplified"] == ""
44+
assert actual["tree"] == []
45+
assert actual["iframes"] == []
46+
assert actual["idToUrl"] == {}
47+
48+
class TestFindScrollableElementIds:
49+
async def test_something(self):
50+
raise NotImplementedError

0 commit comments

Comments
 (0)