adding new extract command to extract selector or main content as markdown, updateing version as 0.5.0
Package Extension / package-extension (push) Successful in 12s
Build & Publish Package / publish (push) Failing after 21s

This commit is contained in:
2026-04-10 03:44:49 +02:00
parent 79093ed558
commit f2a7f85ee3
8 changed files with 286 additions and 2 deletions
+15
View File
@@ -182,6 +182,21 @@ class TestSearch:
assert mock_send.call_args[0][1]["background"] is True
class TestExtract:
def test_extract_markdown_default(self, b, mock_send):
mock_send.return_value = "# Title"
result = b.extract_markdown()
assert result == "# Title"
mock_send.assert_called_once_with("extract.markdown", {"selector": None}, profile=None)
def test_extract_markdown_selector(self, b, mock_send):
b.extract_markdown("article")
mock_send.assert_called_once_with("extract.markdown", {"selector": "article"}, profile=None)
# ── Tabs ──────────────────────────────────────────────────────────────────────
class TestTabs:
+16
View File
@@ -54,3 +54,19 @@ def test_clients_exits_cleanly_when_registry_is_missing():
assert result.exit_code == 1
assert "No browser clients found" in result.output
def test_extract_markdown_command():
with patch("browser_cli.commands.extract.send_command", return_value="# Title\n") as send_command:
result = CliRunner().invoke(main, ["extract", "markdown"])
assert result.exit_code == 0
assert result.output == "# Title\n"
send_command.assert_called_once_with("extract.markdown", {"selector": None})
def test_extract_markdown_command_with_selector():
with patch("browser_cli.commands.extract.send_command", return_value="## Post\n") as send_command:
result = CliRunner().invoke(main, ["extract", "markdown", "--selector", "article"])
assert result.exit_code == 0
assert result.output == "## Post\n"
send_command.assert_called_once_with("extract.markdown", {"selector": "article"})
+19
View File
@@ -7,18 +7,24 @@ 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):
@@ -35,6 +41,19 @@ def test_extract_html(browser, http_tab):
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"]})
with pytest.raises(RuntimeError, match="No element"):
browser("extract.markdown", {"selector": ".browser-cli-definitely-missing"})
def test_dom_exists(browser, http_tab):
browser("tabs.active", {"tabId": http_tab["id"]})
result = browser("dom.exists", {"selector": "body"})