High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
refactor(e2e): extract assert_json_contains/assert_eval_poll, simplify redirects + stealth tests
Bosch5cd7b2b3339f
diff --git a/tests/e2e/scenarios/22-redirects.sh b/tests/e2e/scenarios/22-redirects.shindex ebc99133..857a2d14 100755--- a/tests/e2e/scenarios/22-redirects.sh+++ b/tests/e2e/scenarios/22-redirects.sh@@ -11,14 +11,7 @@ assert_ok "single redirect followed"# Verify we ended up at final destinationpt_get /snapshot-FINAL_URL=$(echo "$RESULT" | jq -r '.url // empty')-if echo "$FINAL_URL" | grep -q "httpbin.org/get"; then- echo -e " ${GREEN}✓${NC} final URL is /get (redirect successful)"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${YELLOW}~${NC} redirect may have been followed (URL: $FINAL_URL)"- ((ASSERTIONS_PASSED++)) || true-fi+assert_json_contains "$RESULT" ".url" "httpbin.org/get" "final URL is /get (redirect successful)"end_test@@ -31,14 +24,7 @@ assert_ok "five redirects followed"# Verify final destinationpt_get /snapshot-FINAL_URL=$(echo "$RESULT" | jq -r '.url // empty')-if echo "$FINAL_URL" | grep -q "httpbin.org/get"; then- echo -e " ${GREEN}✓${NC} multiple redirects followed to destination"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${YELLOW}~${NC} final URL: $FINAL_URL"- ((ASSERTIONS_PASSED++)) || true-fi+assert_json_contains "$RESULT" ".url" "httpbin.org/get" "multiple redirects followed to destination"end_testdiff --git a/tests/e2e/scenarios/30-stealth.sh b/tests/e2e/scenarios/30-stealth.shindex 1ca3bd0d..2916873e 100755--- a/tests/e2e/scenarios/30-stealth.sh+++ b/tests/e2e/scenarios/30-stealth.sh@@ -12,67 +12,21 @@ sleep 1# ─────────────────────────────────────────────────────────────────start_test "stealth: webdriver is undefined"-# Poll for stealth injection (up to 2s)-STEALTH_OK=false-for i in $(seq 1 5); do- pt_post /evaluate '{"expression":"navigator.webdriver === undefined"}'- if echo "$RESULT" | jq -r '.result' 2>/dev/null | grep -q "true"; then- STEALTH_OK=true- break- fi- sleep 0.4-done-if [ "$STEALTH_OK" = "true" ]; then- echo -e " ${GREEN}✓${NC} navigator.webdriver is undefined"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${RED}✗${NC} navigator.webdriver still defined"- ((ASSERTIONS_FAILED++)) || true-fi+assert_eval_poll "navigator.webdriver === undefined" "true" "navigator.webdriver is undefined"end_test# ─────────────────────────────────────────────────────────────────start_test "stealth: plugins present"-STEALTH_OK=false-for i in $(seq 1 5); do- pt_post /evaluate '{"expression":"navigator.plugins.length > 0"}'- if echo "$RESULT" | jq -r '.result' 2>/dev/null | grep -q "true"; then- STEALTH_OK=true- break- fi- sleep 0.4-done-if [ "$STEALTH_OK" = "true" ]; then- echo -e " ${GREEN}✓${NC} navigator.plugins spoofed"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${RED}✗${NC} navigator.plugins empty"- ((ASSERTIONS_FAILED++)) || true-fi+assert_eval_poll "navigator.plugins.length > 0" "true" "navigator.plugins spoofed"end_test# ─────────────────────────────────────────────────────────────────start_test "stealth: chrome.runtime present"-STEALTH_OK=false-for i in $(seq 1 5); do- pt_post /evaluate '{"expression":"!!window.chrome && !!window.chrome.runtime"}'- if echo "$RESULT" | jq -r '.result' 2>/dev/null | grep -q "true"; then- STEALTH_OK=true- break- fi- sleep 0.4-done-if [ "$STEALTH_OK" = "true" ]; then- echo -e " ${GREEN}✓${NC} window.chrome.runtime present"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${RED}✗${NC} window.chrome.runtime missing"- ((ASSERTIONS_FAILED++)) || true-fi+assert_eval_poll "!!window.chrome && !!window.chrome.runtime" "true" "window.chrome.runtime present"end_test@@ -92,7 +46,6 @@ assert_ok "fingerprint rotate (random)"end_test-# ─────────────────────────────────────────────────────────────────# ─────────────────────────────────────────────────────────────────start_test "stealth: fingerprint rotate (specific tab)"diff --git a/tests/e2e/scenarios/common.sh b/tests/e2e/scenarios/common.shindex 65d90888..91008ca8 100755--- a/tests/e2e/scenarios/common.sh+++ b/tests/e2e/scenarios/common.sh@@ -567,6 +567,40 @@ assert_tab_closed() {fi}+# ================================================================+# Evaluate with polling (for stealth/async injection)+# ================================================================++# Poll an expression up to N times, assert result equals expected+# Usage: assert_eval_poll "navigator.webdriver === undefined" "true" "webdriver is undefined" [attempts] [delay]+assert_eval_poll() {+ local expr="$1"+ local expected="$2"+ local desc="${3:-eval poll}"+ local attempts="${4:-5}"+ local delay="${5:-0.4}"++ local ok=false+ for i in $(seq 1 "$attempts"); do+ pt_post /evaluate "{\"expression\":\"$expr\"}"+ local actual+ actual=$(echo "$RESULT" | jq -r '.result // empty' 2>/dev/null)+ if [ "$actual" = "$expected" ]; then+ ok=true+ break+ fi+ sleep "$delay"+ done++ if [ "$ok" = "true" ]; then+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} $desc (got: $actual, expected: $expected)"+ ((ASSERTIONS_FAILED++)) || true+ fi+}+# ================================================================# Page-specific assertions (we control the fixtures!)# ================================================================