Set Up Browser-Use Models for Agentic Navigation | desplega.ai
Learn how to configure browser-use AI models in desplega.ai to enable agentic navigation that autonomously drives end-to-end tests across your web app.
Prerequisites
- Python 3.11+ installed on your machine or CI environment.
- A desplega.ai account with an active project and a valid project token.
- An API key for your chosen LLM provider — OpenAI, Anthropic, or an OpenAI-compatible endpoint.
- Playwright browsers installed, which browser-use depends on for headless automation.
Agentic navigation flips traditional end-to-end testing on its head: instead of scripting every click, you describe an outcome and let an LLM-powered browser agent figure out how to reach it. This guide walks through wiring the popular browser-use library into your desplega.ai project so every run is recorded, replayable, and production-grade. If you're also exploring model-driven workflows inside your editor, pair this with our guide on configuring MCP for Cursor to unify agentic testing and coding in a single loop.
Install the browser-use package
Add the browser-use library to your project dependencies so desplega.ai can invoke AI-driven browser agents during test runs. We recommend pinning a minor version in a requirements file so CI stays deterministic — browser-use is under active development and its API surface is still evolving.
pip install browser-use
# or, if you use a requirements file:
echo 'browser-use>=0.1.0' >> requirements.txt && pip install -r requirements.txtChoose and configure your LLM provider
Select the language model that will power agentic navigation — OpenAI GPT-4o, Anthropic Claude, or any OpenAI-compatible endpoint — and export your API key as an environment variable. GPT-4o is a strong default because it balances vision reasoning with latency, while Claude 3.5 Sonnet tends to be more deliberate on multi-step flows. If cost matters, self-hosted models behind an OpenAI-compatible gateway are fully supported.
# OpenAI example
export OPENAI_API_KEY="sk-..."
# Anthropic example
export ANTHROPIC_API_KEY="sk-ant-..."
# Custom OpenAI-compatible endpoint
export OPENAI_BASE_URL="https://your-endpoint.example.com/v1"Instantiate the Agent with your chosen model
Create a browser-use Agent in your test file, passing the task description and the LLM instance so the agent knows what to navigate and which model to use. The task string is essentially a natural-language prompt — the more specific and outcome-oriented it is, the more reliable the agent will be. Prefer verbs like "verify", "confirm", or "submit" over vague descriptions.
from browser_use import Agent
from langchain_openai import ChatOpenAI
agent = Agent(
task="Log in to the app and verify the dashboard loads",
llm=ChatOpenAI(model="gpt-4o"),
)Connect the agent to desplega.ai
Point the agent at your desplega.ai project by supplying your project token, which lets the platform record sessions, capture screenshots, and attach results to the relevant test suite. The token is injected as a custom header so every Playwright request the agent issues is tagged with the correct project and run context. Store it in your secret manager — never commit it directly.
import os
from browser_use import Agent, BrowserConfig
from langchain_openai import ChatOpenAI
agent = Agent(
task="Log in to the app and verify the dashboard loads",
llm=ChatOpenAI(model="gpt-4o"),
browser_config=BrowserConfig(
extra_headers={
"X-Desplega-Token": os.environ["DESPLEGA_PROJECT_TOKEN"]
}
),
)Run the agentic navigation task
Execute the agent's run coroutine inside an async context to kick off the autonomous browser session and capture the result for assertion. Because browser-use is fully async, wrap the call in asyncio.run if you're invoking it as a standalone script, or use your test framework's async runner (e.g. pytest-asyncio) inside a suite.
import asyncio
async def main():
result = await agent.run()
print(result) # inspect final agent output
asyncio.run(main())Assert outcomes and review the session replay
Use the returned result object to assert key conditions in your test framework, then open the desplega.ai dashboard to review the full session replay, annotated screenshots, and step-by-step agent reasoning. This last piece is where agentic tests earn their keep: instead of a red X and a stack trace, you get a narrated timeline of what the model saw, decided, and clicked — perfect for debugging flaky flows or onboarding new engineers.
async def main():
result = await agent.run()
# Example assertion with pytest
assert result.is_done(), "Agent did not complete the task"
assert "dashboard" in result.final_result().lower()
asyncio.run(main())With these six steps in place, your desplega.ai project is ready to run production-grade agentic navigation on every commit. As your suite grows, consider extracting shared task templates, tuning temperature per model, and using desplega.ai's replay diffing to catch subtle UI regressions the agent might otherwise route around.
Related Guides
Issues
Track and manage test failures and issues effectively. Learn how to identify, categorize, and resolve testing issues in your workflow.
Vibe QA Extension
Power your vibe coding workflow with AI-powered QA testing. The Desplega.ai Vibe QA Extension integrates seamlessly with Lovable, bringing enterprise-grade testing directly into your development workflow.
Personas
Test your application with different user personas to ensure comprehensive coverage. Learn how to create and use personas in your testing strategy.