refactored import structure and created full tests

This commit is contained in:
2025-11-04 19:09:29 +01:00
parent 7249a812f5
commit 5b0afea651
4 changed files with 29 additions and 3 deletions

0
experiments/__init__.py Normal file
View File

View File

@@ -1,5 +1,4 @@
from os import environ
from base import Agent as BaseAgent
from experiments.agents.base import Agent as BaseAgent
from browser_use import Browser, Agent, ChatOpenAI
from enum import Enum
@@ -28,6 +27,7 @@ class GenericBrowserUseAgent(BaseAgent):
browser=self.browser)
async def act(self) -> str:
self.result = await self.agent.run()
# https://github.com/browser-use/browser-use/blob/main/browser_use/agent/views.py#L301
return self.result.final_result()
def get_agent(agent_type: AgentTypes, **kwargs) -> Agent:

View File

@@ -1,3 +1,27 @@
import pytest
import asyncio
from experiments.agents.agent import get_agent, AgentTypes
from agent import get_agent
def test_agent_init():
agent = get_agent(AgentTypes.GENERIC_BROWSER_USE_AGENT, goal="test", url="http://example.com", timeout=100)
assert agent.goal == "test"
assert agent.url == "http://example.com"
assert agent.timeout == 100
def test_invalid_agent():
with pytest.raises(ValueError):
get_agent("invalid", goal="test")
@pytest.mark.asyncio
async def test_agent_execution():
agent = get_agent(AgentTypes.GENERIC_BROWSER_USE_AGENT, goal="get page title", url="https://example.com", timeout=60)
result = await agent.act()
assert result
assert agent.final_result()
assert agent.final_result().history[-1].result[-1].is_done == True
assert isinstance(result, str)
assert "example" in result.lower()
assert len(result) > 0