31 lines
990 B
Python
31 lines
990 B
Python
"""
|
|
Shared pytest fixtures for browser-cli integration tests.
|
|
|
|
Tests that require a live browser connection use the `browser` fixture.
|
|
They are automatically skipped if the native host socket is not reachable.
|
|
"""
|
|
import pytest
|
|
from browser_cli.client import send_command, BrowserNotConnected
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def browser():
|
|
"""Returns a connected send_command callable, or skips the test."""
|
|
try:
|
|
send_command("tabs.list")
|
|
except BrowserNotConnected:
|
|
pytest.skip("Browser not connected — start Brave/Chrome with the extension loaded")
|
|
return send_command
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def http_tab(browser):
|
|
"""Ensures at least one http/https tab is open; returns its tab info."""
|
|
tabs = browser("tabs.list")
|
|
http_tab = next(
|
|
(t for t in tabs if t.get("url", "").startswith("http")), None
|
|
)
|
|
if http_tab is None:
|
|
pytest.skip("No http/https tab open — open a web page first")
|
|
return http_tab
|