Skip to content

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

refactor: element interaction helpers

Bosch1500dc68325f
diff --git a/tests/e2e/scenarios/05-actions.sh b/tests/e2e/scenarios/05-actions.sh
index d7e97b1c..4792d9d3 100755
--- a/tests/e2e/scenarios/05-actions.sh
+++ b/tests/e2e/scenarios/05-actions.sh
@@ -4,50 +4,30 @@
source "$(dirname "$0")/common.sh"
# ─────────────────────────────────────────────────────────────────
-start_test "pinchtab click <ref>"
+start_test "pinchtab click <button>"
pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
-sleep 2
+sleep 1
-# Get snapshot and find increment button
pt_get /snapshot
-INCREMENT_REF=$(echo "$RESULT" | jq -r '.nodes[] | select(.name == "Increment") | .ref' | head -1)
-
-if [ -n "$INCREMENT_REF" ] && [ "$INCREMENT_REF" != "null" ]; then
- pt_post /action -d "{\"kind\":\"click\",\"ref\":\"${INCREMENT_REF}\"}"
- echo -e " ${GREEN}✓${NC} Clicked button (ref: $INCREMENT_REF)"
- ((ASSERTIONS_PASSED++)) || true
-else
- echo -e " ${YELLOW}⚠${NC} Could not find increment button"
- ((ASSERTIONS_PASSED++)) || true
-fi
+click_button "Increment"
end_test
# ─────────────────────────────────────────────────────────────────
-start_test "pinchtab type <ref> <text>"
+start_test "pinchtab type <field> <text>"
pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/form.html\"}"
sleep 1
pt_get /snapshot
-USERNAME_REF=$(echo "$RESULT" | jq -r '.nodes[] | select(.role == "textbox") | .ref' | head -1)
-
-if [ -n "$USERNAME_REF" ] && [ "$USERNAME_REF" != "null" ]; then
- pt_post /action -d "{\"kind\":\"type\",\"ref\":\"${USERNAME_REF}\",\"text\":\"testuser123\"}"
- echo -e " ${GREEN}✓${NC} Typed into field (ref: $USERNAME_REF)"
- ((ASSERTIONS_PASSED++)) || true
-else
- echo -e " ${YELLOW}⚠${NC} Could not find input field"
- ((ASSERTIONS_PASSED++)) || true
-fi
+type_into "Username" "testuser123"
end_test
# ─────────────────────────────────────────────────────────────────
start_test "pinchtab press <key>"
-pt_post /action -d '{"kind":"press","key":"Escape"}'
-assert_status 200 "${PINCHTAB_URL}/action" "POST" '{"kind":"press","key":"Escape"}'
+press_key "Escape"
end_test
diff --git a/tests/e2e/scenarios/common.sh b/tests/e2e/scenarios/common.sh
index b9622ff9..9ade0108 100755
--- a/tests/e2e/scenarios/common.sh
+++ b/tests/e2e/scenarios/common.sh
@@ -219,6 +219,64 @@ pt() { pinchtab "$@"; }
pt_get() { pinchtab GET "$1"; echo "$RESULT"; }
pt_post() { pinchtab POST "$1" -d "$2"; echo "$RESULT"; }
+# ================================================================
+# Element interaction helpers
+# ================================================================
+
+# Get ref for element by name from last snapshot
+get_ref() {
+ local name="$1"
+ echo "$RESULT" | jq -r ".nodes[] | select(.name == \"$name\") | .ref" | head -1
+}
+
+# Get ref for element by role from last snapshot
+get_ref_by_role() {
+ local role="$1"
+ echo "$RESULT" | jq -r ".nodes[] | select(.role == \"$role\") | .ref" | head -1
+}
+
+# Click a button by name (requires snapshot in $RESULT)
+click_button() {
+ local name="$1"
+ local ref=$(get_ref "$name")
+
+ if [ -n "$ref" ] && [ "$ref" != "null" ]; then
+ pt_post /action -d "{\"kind\":\"click\",\"ref\":\"${ref}\"}" > /dev/null
+ echo -e " ${GREEN}✓${NC} clicked '$name' (ref: $ref)"
+ ((ASSERTIONS_PASSED++)) || true
+ else
+ echo -e " ${RED}✗${NC} button '$name' not found"
+ ((ASSERTIONS_FAILED++)) || true
+ fi
+}
+
+# Type into a field by name or role
+type_into() {
+ local name="$1"
+ local text="$2"
+ local ref=$(get_ref "$name")
+
+ # Fallback to role if name not found
+ [ -z "$ref" ] || [ "$ref" = "null" ] && ref=$(get_ref_by_role "textbox")
+
+ if [ -n "$ref" ] && [ "$ref" != "null" ]; then
+ pt_post /action -d "{\"kind\":\"type\",\"ref\":\"${ref}\",\"text\":\"${text}\"}" > /dev/null
+ echo -e " ${GREEN}✓${NC} typed '$text' into '$name' (ref: $ref)"
+ ((ASSERTIONS_PASSED++)) || true
+ else
+ echo -e " ${RED}✗${NC} input '$name' not found"
+ ((ASSERTIONS_FAILED++)) || true
+ fi
+}
+
+# Press a key
+press_key() {
+ local key="$1"
+ pt_post /action -d "{\"kind\":\"press\",\"key\":\"${key}\"}" > /dev/null
+ echo -e " ${GREEN}✓${NC} pressed '$key'"
+ ((ASSERTIONS_PASSED++)) || true
+}
+
# ================================================================
# Tab helpers
# ================================================================