#!/bin/bash
echo "=== Functional Testing - 7 Advanced Features ==="
echo
echo "Test 1: Variables (set/get)"
curl -s -X POST http://localhost:9100/advanced/execute -H "Content-Type: application/json" -d "{\"steps\":[{\"action\":\"set-var\",\"name\":\"user\",\"value\":\"admin\"},{\"action\":\"get-var\",\"name\":\"user\"}]}"
echo -e "\n"
echo "Test 2: Clipboard (copy)"
curl -s -X POST http://localhost:9100/advanced/execute -H "Content-Type: application/json" -d "{\"steps\":[{\"action\":\"clipboard-copy\",\"text\":\"TestData123\"}]}"
echo -e "\n"
echo "Test 3: Loop (3 iterations)"
curl -s -X POST http://localhost:9100/advanced/execute -H "Content-Type: application/json" -d "{\"steps\":[{\"action\":\"loop\",\"times\":3,\"steps\":[{\"action\":\"set-var\",\"name\":\"count\",\"value\":\"1\"}]}]}"
echo -e "\n"
echo "Test 4: Verify Text (should fail)"
curl -s -X POST http://localhost:9100/advanced/execute -H "Content-Type: application/json" -d "{\"steps\":[{\"action\":\"verify-text\",\"text\":\"NonExistent\",\"stopOnError\":false}]}"
echo -e "\n"
echo "Test 5: Conditional (if)"
curl -s -X POST http://localhost:9100/advanced/execute -H "Content-Type: application/json" -d "{\"steps\":[{\"action\":\"set-var\",\"name\":\"status\",\"value\":\"ok\"},{\"action\":\"if\",\"condition\":\"var:status==ok\"}]}"
echo -e "\n"
echo "Test 6: Wait Until (should timeout)"
timeout 3 curl -s -X POST http://localhost:9100/advanced/execute -H "Content-Type: application/json" -d "{\"steps\":[{\"action\":\"wait-until\",\"condition\":\"text:NeverAppears\",\"timeout\":2,\"stopOnError\":false}]}"
echo -e "\n"
echo "Test 7: Find-Click (OCR-based)"
curl -s -X POST http://localhost:9100/advanced/execute -H "Content-Type: application/json" -d "{\"steps\":[{\"action\":\"find-click\",\"description\":\"test\",\"stopOnError\":false}]}"
echo