Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

refactor: more helpers for cleaner tests

Bosch59e54ca6a487
diff --git a/tests/e2e/scenarios/01-health.sh b/tests/e2e/scenarios/01-health.sh
index dd3b5125..19d051dd 100755
--- a/tests/e2e/scenarios/01-health.sh
+++ b/tests/e2e/scenarios/01-health.sh
@@ -14,9 +14,6 @@ end_test
# ─────────────────────────────────────────────────────────────────
start_test "fixtures server"
-# Verify test fixtures are accessible
-curl -sf "${FIXTURES_URL}/" > /dev/null && echo -e " ${GREEN}✓${NC} GET ${FIXTURES_URL}/" && ((ASSERTIONS_PASSED++)) || ((ASSERTIONS_FAILED++))
-curl -sf "${FIXTURES_URL}/form.html" > /dev/null && echo -e " ${GREEN}✓${NC} GET ${FIXTURES_URL}/form.html" && ((ASSERTIONS_PASSED++)) || ((ASSERTIONS_FAILED++))
-curl -sf "${FIXTURES_URL}/table.html" > /dev/null && echo -e " ${GREEN}✓${NC} GET ${FIXTURES_URL}/table.html" && ((ASSERTIONS_PASSED++)) || ((ASSERTIONS_FAILED++))
+assert_fixtures_accessible
end_test
diff --git a/tests/e2e/scenarios/04-tabs-api.sh b/tests/e2e/scenarios/04-tabs-api.sh
index df259dd5..a8eb860b 100755
--- a/tests/e2e/scenarios/04-tabs-api.sh
+++ b/tests/e2e/scenarios/04-tabs-api.sh
@@ -8,17 +8,16 @@ start_test "pinchtab snap --tab <id> (regression #207)"
# Create a tab
pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"
-CREATED_TAB=$(echo "$RESULT" | jq -r '.tabId')
-echo -e " Created tab: ${CREATED_TAB:0:12}..."
+show_tab "created" "$(get_tab_id)"
# Get tab ID from /tabs endpoint
pt_get /tabs
-LISTED_TAB=$(echo "$RESULT" | jq -r '.tabs[-1].id')
-echo -e " Listed tab: ${LISTED_TAB:0:12}..."
+TAB_ID=$(get_last_tab)
+show_tab "listed" "$TAB_ID"
# Test: /tabs/{id}/snapshot should work (was broken in #207)
-pt_get "/tabs/${LISTED_TAB}/snapshot"
-assert_status 200 "${PINCHTAB_URL}/tabs/${LISTED_TAB}/snapshot"
+pt_get "/tabs/${TAB_ID}/snapshot"
+assert_ok "tab snapshot"
assert_json_contains "$RESULT" '.title' 'E2E Test'
end_test
@@ -27,13 +26,13 @@ end_test
start_test "pinchtab text/screenshot --tab <id>"
pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/form.html\"}"
-TAB_ID=$(echo "$RESULT" | jq -r '.tabId')
+TAB_ID=$(get_tab_id)
-# Test /tabs/{id}/text
-assert_status 200 "${PINCHTAB_URL}/tabs/${TAB_ID}/text"
+pt_get "/tabs/${TAB_ID}/text"
+assert_ok "tab text"
-# Test /tabs/{id}/screenshot
-assert_status 200 "${PINCHTAB_URL}/tabs/${TAB_ID}/screenshot"
+pt_get "/tabs/${TAB_ID}/screenshot"
+assert_ok "tab screenshot"
end_test
@@ -42,11 +41,11 @@ start_test "pinchtab tab close"
BEFORE=$(get_tab_count)
-# Create and close a tab
pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
-TAB_ID=$(echo "$RESULT" | jq -r '.tabId')
+TAB_ID=$(get_tab_id)
-assert_status 200 "${PINCHTAB_URL}/tabs/${TAB_ID}/close" "POST"
+pt_post "/tabs/${TAB_ID}/close" -d '{}'
+assert_ok "tab close"
sleep 1
assert_tab_closed "$BEFORE"
diff --git a/tests/e2e/scenarios/06-screenshot-pdf.sh b/tests/e2e/scenarios/06-screenshot-pdf.sh
index 7cae3744..92b8a32f 100755
--- a/tests/e2e/scenarios/06-screenshot-pdf.sh
+++ b/tests/e2e/scenarios/06-screenshot-pdf.sh
@@ -17,9 +17,7 @@ end_test
# ─────────────────────────────────────────────────────────────────
start_test "pinchtab pdf (shorthand)"
-# Note: /pdf shorthand not available in server mode — skipped
-echo -e " ${YELLOW}⚠${NC} Skipped: /pdf shorthand not in server mode"
-((ASSERTIONS_PASSED++)) || true
+skip "/pdf shorthand not in server mode"
end_test
@@ -27,7 +25,7 @@ end_test
start_test "pinchtab screenshot --tab <id>"
pt_get /tabs
-TAB_ID=$(echo "$RESULT" | jq -r '.tabs[0].id')
+TAB_ID=$(get_first_tab)
pt_get "/tabs/${TAB_ID}/screenshot"
assert_ok "tab screenshot"
@@ -38,7 +36,7 @@ end_test
start_test "pinchtab pdf --tab <id>"
pt_get /tabs
-TAB_ID=$(echo "$RESULT" | jq -r '.tabs[0].id')
+TAB_ID=$(get_first_tab)
pt_get "/tabs/${TAB_ID}/pdf"
assert_ok "tab pdf"
diff --git a/tests/e2e/scenarios/common.sh b/tests/e2e/scenarios/common.sh
index 210e1ed4..3413afad 100755
--- a/tests/e2e/scenarios/common.sh
+++ b/tests/e2e/scenarios/common.sh
@@ -219,6 +219,42 @@ pt() { pinchtab "$@"; }
pt_get() { pinchtab GET "$1"; echo "$RESULT"; }
pt_post() { pinchtab POST "$1" -d "$2"; echo "$RESULT"; }
+# ================================================================
+# URL accessibility checks
+# ================================================================
+
+# Check if a URL is accessible
+assert_url_accessible() {
+ local url="$1"
+ local label="${2:-$url}"
+
+ if curl -sf "$url" > /dev/null 2>&1; then
+ echo -e " ${GREEN}✓${NC} GET $label"
+ ((ASSERTIONS_PASSED++)) || true
+ else
+ echo -e " ${RED}✗${NC} GET $label (not accessible)"
+ ((ASSERTIONS_FAILED++)) || true
+ fi
+}
+
+# Check all fixture pages
+assert_fixtures_accessible() {
+ assert_url_accessible "${FIXTURES_URL}/" "fixtures/"
+ assert_url_accessible "${FIXTURES_URL}/form.html" "fixtures/form.html"
+ assert_url_accessible "${FIXTURES_URL}/table.html" "fixtures/table.html"
+ assert_url_accessible "${FIXTURES_URL}/buttons.html" "fixtures/buttons.html"
+}
+
+# ================================================================
+# Skip helper
+# ================================================================
+
+skip() {
+ local reason="$1"
+ echo -e " ${YELLOW}⚠${NC} Skipped: $reason"
+ ((ASSERTIONS_PASSED++)) || true
+}
+
# ================================================================
# HTTP status assertions
# ================================================================
@@ -317,6 +353,28 @@ get_tab_count() {
curl -s "${PINCHTAB_URL}/tabs" | jq '.tabs | length'
}
+# Get tab ID from last response (e.g., after /navigate)
+get_tab_id() {
+ echo "$RESULT" | jq -r '.tabId'
+}
+
+# Get first tab ID from /tabs response
+get_first_tab() {
+ echo "$RESULT" | jq -r '.tabs[0].id'
+}
+
+# Get last tab ID from /tabs response
+get_last_tab() {
+ echo "$RESULT" | jq -r '.tabs[-1].id'
+}
+
+# Print tab ID (truncated for readability)
+show_tab() {
+ local label="$1"
+ local id="$2"
+ echo -e " ${MUTED}$label: ${id:0:12}...${NC}"
+}
+
# Assert tab count equals expected
assert_tab_count() {
local expected="$1"