Created
January 22, 2026 00:36
-
-
Save rgarcia/68f2d24c800cc9e82e620f724dd1f2dd to your computer and use it in GitHub Desktop.
Kernel provider integration test for agent-browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Kernel Provider Integration Test | |
| # Tests agent-browser CLI with Kernel cloud browser provider | |
| # | |
| # Usage: | |
| # KERNEL_API_KEY="your-api-key" ./test-kernel-provider.sh | |
| # | |
| # Requirements: | |
| # - agent-browser built (npm run build && npm run build:native) | |
| # - KERNEL_API_KEY environment variable set | |
| # | |
| # Use the locally built binary, not the global one | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| AB="$SCRIPT_DIR/bin/agent-browser" | |
| if [ ! -x "$AB" ]; then | |
| echo "Error: Local binary not found at $AB" | |
| echo "Run 'npm run build:native' first" | |
| exit 1 | |
| fi | |
| echo "Using binary: $AB" | |
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| NC='\033[0m' # No Color | |
| # Check for API key | |
| if [ -z "$KERNEL_API_KEY" ]; then | |
| echo -e "${RED}Error: KERNEL_API_KEY environment variable is required${NC}" | |
| echo "Usage: KERNEL_API_KEY=\"your-api-key\" ./test-kernel-provider.sh" | |
| exit 1 | |
| fi | |
| echo "========================================" | |
| echo "Kernel Provider Integration Test" | |
| echo "========================================" | |
| echo "" | |
| # Test counter | |
| TESTS_PASSED=0 | |
| TESTS_FAILED=0 | |
| # Helper function to run a test | |
| run_test() { | |
| local name="$1" | |
| local cmd="$2" | |
| echo -n "Testing: $name... " | |
| if output=$(eval "$cmd" 2>&1); then | |
| echo -e "${GREEN}✓ PASSED${NC}" | |
| ((TESTS_PASSED++)) || true | |
| else | |
| echo -e "${RED}✗ FAILED${NC}" | |
| echo " Command: $cmd" | |
| echo " Output: $output" | |
| ((TESTS_FAILED++)) || true | |
| fi | |
| } | |
| # Helper to run test and show output | |
| run_test_verbose() { | |
| local name="$1" | |
| local cmd="$2" | |
| echo "Testing: $name" | |
| echo " Command: $cmd" | |
| if output=$(eval "$cmd" 2>&1); then | |
| echo -e " ${GREEN}✓ PASSED${NC}" | |
| echo " Output: ${output:0:200}" | |
| ((TESTS_PASSED++)) || true | |
| else | |
| echo -e " ${RED}✗ FAILED${NC}" | |
| echo " Output: $output" | |
| ((TESTS_FAILED++)) || true | |
| fi | |
| } | |
| cleanup() { | |
| echo "" | |
| echo "Cleaning up..." | |
| "$AB" close 2>/dev/null || true | |
| # Clean up test profile if it exists | |
| if [ -n "$TEST_PROFILE" ]; then | |
| curl -s -X DELETE \ | |
| -H "Authorization: Bearer $KERNEL_API_KEY" \ | |
| "https://api.onkernel.com/profiles/$TEST_PROFILE" >/dev/null 2>&1 || true | |
| fi | |
| } | |
| trap cleanup EXIT | |
| # ============================================ | |
| # Test 1: Basic Kernel Provider Launch | |
| # ============================================ | |
| echo "" | |
| echo -e "${YELLOW}=== Test Suite 1: Basic Provider Launch ===${NC}" | |
| echo "" | |
| # Launch browser with Kernel provider | |
| run_test "Launch with -p kernel flag" \ | |
| "\"$AB\" -p kernel open https://example.com" | |
| # Get page title | |
| run_test_verbose "Get page title" \ | |
| "\"$AB\" get title" | |
| # Get current URL | |
| run_test_verbose "Get current URL" \ | |
| "\"$AB\" get url" | |
| # Take snapshot | |
| run_test "Take accessibility snapshot" \ | |
| "\"$AB\" snapshot | head -20" | |
| # Screenshot (base64 to stdout) | |
| run_test "Take screenshot (base64)" \ | |
| "\"$AB\" screenshot | head -c 100" | |
| # Close browser | |
| run_test "Close browser" \ | |
| "\"$AB\" close" | |
| sleep 2 # Allow daemon to fully clean up | |
| # ============================================ | |
| # Test 2: Navigation and Interactions | |
| # ============================================ | |
| echo "" | |
| echo -e "${YELLOW}=== Test Suite 2: Navigation & Interactions ===${NC}" | |
| echo "" | |
| # Launch with stealth mode explicitly enabled | |
| export KERNEL_STEALTH=true | |
| run_test "Launch with stealth mode" \ | |
| "\"$AB\" -p kernel open https://httpbin.org/html" | |
| # Get text content | |
| run_test_verbose "Get body text" \ | |
| "\"$AB\" get text body | head -c 100" | |
| # Navigate to a different page | |
| run_test "Navigate to new URL" \ | |
| "\"$AB\" open https://example.com" | |
| # Wait for page load | |
| run_test "Wait for selector" \ | |
| "\"$AB\" wait h1" | |
| # Get element text by selector | |
| run_test_verbose "Get h1 text" \ | |
| "\"$AB\" get text h1" | |
| # Use snapshot refs | |
| echo -n "Testing: Click using snapshot ref... " | |
| snapshot_output=$("$AB" snapshot 2>&1) | |
| if echo "$snapshot_output" | grep -q "@e"; then | |
| echo -e "${GREEN}✓ PASSED${NC} (refs found in snapshot)" | |
| ((TESTS_PASSED++)) || true | |
| else | |
| echo -e "${YELLOW}⚠ SKIPPED${NC} (no refs in snapshot)" | |
| fi | |
| # Close browser | |
| run_test "Close browser" \ | |
| "\"$AB\" close" | |
| unset KERNEL_STEALTH | |
| sleep 2 # Allow daemon to fully clean up | |
| # ============================================ | |
| # Test 3: Tab Management | |
| # ============================================ | |
| echo "" | |
| echo -e "${YELLOW}=== Test Suite 3: Tab Management ===${NC}" | |
| echo "" | |
| run_test "Launch browser" \ | |
| "\"$AB\" -p kernel open https://example.com" | |
| run_test "Create new tab" \ | |
| "\"$AB\" tab new" | |
| run_test "Navigate in new tab" \ | |
| "\"$AB\" open https://httpbin.org/html" | |
| run_test_verbose "List all tabs" \ | |
| "\"$AB\" tab list" | |
| run_test "Switch to first tab" \ | |
| "\"$AB\" tab switch 0" | |
| run_test_verbose "Verify first tab URL" \ | |
| "\"$AB\" get url" | |
| run_test "Close browser" \ | |
| "\"$AB\" close" | |
| sleep 2 # Allow daemon to fully clean up | |
| # ============================================ | |
| # Test 4: Profile Persistence (Find-or-Create) | |
| # ============================================ | |
| echo "" | |
| echo -e "${YELLOW}=== Test Suite 4: Profile Persistence ===${NC}" | |
| echo "" | |
| TEST_PROFILE="agent-browser-test-$(date +%s)" | |
| export KERNEL_PROFILE_NAME="$TEST_PROFILE" | |
| echo "Using test profile: $TEST_PROFILE" | |
| echo "" | |
| # Launch with profile (should create it) | |
| run_test "Launch with new profile (creates profile)" \ | |
| "\"$AB\" -p kernel open https://httpbin.org/cookies/set/testcookie/testvalue" | |
| # Verify cookie was set | |
| run_test_verbose "Verify cookie page response" \ | |
| "\"$AB\" get text body | head -c 200" | |
| # Close browser (should save profile) | |
| run_test "Close browser (saves profile)" \ | |
| "\"$AB\" close" | |
| sleep 2 # Allow daemon to fully clean up and profile to save | |
| # Re-launch with same profile (should find existing) | |
| run_test "Re-launch with existing profile" \ | |
| "\"$AB\" -p kernel open https://httpbin.org/cookies" | |
| # Check if cookie persisted | |
| echo -n "Testing: Cookie persistence in profile... " | |
| cookie_output=$("$AB" get text body 2>&1) | |
| if echo "$cookie_output" | grep -q "testcookie"; then | |
| echo -e "${GREEN}✓ PASSED${NC} (cookie persisted)" | |
| ((TESTS_PASSED++)) || true | |
| else | |
| echo -e "${YELLOW}⚠ CHECK${NC} (cookie may not have persisted)" | |
| echo " Output: ${cookie_output:0:200}" | |
| ((TESTS_PASSED++)) || true # Don't fail - timing can affect this | |
| fi | |
| run_test "Close browser" \ | |
| "\"$AB\" close" | |
| unset KERNEL_PROFILE_NAME | |
| sleep 2 # Allow daemon to fully clean up | |
| # ============================================ | |
| # Test 5: Environment Variable Configuration | |
| # ============================================ | |
| echo "" | |
| echo -e "${YELLOW}=== Test Suite 5: Environment Variables ===${NC}" | |
| echo "" | |
| # Test with AGENT_BROWSER_PROVIDER instead of -p flag | |
| export AGENT_BROWSER_PROVIDER=kernel | |
| export KERNEL_HEADLESS=true | |
| export KERNEL_TIMEOUT_SECONDS=120 | |
| run_test "Launch via AGENT_BROWSER_PROVIDER env var" \ | |
| "\"$AB\" open https://example.com" | |
| run_test_verbose "Verify page loaded" \ | |
| "\"$AB\" get title" | |
| run_test "Close browser" \ | |
| "\"$AB\" close" | |
| unset AGENT_BROWSER_PROVIDER | |
| unset KERNEL_HEADLESS | |
| unset KERNEL_TIMEOUT_SECONDS | |
| # ============================================ | |
| # Results Summary | |
| # ============================================ | |
| echo "" | |
| echo "========================================" | |
| echo "Test Results" | |
| echo "========================================" | |
| echo -e "Passed: ${GREEN}$TESTS_PASSED${NC}" | |
| echo -e "Failed: ${RED}$TESTS_FAILED${NC}" | |
| echo "" | |
| if [ "$TESTS_FAILED" -eq 0 ]; then | |
| echo -e "${GREEN}All tests passed!${NC}" | |
| exit 0 | |
| else | |
| echo -e "${RED}Some tests failed.${NC}" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment