#!/usr/bin/env python3 """ Test script to verify the select element fix in cremote MCP system. This script demonstrates that select dropdowns now work correctly with: 1. Single web_interact_cremotemcp with "select" action (after server restart) 2. Multiple web_interact_multiple_cremotemcp with "select" action (works now) 3. Bulk form fill web_form_fill_bulk_cremotemcp (after server restart) The fix includes: - Added "select" action to web_interact_cremotemcp - Added SelectElement method to client - Added select-element endpoint to daemon - Modified fillFormBulk to detect select elements and use appropriate action """ import requests import json def test_multiple_interactions_select(): """Test select functionality using web_interact_multiple (works immediately)""" print("Testing select with web_interact_multiple...") url = "http://localhost:8080/interact-multiple" data = { "interactions": [ { "selector": "#state", "action": "select", "value": "TX" } ], "timeout": 5 } response = requests.post(url, json=data) if response.status_code == 200: result = response.json() print(f"✅ Multiple interactions select: {json.dumps(result, indent=2)}") # Verify the value was set verify_url = "http://localhost:8080/eval-js" verify_data = {"code": "document.querySelector('#state').value"} verify_response = requests.post(verify_url, json=verify_data) if verify_response.status_code == 200: actual_value = verify_response.json().get('result', '') print(f"✅ Verified dropdown value: '{actual_value}'") return actual_value == 'TX' else: print(f"❌ HTTP Error: {response.status_code}") return False def test_form_completion(): """Test complete form filling with mixed field types""" print("\nTesting complete form with mixed field types...") url = "http://localhost:8080/interact-multiple" data = { "interactions": [ {"selector": "#firstName", "action": "fill", "value": "Jane"}, {"selector": "#lastName", "action": "fill", "value": "Smith"}, {"selector": "#email", "action": "fill", "value": "jane.smith@test.com"}, {"selector": "#state", "action": "select", "value": "Florida"}, {"selector": "#contactPhone", "action": "click"}, {"selector": "#interestMusic", "action": "check"}, {"selector": "#newsletter", "action": "check"} ], "timeout": 10 } response = requests.post(url, json=data) if response.status_code == 200: result = response.json() success_count = result.get('success_count', 0) total_count = result.get('total_count', 0) print(f"✅ Form completion: {success_count}/{total_count} fields successful") # Extract all values to verify extract_url = "http://localhost:8080/extract-multiple" extract_data = { "selectors": { "firstName": "#firstName", "lastName": "#lastName", "email": "#email", "state": "#state", "contactMethod": "input[name='contactMethod']:checked", "musicInterest": "#interestMusic", "newsletter": "#newsletter" } } extract_response = requests.post(extract_url, json=extract_data) if extract_response.status_code == 200: values = extract_response.json().get('results', {}) print(f"✅ Form values: {json.dumps(values, indent=2)}") return success_count == total_count else: print(f"❌ HTTP Error: {response.status_code}") return False def main(): print("🧪 Testing cremote select element fixes") print("=" * 50) # Test 1: Multiple interactions select (works immediately) test1_passed = test_multiple_interactions_select() # Test 2: Complete form with mixed field types test2_passed = test_form_completion() print("\n" + "=" * 50) print("📋 Test Results Summary:") print(f"✅ Multiple interactions select: {'PASS' if test1_passed else 'FAIL'}") print(f"✅ Complete form filling: {'PASS' if test2_passed else 'FAIL'}") if test1_passed and test2_passed: print("\n🎉 All tests passed! Select elements are working correctly.") print("\n📝 Note: After server restart, these will also work:") print(" - Single web_interact_cremotemcp with 'select' action") print(" - Bulk form fill web_form_fill_bulk_cremotemcp with select detection") else: print("\n❌ Some tests failed. Check the cremote daemon status.") if __name__ == "__main__": main()