browser-use-e2e
Generate and run E2E tests using browser-use AI automation. This skill should be used when creating automated browser tests, testing authenticated flows, generating test scripts from natural language, or validating user journeys with AI-powered browser control. Handles credentials securely via .env.test with domain-prefixed variables.
What this skill does
# browser-use E2E Testing ## Overview Generate and execute end-to-end tests using browser-use, an AI-powered browser automation library. Tests are written in natural language and the AI agent figures out the specific interactions. ## Quick Start ### 1. Setup ```bash # Install browser-use uv add browser-use python-dotenv uvx browser-use install ``` ### 2. Configure Credentials Create `.env.test` with domain-prefixed credentials: ```bash # Format: SERVICENAME_USER, SERVICENAME_PASS, SERVICENAME_DOMAIN (optional) GITHUB_USER=your-username GITHUB_PASS=your-password [email protected] GMAIL_PASS=your-app-password # Custom app MYAPP_USER=admin MYAPP_PASS=secret MYAPP_DOMAIN=https://app.example.com ``` ### 3. Credential Loader ```python # tests/e2e/conftest.py import os from dotenv import load_dotenv load_dotenv('.env.test') DOMAIN_MAP = { 'GITHUB': 'https://*.github.com', 'GMAIL': 'https://*.google.com', 'GOOGLE': 'https://*.google.com', } def build_sensitive_data() -> dict: """Build browser-use sensitive_data from .env.test vars.""" credentials = {} for key in os.environ: if key.endswith('_USER') or key.endswith('_EMAIL'): prefix = key.rsplit('_', 1)[0] user_val = os.getenv(key) pass_key = f'{prefix}_PASS' pass_val = os.getenv(pass_key) if not pass_val: continue # Determine domain domain_key = f'{prefix}_DOMAIN' domain = os.getenv(domain_key) or DOMAIN_MAP.get(prefix) if not domain: continue # Build credential entry placeholder_user = f'{prefix.lower()}_user' placeholder_pass = f'{prefix.lower()}_pass' credentials[domain] = { placeholder_user: user_val, placeholder_pass: pass_val, } return credentials ``` ## Test Patterns ### Simple Test ```python from browser_use import Agent, Browser, ChatBrowserUse import asyncio async def test_login(): from conftest import build_sensitive_data agent = Agent( task=''' Go to github.com Log in with github_user and github_pass Verify the dashboard loads successfully ''', llm=ChatBrowserUse(), browser=Browser(headless=True), sensitive_data=build_sensitive_data(), use_vision=False, # Security: no screenshots with creds ) result = await agent.run() assert result.is_successful() asyncio.run(test_login()) ``` ### With Pytest ```python # tests/e2e/test_auth.py import pytest from browser_use import Agent, Browser, ChatBrowserUse @pytest.fixture def sensitive_data(): from conftest import build_sensitive_data return build_sensitive_data() @pytest.fixture async def browser(): b = Browser(headless=True) yield b await b.close() @pytest.mark.asyncio async def test_github_login(browser, sensitive_data): agent = Agent( task='Log into github.com with github_user/github_pass, verify repos page', llm=ChatBrowserUse(), browser=browser, sensitive_data=sensitive_data, use_vision=False, ) result = await agent.run() assert result.is_successful() ``` ### Persistent Profile (2FA Sites) ```python from pathlib import Path async def test_with_2fa_profile(): profile_dir = Path.home() / '.browser-use-profiles' / 'github-2fa' browser = Browser( headless=False, user_data_dir=str(profile_dir), ) agent = Agent( task='Go to github.com/settings/security, verify 2FA is enabled', llm=ChatBrowserUse(), browser=browser, # No credentials needed - profile has active session ) result = await agent.run() assert result.is_successful() ``` ### Setup Profile Script ```bash # Run once interactively to save 2FA session python scripts/setup_profile.py --service github --profile-name github-2fa ``` ```python # scripts/setup_profile.py import argparse import asyncio from pathlib import Path from browser_use import Browser async def setup_profile(service: str, profile_name: str): profile_dir = Path.home() / '.browser-use-profiles' / profile_name profile_dir.mkdir(parents=True, exist_ok=True) urls = { 'github': 'https://github.com/login', 'google': 'https://accounts.google.com', 'gitlab': 'https://gitlab.com/users/sign_in', } browser = Browser(headless=False, user_data_dir=str(profile_dir)) ctx = await browser.new_context() page = await ctx.new_page() await page.goto(urls.get(service, service)) input(f'Complete {service} login (including 2FA), then press Enter...') await browser.close() print(f'Profile saved to {profile_dir}') if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--service', required=True) parser.add_argument('--profile-name', required=True) args = parser.parse_args() asyncio.run(setup_profile(args.service, args.profile_name)) ``` ## Running Tests ```bash # Run all E2E tests pytest tests/e2e/ -v # Run specific test pytest tests/e2e/test_auth.py::test_github_login -v # Run with visible browser HEADLESS=false pytest tests/e2e/ -v # Generate HTML report pytest tests/e2e/ --html=report.html ``` ## Domain Restriction ```python # Limit where the agent can navigate (security) browser = Browser( allowed_domains=['github.com', 'app.example.com'] ) ``` ## Tips 1. **Credential placeholders**: Use descriptive names like `github_user` not `x_user` 2. **Disable vision** when handling credentials to prevent screenshot leaks 3. **Use profiles** for 2FA - browser-use can't solve CAPTCHAs 4. **Domain restriction** prevents agent from navigating to unexpected sites 5. **Headless in CI** - set `headless=True` for automated pipelines 6. **Test idempotency** - clean up test data or use unique identifiers ## File Structure ``` project/ ├── .env.test # Credentials (git-ignored) ├── tests/ │ └── e2e/ │ ├── conftest.py # Fixtures, credential loader │ ├── test_auth.py # Authentication tests │ └── test_journeys.py # User journey tests └── scripts/ └── setup_profile.py # Profile setup for 2FA ```
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.