Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #611: Fix ImportError in browser_use/agent/tests.py (#611) #624

Merged
merged 4 commits into from
Feb 12, 2025

Conversation

k-w-lee
Copy link
Contributor

@k-w-lee k-w-lee commented Feb 8, 2025

Pull Request: Fix Agent Test by Adding ExtractPageContentAction

This PR resolves #611

Summary

This PR fixes failing agent tests by introducing ExtractPageContentAction into the controller. The test cases require this action to properly validate the model outputs.

Changes Made

  1. Added ExtractPageContentAction in browser_use/controller/views.py to support test validation.
  2. Fix missing page_summary in Agent Brain
  3. Updated interacted elements in AgentHistory samples to include meaningful interactions (xpath values).
  4. Updated agent tests (browser_use/agent/tests.py) to include extract_page_content in expected outputs.
  5. Fixed assertion issues by ensuring correct dictionary comparisons for action outputs.

Why This Change?

  • The test suite was missing ExtractPageContentAction, leading to assertion errors.
  • Ensures the agent's model outputs align with expected behavior.
  • Improves test reliability by correctly handling page content extraction.

Impact & Risk

Low risk – This change only introduces an action already referenced in tests.
Backward compatible – No existing logic is modified, only extended to support test cases.

Next Steps

  • Merge this PR to ensure test cases pass.
  • Validate with other agents to check for similar missing actions.

Let me know if you need any adjustments! 🚀

❌Before the Changes

Even before add the ExtractPageContentAction, it has 8 errors occur, this pull request will fix the bugs in the test case:
image

✅ After the Changes

Screenshot 2025-02-08 at 6 45 29 PM

Copy link
Contributor

codebeaver-ai bot commented Feb 8, 2025

I opened a Pull Request with the following:

🔄 1 test added.
🐛 No bugs detected in your changes
🛠️ 1/8 tests passed

🔄 Test Updates

I've added 1 tests. They all pass ☑️
New Tests:

  • tests/test_views.py

No existing tests required updates.

🐛 Bug Detection

No bugs detected in your changes. Good job!

🛠️ Test Results

1/8 tests passed ⚠️

tests/test_dropdown.py

View error
tests/test_dropdown.py:20: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_dropdown.py

tests/test_dropdown_complex.py

View error
tests/test_dropdown_complex.py:20: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_dropdown_complex.py

tests/test_dropdown_error.py

View error
tests/test_dropdown_error.py:20: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_dropdown_error.py

tests/test_gif_path.py

View error
tests/test_gif_path.py:19: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_gif_path.py

tests/test_models.py

View error
tests/test_models.py:54: in <module>
    ChatOpenAI(
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_models.py

tests/test_react_dropdown.py

View error
tests/test_react_dropdown.py:20: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_react_dropdown.py

tests/test_vision.py

View error
tests/test_vision.py:25: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_vision.py

☂️ Coverage Improvements

Coverage improvements by file:

  • tests/test_views.py

    New coverage: 100.00%
    Improvement: +100.00%

🎨 Final Touches

  • I ran the hooks included in the pre-commit config.

Settings | Logs | CodeBeaver

@MagMueller MagMueller merged commit abd1aeb into browser-use:main Feb 12, 2025
2 checks passed
AryamanParida pushed a commit to AryamanParida/browser-use that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImportError in browser_use/agent/tests.py
2 participants