Files
browser-cli/tests/test_extract.py
T
daniel156161 1b53a884e7
Testing / test (push) Successful in 21s
Package Extension / package-extension (push) Successful in 10s
Build & Publish Package / publish (push) Successful in 20s
add delay wht more tests not conflict and fix tests with the current cli version
2026-04-10 13:41:49 +02:00

73 lines
2.2 KiB
Python

"""Tests for extract.* commands (require an http/https active tab)."""
import pytest
from browser_cli.client import send_command
def test_extract_links(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
links = browser("extract.links")
assert isinstance(links, list)
hrefs = []
for lnk in links:
assert "href" in lnk
assert "text" in lnk
hrefs.append(lnk["href"])
assert len(hrefs) == len(set(hrefs))
def test_extract_images(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
images = browser("extract.images")
assert isinstance(images, list)
sources = []
for img in images:
assert "src" in img
assert img["src"] != ""
sources.append(img["src"])
assert len(sources) == len(set(sources))
def test_extract_text(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
text = browser("extract.text")
assert isinstance(text, str)
assert len(text) > 0
def test_extract_html(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
html = browser("extract.html")
assert isinstance(html, str)
assert "<" in html
def test_extract_markdown(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
markdown = browser("extract.markdown")
assert isinstance(markdown, str)
assert len(markdown.strip()) > 0
def test_extract_markdown_missing_selector_errors(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
assert browser("dom.exists", {"selector": ".browser-cli-definitely-missing"}) is False
try:
browser("extract.markdown", {"selector": ".browser-cli-definitely-missing"})
except RuntimeError as exc:
assert "No element" in str(exc)
def test_dom_exists(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
result = browser("dom.exists", {"selector": "body"})
assert result is True
def test_dom_query(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
elements = browser("dom.query", {"selector": "body"})
assert isinstance(elements, list)
assert len(elements) > 0
assert elements[0].get("tag") == "body"