High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(e2e): add find, evaluate, download, upload tests
Boschdbc501154272
diff --git a/tests/e2e/Dockerfile.pinchtab b/tests/e2e/Dockerfile.pinchtabindex 23b49abc..5bbe3065 100644--- a/tests/e2e/Dockerfile.pinchtab+++ b/tests/e2e/Dockerfile.pinchtab@@ -39,11 +39,12 @@ ENV PINCHTAB_BIND=0.0.0.0 \PINCHTAB_STATE_DIR=/data \CHROME_BIN=/usr/bin/chromium-browser-# Create config with Chrome flags for Docker and IDPI allowlist for test fixtures+# Create config with Chrome flags for Docker, IDPI allowlist, and security features enabled# Config goes in XDG_CONFIG_HOME which defaults to ~/.config# AllowedDomains replaces defaults, so include localhost + fixtures+# Enable evaluate/download/upload for comprehensive E2E testingRUN mkdir -p /root/.config/pinchtab && \- echo '{"browser":{"extraFlags":"--no-sandbox --disable-dev-shm-usage"},"security":{"idpi":{"enabled":true,"allowedDomains":["localhost","127.0.0.1","::1","fixtures"]}}}' > /root/.config/pinchtab/config.json+ echo '{"browser":{"extraFlags":"--no-sandbox --disable-dev-shm-usage"},"security":{"allowEvaluate":true,"allowDownload":true,"allowUpload":true,"idpi":{"enabled":true,"allowedDomains":["localhost","127.0.0.1","::1","fixtures"]}}}' > /root/.config/pinchtab/config.jsonEXPOSE 9999diff --git a/tests/e2e/fixtures/evaluate.html b/tests/e2e/fixtures/evaluate.htmlnew file mode 100644index 00000000..0fa3a2d2--- /dev/null+++ b/tests/e2e/fixtures/evaluate.html@@ -0,0 +1,81 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <title>Evaluate Test Page</title>+ <style>+ body { font-family: system-ui, sans-serif; padding: 2rem; }+ .result { padding: 1rem; margin: 1rem 0; background: #f5f5f5; border-radius: 4px; }+ #counter { font-size: 2rem; font-weight: bold; }+ </style>+</head>+<body>+ <h1>JavaScript Evaluate Test Page</h1>++ <div class="result">+ <p>Counter: <span id="counter">0</span></p>+ <button onclick="increment()">Increment</button>+ <button onclick="decrement()">Decrement</button>+ <button onclick="reset()">Reset</button>+ </div>++ <div class="result">+ <p>Message: <span id="message">Hello, World!</span></p>+ </div>++ <div class="result">+ <p>Data: <span id="data"></span></p>+ </div>++ <script>+ // Global state for testing+ window.testData = {+ name: 'PinchTab',+ version: '1.0.0',+ features: ['snapshot', 'screenshot', 'pdf', 'evaluate']+ };++ let count = 0;++ function increment() {+ count++;+ document.getElementById('counter').textContent = count;+ return count;+ }++ function decrement() {+ count--;+ document.getElementById('counter').textContent = count;+ return count;+ }++ function reset() {+ count = 0;+ document.getElementById('counter').textContent = count;+ return count;+ }++ function setMessage(msg) {+ document.getElementById('message').textContent = msg;+ return msg;+ }++ function getData() {+ return window.testData;+ }++ function asyncOperation() {+ return new Promise(resolve => {+ setTimeout(() => resolve({ status: 'complete', timestamp: Date.now() }), 100);+ });+ }++ // Math utilities for testing+ window.calculate = {+ add: (a, b) => a + b,+ multiply: (a, b) => a * b,+ factorial: (n) => n <= 1 ? 1 : n * window.calculate.factorial(n - 1)+ };+ </script>+</body>+</html>diff --git a/tests/e2e/fixtures/find.html b/tests/e2e/fixtures/find.htmlnew file mode 100644index 00000000..2e8fdc4c--- /dev/null+++ b/tests/e2e/fixtures/find.html@@ -0,0 +1,67 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <title>Find Test Page</title>+ <style>+ body { font-family: system-ui, sans-serif; padding: 2rem; }+ .section { margin: 2rem 0; padding: 1rem; border: 1px solid #ddd; border-radius: 8px; }+ button { padding: 0.5rem 1rem; margin: 0.25rem; cursor: pointer; }+ input, select { padding: 0.5rem; margin: 0.25rem; }+ .primary { background: #007bff; color: white; border: none; border-radius: 4px; }+ .danger { background: #dc3545; color: white; border: none; border-radius: 4px; }+ .success { background: #28a745; color: white; border: none; border-radius: 4px; }+ </style>+</head>+<body>+ <h1>Element Finder Test Page</h1>++ <div class="section">+ <h2>Authentication</h2>+ <input type="email" placeholder="Email address" aria-label="Email">+ <input type="password" placeholder="Password" aria-label="Password">+ <button class="primary" id="login-btn">Log In</button>+ <button id="signup-btn">Sign Up</button>+ <a href="#forgot">Forgot password?</a>+ </div>++ <div class="section">+ <h2>Actions</h2>+ <button class="success" id="save-btn">Save Changes</button>+ <button class="danger" id="delete-btn">Delete Account</button>+ <button id="cancel-btn">Cancel</button>+ <button id="submit-form">Submit Form</button>+ </div>++ <div class="section">+ <h2>Navigation</h2>+ <a href="#home">Home</a>+ <a href="#about">About Us</a>+ <a href="#contact">Contact Support</a>+ <a href="#pricing">View Pricing</a>+ </div>++ <div class="section">+ <h2>Form Elements</h2>+ <label>+ <input type="checkbox" id="terms"> I agree to the terms and conditions+ </label>+ <br>+ <label>+ <input type="checkbox" id="newsletter"> Subscribe to newsletter+ </label>+ <br>+ <select aria-label="Country">+ <option>United States</option>+ <option>United Kingdom</option>+ <option>Canada</option>+ </select>+ </div>++ <div class="section">+ <h2>Search</h2>+ <input type="search" placeholder="Search products..." aria-label="Search">+ <button id="search-btn">Search</button>+ </div>+</body>+</html>diff --git a/tests/e2e/fixtures/sample.txt b/tests/e2e/fixtures/sample.txtnew file mode 100644index 00000000..3c89fa89--- /dev/null+++ b/tests/e2e/fixtures/sample.txt@@ -0,0 +1,4 @@+This is a sample file for download testing.+PinchTab E2E Test Suite+========================+If you can read this, the download worked!diff --git a/tests/e2e/fixtures/upload.html b/tests/e2e/fixtures/upload.htmlnew file mode 100644index 00000000..14eba93b--- /dev/null+++ b/tests/e2e/fixtures/upload.html@@ -0,0 +1,92 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <title>Upload Test Page</title>+ <style>+ body { font-family: system-ui, sans-serif; padding: 2rem; }+ .upload-zone {+ border: 2px dashed #ccc;+ border-radius: 8px;+ padding: 2rem;+ text-align: center;+ margin: 1rem 0;+ }+ .upload-zone.dragover { border-color: #007bff; background: #f0f7ff; }+ .file-list { margin: 1rem 0; }+ .file-item { padding: 0.5rem; background: #f5f5f5; margin: 0.25rem 0; border-radius: 4px; }+ input[type="file"] { margin: 1rem 0; }+ </style>+</head>+<body>+ <h1>File Upload Test Page</h1>++ <div class="upload-zone" id="drop-zone">+ <p>Drag and drop files here or click to select</p>+ <input type="file" id="single-file" aria-label="Single file upload">+ </div>++ <div>+ <h2>Multiple Files</h2>+ <input type="file" id="multi-file" multiple aria-label="Multiple file upload">+ </div>++ <div>+ <h2>Specific Types</h2>+ <label>+ Images only:+ <input type="file" id="image-upload" accept="image/*" aria-label="Image upload">+ </label>+ <br><br>+ <label>+ Documents:+ <input type="file" id="doc-upload" accept=".pdf,.doc,.docx,.txt" aria-label="Document upload">+ </label>+ </div>++ <div class="file-list" id="file-list">+ <h2>Uploaded Files</h2>+ <p id="no-files">No files uploaded yet</p>+ </div>++ <script>+ const fileInputs = document.querySelectorAll('input[type="file"]');+ const fileList = document.getElementById('file-list');+ const noFiles = document.getElementById('no-files');++ fileInputs.forEach(input => {+ input.addEventListener('change', (e) => {+ const files = e.target.files;+ if (files.length > 0) {+ noFiles.style.display = 'none';+ Array.from(files).forEach(file => {+ const item = document.createElement('div');+ item.className = 'file-item';+ item.textContent = `${file.name} (${(file.size / 1024).toFixed(1)} KB)`;+ item.dataset.filename = file.name;+ item.dataset.size = file.size;+ item.dataset.type = file.type;+ fileList.appendChild(item);+ });+ }+ });+ });++ // Drag and drop+ const dropZone = document.getElementById('drop-zone');+ dropZone.addEventListener('dragover', (e) => {+ e.preventDefault();+ dropZone.classList.add('dragover');+ });+ dropZone.addEventListener('dragleave', () => {+ dropZone.classList.remove('dragover');+ });+ dropZone.addEventListener('drop', (e) => {+ e.preventDefault();+ dropZone.classList.remove('dragover');+ document.getElementById('single-file').files = e.dataTransfer.files;+ document.getElementById('single-file').dispatchEvent(new Event('change'));+ });+ </script>+</body>+</html>diff --git a/tests/e2e/scenarios/07-find.sh b/tests/e2e/scenarios/07-find.shnew file mode 100755index 00000000..c0dc6de9--- /dev/null+++ b/tests/e2e/scenarios/07-find.sh@@ -0,0 +1,61 @@+#!/bin/bash+# 07-find.sh — Element finding with semantic search++source "$(dirname "$0")/common.sh"++# Navigate to find test page+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/find.html\"}"+sleep 1++# ─────────────────────────────────────────────────────────────────+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 "$LAST_BODY" | jq -e '.best_ref' >/dev/null 2>&1; then+ fail "expected best_ref in response"+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find (email input)"++pt_post /find -d '{"query":"email input field"}'+assert_ok "find email"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find (delete button)"++pt_post /find -d '{"query":"delete account button","threshold":0.2}'+assert_ok "find delete"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find (search)"++pt_post /find -d '{"query":"search input","topK":5}'+assert_ok "find search"++# Verify candidates array+if ! echo "$LAST_BODY" | jq -e '.candidates | length > 0' >/dev/null 2>&1; then+ fail "expected candidates in response"+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find --tab <id>"++pt_get /tabs+TAB_ID=$(get_first_tab)++pt_post "/tabs/${TAB_ID}/find" -d '{"query":"sign up link"}'+assert_ok "tab find"++end_testdiff --git a/tests/e2e/scenarios/08-evaluate.sh b/tests/e2e/scenarios/08-evaluate.shnew file mode 100755index 00000000..865b8dc7--- /dev/null+++ b/tests/e2e/scenarios/08-evaluate.sh@@ -0,0 +1,92 @@+#!/bin/bash+# 08-evaluate.sh — JavaScript evaluation++source "$(dirname "$0")/common.sh"++# Navigate to evaluate test page+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/evaluate.html\"}"+sleep 1++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab evaluate (simple expression)"++pt_post /evaluate -d '{"expression":"1 + 1"}'+assert_ok "evaluate simple"++# Verify result+RESULT=$(echo "$LAST_BODY" | jq -r '.result')+if [ "$RESULT" != "2" ]; then+ fail "expected result=2, got $RESULT"+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab evaluate (DOM query)"++pt_post /evaluate -d '{"expression":"document.title"}'+assert_ok "evaluate DOM"++RESULT=$(echo "$LAST_BODY" | jq -r '.result')+if [ "$RESULT" != "Evaluate Test Page" ]; then+ fail "expected title, got $RESULT"+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab evaluate (call function)"++pt_post /evaluate -d '{"expression":"window.calculate.add(5, 3)"}'+assert_ok "evaluate function"++RESULT=$(echo "$LAST_BODY" | jq -r '.result')+if [ "$RESULT" != "8" ]; then+ fail "expected result=8, got $RESULT"+fi++end_test++# ─────────────────────────────────────────────────────────────────+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 "$LAST_BODY" | jq -r '.result' | jq -e '.name == "PinchTab"' >/dev/null 2>&1; then+ fail "expected testData object"+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab evaluate (modify DOM)"++pt_post /evaluate -d '{"expression":"document.getElementById(\"counter\").textContent = \"42\"; 42"}'+assert_ok "evaluate modify DOM"++# Verify the change stuck+pt_post /evaluate -d '{"expression":"document.getElementById(\"counter\").textContent"}'+RESULT=$(echo "$LAST_BODY" | jq -r '.result')+if [ "$RESULT" != "42" ]; then+ fail "expected counter=42, got $RESULT"+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab evaluate --tab <id>"++pt_get /tabs+TAB_ID=$(get_first_tab)++pt_post "/tabs/${TAB_ID}/evaluate" -d '{"expression":"window.calculate.multiply(6, 7)"}'+assert_ok "tab evaluate"++RESULT=$(echo "$LAST_BODY" | jq -r '.result')+if [ "$RESULT" != "42" ]; then+ fail "expected result=42, got $RESULT"+fi++end_testdiff --git a/tests/e2e/scenarios/09-download.sh b/tests/e2e/scenarios/09-download.shnew file mode 100755index 00000000..b4cd4c1d--- /dev/null+++ b/tests/e2e/scenarios/09-download.sh@@ -0,0 +1,50 @@+#!/bin/bash+# 09-download.sh — File download++source "$(dirname "$0")/common.sh"++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab download (text file)"++# Download the sample.txt file from fixtures server+pt_get "/download?url=${FIXTURES_URL}/sample.txt"+assert_ok "download text"++# Verify we got content back (base64 encoded by default)+if ! echo "$LAST_BODY" | jq -e '.content' >/dev/null 2>&1; then+ fail "expected content in response"+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab download (raw mode)"++pt_get "/download?url=${FIXTURES_URL}/sample.txt&raw=true"+assert_ok "download raw"++# In raw mode, body should be the file content directly+if ! echo "$LAST_BODY" | grep -q "PinchTab E2E Test Suite"; then+ fail "expected file content in raw response"+fi++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab download (HTML page)"++pt_get "/download?url=${FIXTURES_URL}/index.html"+assert_ok "download html"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab download --tab <id>"++pt_get /tabs+TAB_ID=$(get_first_tab)++pt_get "/tabs/${TAB_ID}/download?url=${FIXTURES_URL}/sample.txt"+assert_ok "tab download"++end_testdiff --git a/tests/e2e/scenarios/10-upload.sh b/tests/e2e/scenarios/10-upload.shnew file mode 100755index 00000000..2f976b24--- /dev/null+++ b/tests/e2e/scenarios/10-upload.sh@@ -0,0 +1,39 @@+#!/bin/bash+# 10-upload.sh — File upload++source "$(dirname "$0")/common.sh"++# Navigate to upload test page+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/upload.html\"}"+sleep 1++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab upload (base64 file)"++# Create a simple base64-encoded test file+# "Hello from E2E test!" in base64+FILE_CONTENT="SGVsbG8gZnJvbSBFMkUgdGVzdCE="++pt_post /upload -d "{\"selector\":\"#single-file\",\"files\":[{\"name\":\"test.txt\",\"content\":\"${FILE_CONTENT}\"}]}"+assert_ok "upload base64"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab upload (multiple files)"++pt_post /upload -d "{\"selector\":\"#multi-file\",\"files\":[{\"name\":\"file1.txt\",\"content\":\"${FILE_CONTENT}\"},{\"name\":\"file2.txt\",\"content\":\"${FILE_CONTENT}\"}]}"+assert_ok "upload multiple"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab upload --tab <id>"++pt_get /tabs+TAB_ID=$(get_first_tab)++pt_post "/tabs/${TAB_ID}/upload" -d "{\"selector\":\"#image-upload\",\"files\":[{\"name\":\"test.png\",\"content\":\"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\"}]}"+assert_ok "tab upload"++end_test