Skip to content

Commit

Permalink
Add tests for find
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanlensky committed Jan 28, 2025
1 parent c01136c commit ec851f7
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 3 deletions.
Empty file added tests/__init__.py
Empty file.
Empty file added tests/bot_detection/__init__.py
Empty file.
Empty file added tests/core/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions tests/core/test_tab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import asyncio

import pytest

import zendriver as zd
from tests.sample_data import sample_file


async def test_set_user_agent_sets_navigator_values(browser: zd.Browser):
Expand Down Expand Up @@ -26,3 +31,20 @@ async def test_set_user_agent_defaults_existing_user_agent(browser: zd.Browser):
navigator_language = await tab.evaluate("navigator.language")
assert navigator_user_agent == existing_user_agent
assert navigator_language == "testLang"


async def test_find_finds_element_by_text(browser: zd.Browser):
tab = await browser.get(sample_file("groceries.html"))

result = await tab.find("Apples")

assert result is not None
assert result.tag == "li"
assert result.text == "Apples"


async def test_find_times_out_if_element_not_found(browser: zd.Browser):
tab = await browser.get(sample_file("groceries.html"))

with pytest.raises(asyncio.TimeoutError):
await tab.find("Clothes", timeout=1)
6 changes: 6 additions & 0 deletions tests/sample_data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pathlib import Path


def sample_file(name: str) -> str:
path = (Path(__file__).parent / name).absolute()
return f"file://{path}"
19 changes: 19 additions & 0 deletions tests/sample_data/groceries.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Grocery List</title>
</head>

<body>
<h1>Grocery List</h1>
<ul>
<li>Apples</li>
<li>Bananas</li>
<li>Carrots</li>
<li>Donuts</li>
<li>Eggs</li>
<li>French Fries</li>
<li>Grapes</li>
<ul>
</body>
</html>
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ec851f7

Please sign in to comment.