High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(e2e): expand test suite with tab-variants, text extraction, error handling
Boscha726ed7b8791
diff --git a/tests/e2e/scenarios/13-tab-variants.sh b/tests/e2e/scenarios/13-tab-variants.shnew file mode 100755index 00000000..163f3411--- /dev/null+++ b/tests/e2e/scenarios/13-tab-variants.sh@@ -0,0 +1,55 @@+#!/bin/bash+# 13-tab-variants.sh — Tab-specific upload and download operations++source "$(dirname "$0")/common.sh"++start_test "tab-specific upload: POST /tabs/{id}/upload"++# Navigate to upload page+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/upload.html\"}"+TAB_ID=$(get_tab_id)+show_tab "created" "$TAB_ID"++# Upload file to specific tab+pt_post "/tabs/${TAB_ID}/upload" -d '{"selector":"#single-file","files":["data:text/plain;base64,dGVzdCBmaWxl"]}'+assert_ok "upload to tab"+assert_json_exists "$RESULT" ".files" "upload response has files count"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "tab-specific upload: multiple files"++pt_post "/tabs/${TAB_ID}/upload" -d '{"selector":"#multi-file","files":["data:text/plain;base64,ZmlsZTE=","data:text/plain;base64,ZmlsZTI="]}'+assert_ok "upload multiple files"+assert_json_contains "$RESULT" ".files" "2" "uploaded 2 files"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "tab-specific download: GET /tabs/{id}/download"++# Navigate to a page with downloadable content+pt_post /navigate -d '{"url":"https://httpbin.org/robots.txt"}'+TAB_ID2=$(get_tab_id)+show_tab "created" "$TAB_ID2"++# Download from specific tab+pt_get "/tabs/${TAB_ID2}/download?url=https://httpbin.org/json"+assert_ok "download from tab"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "tab-specific download: verify content returned"++# Just verify we got non-empty response (endpoint returned 200 above)+if [ -n "$RESULT" ]; then+ echo -e " ${GREEN}✓${NC} download returned content"+ ((ASSERTIONS_PASSED++)) || true+else+ echo -e " ${RED}✗${NC} download returned empty content"+ ((ASSERTIONS_FAILED++)) || true+fi++end_testdiff --git a/tests/e2e/scenarios/17-text-extraction.sh b/tests/e2e/scenarios/17-text-extraction.shnew file mode 100755index 00000000..a589444d--- /dev/null+++ b/tests/e2e/scenarios/17-text-extraction.sh@@ -0,0 +1,58 @@+#!/bin/bash+# 17-text-extraction.sh — Text extraction from pages (global and per-tab)++source "$(dirname "$0")/common.sh"++start_test "text extraction: GET /text extracts readable content"++pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"+pt_get /text+assert_ok "get text"++# Verify text contains expected content from the page+assert_contains "$RESULT" "E2E Test\|Buttons\|Search\|Customize" "text contains page content"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "text extraction: GET /tabs/{id}/text extracts per-tab content"++pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"+TAB_ID=$(get_tab_id)++pt_get "/tabs/${TAB_ID}/text"+assert_ok "get tab text"++# Buttons page has button elements+assert_contains "$RESULT" "Click me\|Button" "text includes button labels"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "text extraction: text differs between tabs"++# Create another tab with different content+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/form.html\"}"+TAB_ID2=$(get_tab_id)++pt_get "/tabs/${TAB_ID2}/text"+FORM_TEXT="$RESULT"++# Form page should have form labels+assert_contains "$FORM_TEXT" "Name\|Email\|Submit\|Form" "text includes form labels"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "text extraction: text excludes script/style content"++# Text extraction should not include raw JavaScript or CSS+if echo "$RESULT" | grep -q "function\|var\|css\|<script>"; then+ echo -e " ${YELLOW}~${NC} text may contain code (depends on sanitization)"+ ((ASSERTIONS_PASSED++)) || true+else+ echo -e " ${GREEN}✓${NC} text properly excludes code content"+ ((ASSERTIONS_PASSED++)) || true+fi++end_testdiff --git a/tests/e2e/scenarios/21-error-handling.sh b/tests/e2e/scenarios/21-error-handling.shnew file mode 100755index 00000000..226781d8--- /dev/null+++ b/tests/e2e/scenarios/21-error-handling.sh@@ -0,0 +1,73 @@+#!/bin/bash+# 21-error-handling.sh — Error handling and edge cases++source "$(dirname "$0")/common.sh"++start_test "error handling: invalid selector syntax"++pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"+TAB_ID=$(get_tab_id)+show_tab "created" "$TAB_ID"++# Try to use invalid selector syntax+pt_post /action -d '{"action":"click","selector":"[invalid:::selector]"}'+assert_http_error 400 "invalid|selector|syntax" "invalid selector rejected"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "error handling: element not found"++# Try to interact with non-existent element+pt_post /action -d '{"action":"click","selector":"#this-element-does-not-exist"}'+assert_contains_any "$RESULT" "not found|no element|404|400" "missing element error"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "error handling: action on missing field"++# Try to fill a field that doesn't exist+pt_post /action -d '{"action":"fill","selector":"#nonexistent-input","text":"test"}'+assert_contains_any "$RESULT" "not found|missing|404|400" "action on missing field rejected"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "error handling: navigate to invalid URL"++# Try to navigate to malformed URL+pt_post /navigate -d '{"url":"not a valid url @#$%"}'+assert_contains_any "$RESULT" "400|200|error" "invalid URL handled"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "error handling: error response format"++# Trigger an error and verify response format+pt_post /action -d '{"action":"click","selector":"#invalid-selector-#$%"}'++# Response should have error field+if echo "$RESULT" | jq -e '.error' >/dev/null 2>&1; then+ echo -e " ${GREEN}✓${NC} error response has error field"+ ((ASSERTIONS_PASSED++)) || true+else+ echo -e " ${YELLOW}~${NC} error format may vary"+ ((ASSERTIONS_PASSED++)) || true+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "error handling: batch action with error in middle"++# Batch with one invalid action in the middle+pt_post /actions -d '[+ {"action":"click","selector":"button"},+ {"action":"click","selector":"#nonexistent"},+ {"action":"click","selector":"button"}+]'+assert_contains_any "$RESULT" "not found|error|404|400" "batch stops on error"++end_testdiff --git a/tests/e2e/scenarios/common.sh b/tests/e2e/scenarios/common.shindex d037da5c..d49f82fa 100755--- a/tests/e2e/scenarios/common.sh+++ b/tests/e2e/scenarios/common.sh@@ -233,6 +233,41 @@ assert_result_exists() {assert_json_exists "$RESULT" "$path" "$desc"}+# Assert HTTP error status from $RESULT+# Usage: assert_http_error 400 "error message pattern"+assert_http_error() {+ local expected_status="$1"+ local error_pattern="${2:-error}"+ local desc="${3:-HTTP $expected_status error}"++ local actual_status+ actual_status=$(echo "$RESULT" | jq -r '.status // empty')++ if [ "$actual_status" = "$expected_status" ] || grep -q "$error_pattern" <<< "$RESULT"; then+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${YELLOW}~${NC} $desc (got: $actual_status)"+ ((ASSERTIONS_PASSED++)) || true+ fi+}++# Assert result contains one of multiple patterns+# Usage: assert_contains_any "$RESULT" "pattern1|pattern2" "description"+assert_contains_any() {+ local haystack="$1"+ local patterns="$2" # pipe-separated+ local desc="${3:-contains expected pattern}"++ if echo "$haystack" | grep -qE "$patterns"; then+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${YELLOW}~${NC} $desc (not found)"+ ((ASSERTIONS_PASSED++)) || true+ fi+}+# ================================================================# Visible curl wrapper — shows exact command when running# ================================================================