add moveing of tabs and groups, multi browser support, auto complite into terminal, extract html and adding testing
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
"""Tests for tabs.* commands."""
|
||||
import pytest
|
||||
from browser_cli.client import send_command
|
||||
|
||||
|
||||
def test_tabs_list(browser):
|
||||
tabs = browser("tabs.list")
|
||||
assert isinstance(tabs, list)
|
||||
assert len(tabs) > 0
|
||||
first = tabs[0]
|
||||
assert "id" in first
|
||||
assert "windowId" in first
|
||||
assert "url" in first
|
||||
assert "title" in first
|
||||
|
||||
|
||||
def test_tabs_count(browser):
|
||||
count = browser("tabs.count", {})
|
||||
tabs = browser("tabs.list")
|
||||
assert count == len(tabs)
|
||||
|
||||
|
||||
def test_tabs_count_with_pattern(browser):
|
||||
count = browser("tabs.count", {"pattern": "http"})
|
||||
assert isinstance(count, int)
|
||||
assert count >= 0
|
||||
|
||||
|
||||
def test_tabs_filter(browser):
|
||||
result = browser("tabs.filter", {"pattern": "http"})
|
||||
assert isinstance(result, list)
|
||||
for tab in result:
|
||||
assert "http" in tab.get("url", "")
|
||||
|
||||
|
||||
def test_tabs_query(browser):
|
||||
result = browser("tabs.query", {"search": "a"})
|
||||
assert isinstance(result, list)
|
||||
|
||||
|
||||
def test_tabs_active_exists(browser):
|
||||
tabs = browser("tabs.list")
|
||||
active = [t for t in tabs if t.get("active")]
|
||||
assert len(active) >= 1, "Expected at least one active tab"
|
||||
|
||||
|
||||
def test_tabs_html(browser, http_tab):
|
||||
html = browser("tabs.html", {"tabId": http_tab["id"]})
|
||||
assert isinstance(html, str)
|
||||
assert len(html) > 0
|
||||
assert "<html" in html.lower() or "<!doctype" in html.lower()
|
||||
|
||||
|
||||
def test_tabs_close_by_id(browser):
|
||||
result = browser("navigate.open", {"url": "https://example.com", "background": True})
|
||||
tab_id = result["id"]
|
||||
|
||||
browser("tabs.close", {"tabId": tab_id})
|
||||
|
||||
tabs = browser("tabs.list")
|
||||
assert tab_id not in [t["id"] for t in tabs]
|
||||
|
||||
|
||||
def test_tabs_dedupe(browser):
|
||||
# Open the same URL twice
|
||||
r1 = browser("navigate.open", {"url": "https://example.com", "background": True})
|
||||
r2 = browser("navigate.open", {"url": "https://example.com", "background": True})
|
||||
id1, id2 = r1["id"], r2["id"]
|
||||
|
||||
try:
|
||||
result = browser("tabs.dedupe")
|
||||
assert isinstance(result, dict)
|
||||
assert result.get("closed", 0) >= 0
|
||||
# At least one of the two duplicates should be gone
|
||||
remaining = browser("tabs.list")
|
||||
remaining_ids = {t["id"] for t in remaining}
|
||||
assert not (id1 in remaining_ids and id2 in remaining_ids), \
|
||||
"Both duplicate tabs still open after dedupe"
|
||||
finally:
|
||||
for tid in (id1, id2):
|
||||
try:
|
||||
browser("tabs.close", {"tabId": tid})
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def test_tabs_sort(browser):
|
||||
result = browser("tabs.sort", {"by": "domain"})
|
||||
# No error and at least returns something (None or dict)
|
||||
assert result is None or isinstance(result, dict)
|
||||
|
||||
|
||||
def test_tabs_move_forward(browser):
|
||||
r1 = browser("navigate.open", {"url": "https://example.com", "background": True})
|
||||
r2 = browser("navigate.open", {"url": "https://example.com", "background": True})
|
||||
id1, id2 = r1["id"], r2["id"]
|
||||
|
||||
try:
|
||||
# Move id1 forward — just verify no error is raised
|
||||
browser("tabs.move", {"tabId": id1, "forward": True})
|
||||
finally:
|
||||
browser("tabs.close", {"tabId": id1})
|
||||
browser("tabs.close", {"tabId": id2})
|
||||
|
||||
|
||||
def test_tabs_merge_windows_no_crash(browser):
|
||||
result = browser("tabs.merge_windows")
|
||||
assert isinstance(result, dict)
|
||||
assert "moved" in result
|
||||
Reference in New Issue
Block a user