Skip to main content

Crate llm_browser_testkit

Crate llm_browser_testkit 

Source
Expand description

LLM-driven browser test framework.

Provides reusable building blocks for browser-based test scenarios:

  • Browser client via Chrome DevTools Protocol (headless)
  • LLM client for natural language element targeting and assertions
  • A2A agent integration for agent-to-agent communication
  • MCP client/server integration for tool-calling
  • Cost tracking, token counting, and budget enforcement
  • Declarative TOML scenario runner
  • #[browser_test] macros for cargo test integration

Re-exports§

pub use costs::LlmResponse;
pub use costs::LlmUsage;

Modules§

a2a
A2A agent protocol client. A2A (Agent-to-Agent) protocol client.
budgets
Budget tracking and enforcement. Budget tracking and enforcement.
costs
Cost calculation, usage tracking, and pricing. Cost calculation, usage tracking, and pricing logic.
endpoints
Endpoint registry and routing resolver. Endpoint registry — resolves named endpoints and task-type routing.
mcp_client
MCP client for connecting to external MCP servers. MCP (Model Context Protocol) client.
mcp_server
MCP server for exposing the framework as an MCP server. MCP server exposure — exposes the framework as an MCP server.
reporting
Cost and token report printer. Cost and token report printer.
runner
Step-by-step scenario executor (navigate, click, type, wait, assert).
scenario
Declarative TOML-based test scenario types. Scenario types for human-readable browser test case definitions.

Structs§

LlmConfig
Configuration for the LLM client — bundles URL, model, auth, timeouts, and provider-specific options into a single struct passed everywhere.

Constants§

DOM_EXTRACT_JS
JavaScript to extract interactive elements from the current page. Returns a JSON array of objects with tag, selector, and label.

Functions§

base_url
Returns the target base URL from HARNESS_BROWSER_BASE_URL env, defaulting to http://localhost:4200.
browser_headless
Returns whether to run the browser in headless mode from HARNESS_BROWSER_HEADLESS env, defaulting to true.
http_client
Builds a reqwest::Client with the given timeout.
llm_base_url
Returns the LLM server base URL from HARNESS_LLM_TEST_URL env, defaulting to http://localhost:8080.
llm_chat
Sends a chat completion request to the LLM.
llm_chat_with_usage
Sends a chat completion request to the LLM and returns both the content and token usage from the API response.
llm_model
Returns the LLM model name from HARNESS_LLM_TEST_MODEL env, defaulting to deepseek.
parse_headers_env
Parses HARNESS_LLM_HEADERS env var (JSON object) into a header map.
truncate
Truncates a string to the given maximum length, appending a marker if truncation occurred.