Files
browser-cli/tests/test_dom.py
T
daniel156161 a9071abc9a
Package Extension / package-extension (push) Successful in 24s
Build & Publish Package / publish (push) Successful in 31s
Testing / test (push) Successful in 26s
cleanup tests
2026-05-02 01:48:13 +02:00

61 lines
2.1 KiB
Python

"""Tests for dom.* commands (require an http/https active tab)."""
def test_dom_query_body(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
elements = browser("dom.query", {"selector": "body"})
assert isinstance(elements, list)
assert len(elements) == 1
assert elements[0]["tag"] == "body"
def test_dom_query_multiple(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
# Every HTML page has at least one element
elements = browser("dom.query", {"selector": "*"})
assert isinstance(elements, list)
assert len(elements) > 1
def test_dom_query_no_match(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
elements = browser("dom.query", {"selector": "#zzz_no_such_element_zzz"})
assert isinstance(elements, list)
assert len(elements) == 0
def test_dom_exists_true(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
result = browser("dom.exists", {"selector": "html"})
assert result is True
def test_dom_exists_false(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
result = browser("dom.exists", {"selector": "#zzz_no_such_element_zzz"})
assert result is False
def test_dom_text_body(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
texts = browser("dom.text", {"selector": "body"})
assert isinstance(texts, list)
assert len(texts) > 0
assert isinstance(texts[0], str)
assert len(texts[0]) > 0
def test_dom_attr_returns_list(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
# Get href of all anchor tags — page may or may not have any
hrefs = browser("dom.attr", {"selector": "a", "attr": "href"})
assert isinstance(hrefs, list)
def test_dom_attr_html_lang(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
langs = browser("dom.attr", {"selector": "html", "attr": "lang"})
assert isinstance(langs, list)
# html element exists so we get exactly one entry (may be empty string if no lang attr)
assert len(langs) <= 1