High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
refactor(e2e): extract repeating assertions into helpers
Bosch04e3a489897a
diff --git a/tests/e2e/scenarios/07-find.sh b/tests/e2e/scenarios/07-find.shindex b2f99e03..3d41187a 100755--- a/tests/e2e/scenarios/07-find.sh+++ b/tests/e2e/scenarios/07-find.sh@@ -12,11 +12,7 @@ start_test "pinchtab find (login button)"pt_post /find -d '{"query":"login button"}'assert_ok "find login"--# Verify we got a ref back-if ! echo "$RESULT" | jq -e '.best_ref' >/dev/null 2>&1; then- fail "expected best_ref in response"-fi+assert_result_exists ".best_ref" "has best_ref"end_test@@ -41,11 +37,7 @@ start_test "pinchtab find (search)"pt_post /find -d '{"query":"search input","topK":5}'assert_ok "find search"--# Verify candidates array-if ! echo "$RESULT" | jq -e '.candidates | length > 0' >/dev/null 2>&1; then- fail "expected candidates in response"-fi+assert_json_length_gte "$RESULT" ".candidates" 1 "has candidates"end_testdiff --git a/tests/e2e/scenarios/08-evaluate.sh b/tests/e2e/scenarios/08-evaluate.shindex a323c74b..f9a2968e 100755--- a/tests/e2e/scenarios/08-evaluate.sh+++ b/tests/e2e/scenarios/08-evaluate.sh@@ -12,12 +12,7 @@ start_test "pinchtab evaluate (simple expression)"pt_post /evaluate -d '{"expression":"1 + 1"}'assert_ok "evaluate simple"--# Verify result-VAL=$(echo "$RESULT" | jq -r '.result')-if [ "$VAL" != "2" ]; then- fail "expected result=2, got $VAL"-fi+assert_result_eq ".result" "2" "1+1=2"end_test@@ -26,11 +21,7 @@ start_test "pinchtab evaluate (DOM query)"pt_post /evaluate -d '{"expression":"document.title"}'assert_ok "evaluate DOM"--VAL=$(echo "$RESULT" | jq -r '.result')-if [ "$VAL" != "Evaluate Test Page" ]; then- fail "expected value, got $VAL"-fi+assert_result_eq ".result" "Evaluate Test Page" "got title"end_test@@ -39,11 +30,7 @@ start_test "pinchtab evaluate (call function)"pt_post /evaluate -d '{"expression":"window.calculate.add(5, 3)"}'assert_ok "evaluate function"--VAL=$(echo "$RESULT" | jq -r '.result')-if [ "$VAL" != "8" ]; then- fail "expected value, got $VAL"-fi+assert_result_eq ".result" "8" "5+3=8"end_test@@ -52,11 +39,7 @@ start_test "pinchtab evaluate (get object)"pt_post /evaluate -d '{"expression":"JSON.stringify(window.testData)"}'assert_ok "evaluate object"--# Verify we got the test data-if ! echo "$RESULT" | jq -r '.result' | jq -e '.name == "PinchTab"' >/dev/null 2>&1; then- fail "expected testData object"-fi+assert_json_contains "$RESULT" ".result" "PinchTab" "has testData"end_test@@ -68,10 +51,7 @@ assert_ok "evaluate modify DOM"# Verify the change stuckpt_post /evaluate -d '{"expression":"document.getElementById(\"counter\").textContent"}'-VAL=$(echo "$RESULT" | jq -r '.result')-if [ "$VAL" != "42" ]; then- fail "expected value, got $VAL"-fi+assert_result_eq ".result" "42" "counter=42"end_test@@ -86,10 +66,6 @@ sleep 1pt_post "/tabs/${TAB_ID}/evaluate" -d '{"expression":"1 + 2 + 3"}'assert_ok "tab evaluate"--VAL=$(echo "$RESULT" | jq -r '.result')-if [ "$VAL" != "6" ]; then- fail "expected value, got $VAL"-fi+assert_result_eq ".result" "6" "1+2+3=6"end_testdiff --git a/tests/e2e/scenarios/09-download.sh b/tests/e2e/scenarios/09-download.shindex 14277c97..ae93b853 100755--- a/tests/e2e/scenarios/09-download.sh+++ b/tests/e2e/scenarios/09-download.sh@@ -23,9 +23,7 @@ pt_get "/download?url=${FIXTURES_URL}/sample.txt"assert_http_status 400 "download blocked"# Verify error message mentions blocking-if ! echo "$RESULT" | grep -q "blocked\|private"; then- fail "expected SSRF block message"-fi+assert_contains "$RESULT" "blocked\|private" "SSRF error message"end_testdiff --git a/tests/e2e/scenarios/common.sh b/tests/e2e/scenarios/common.shindex d660969b..332c98f5 100755--- a/tests/e2e/scenarios/common.sh+++ b/tests/e2e/scenarios/common.sh@@ -187,6 +187,51 @@ assert_json_length_gte() {fi}+# Assert JSON field exists (not null)+assert_json_exists() {+ local json="$1"+ local path="$2"+ local desc="${3:-$path exists}"++ if echo "$json" | jq -e "$path" >/dev/null 2>&1; then+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} $desc (field missing or null)"+ ((ASSERTIONS_FAILED++)) || true+ fi+}++# Assert string contains substring+assert_contains() {+ local haystack="$1"+ local needle="$2"+ local desc="${3:-contains '$needle'}"++ if echo "$haystack" | grep -q "$needle"; then+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} $desc (not found)"+ ((ASSERTIONS_FAILED++)) || true+ fi+}++# Assert result JSON field equals value (uses global $RESULT)+assert_result_eq() {+ local path="$1"+ local expected="$2"+ local desc="${3:-$path = $expected}"+ assert_json_eq "$RESULT" "$path" "$expected" "$desc"+}++# Assert result JSON field exists (uses global $RESULT)+assert_result_exists() {+ local path="$1"+ local desc="${2:-$path exists}"+ assert_json_exists "$RESULT" "$path" "$desc"+}+# ================================================================# Visible curl wrapper — shows exact command when running# ================================================================