Skip to content

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

refactor: extract assert_input_not_contains helper

Bosch8994f72a2459
diff --git a/tests/e2e/scenarios/25-press-keys.sh b/tests/e2e/scenarios/25-press-keys.sh
index a81c9cfc..3d40ebe7 100755
--- a/tests/e2e/scenarios/25-press-keys.sh
+++ b/tests/e2e/scenarios/25-press-keys.sh
@@ -35,15 +35,7 @@ else
fi
# Check that username field does NOT contain "Enter" as text
-pt_post /evaluate -d '{"expression":"document.getElementById(\"username\").value"}'
-USERNAME_VALUE=$(echo "$RESULT" | jq -r '.result // empty')
-if echo "$USERNAME_VALUE" | grep -qi "enter"; then
- echo -e " ${RED}✗${NC} username contains 'Enter' text: $USERNAME_VALUE (bug #236)"
- ((ASSERTIONS_FAILED++)) || true
-else
- echo -e " ${GREEN}✓${NC} username field clean: $USERNAME_VALUE"
- ((ASSERTIONS_PASSED++)) || true
-fi
+assert_input_not_contains "#username" "Enter" "username should not contain 'Enter' (bug #236)"
end_test
@@ -64,14 +56,6 @@ pt_post /action -d '{"kind":"press","key":"Tab"}'
assert_ok "press Tab"
# Verify username doesn't contain "Tab" text
-pt_post /evaluate -d '{"expression":"document.getElementById(\"username\").value"}'
-USERNAME_VALUE=$(echo "$RESULT" | jq -r '.result // empty')
-if echo "$USERNAME_VALUE" | grep -qi "tab"; then
- echo -e " ${RED}✗${NC} username contains 'Tab' text: $USERNAME_VALUE (bug #236)"
- ((ASSERTIONS_FAILED++)) || true
-else
- echo -e " ${GREEN}✓${NC} username field has no 'Tab' text: $USERNAME_VALUE"
- ((ASSERTIONS_PASSED++)) || true
-fi
+assert_input_not_contains "#username" "Tab" "username should not contain 'Tab' (bug #236)"
end_test
diff --git a/tests/e2e/scenarios/common.sh b/tests/e2e/scenarios/common.sh
index ed371245..a5d02639 100755
--- a/tests/e2e/scenarios/common.sh
+++ b/tests/e2e/scenarios/common.sh
@@ -258,6 +258,28 @@ assert_result_exists() {
assert_json_exists "$RESULT" "$path" "$desc"
}
+# Assert input field value does NOT contain text (case-insensitive)
+# Usage: assert_input_not_contains "#username" "Enter" "username should not contain Enter"
+assert_input_not_contains() {
+ local selector="$1"
+ local forbidden="$2"
+ local desc="${3:-$selector should not contain '$forbidden'}"
+
+ pt_post /evaluate -d "{\"expression\":\"document.querySelector('$selector')?.value || ''\"}"
+ local value
+ value=$(echo "$RESULT" | jq -r '.result // empty')
+
+ if echo "$value" | grep -qi "$forbidden"; then
+ echo -e " ${RED}✗${NC} $desc: found '$forbidden' in value '$value'"
+ ((ASSERTIONS_FAILED++)) || true
+ return 1
+ else
+ echo -e " ${GREEN}✓${NC} $desc (value: '$value')"
+ ((ASSERTIONS_PASSED++)) || true
+ return 0
+ fi
+}
+
# Assert HTTP error status from $RESULT
# Usage: assert_http_error 400 "error message pattern"
assert_http_error() {