0b3a1313c2
- .gitignore - CAPABILITIES_TODO.md - demo_e2e/results/prueba_1_quotes.json - demo_e2e/results/prueba_2_perceive.json - demo_e2e/results/prueba_3_search.json - demo_e2e/results/prueba_4_login_session.json - demo_e2e/results/prueba_5_books.json - demo_e2e/results/prueba_6_session_storage.json - demo_e2e/results/prueba_7_find_honesto.json - demo_e2e/results/prueba_8_verificacion.json - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
71 lines
2.7 KiB
Python
71 lines
2.7 KiB
Python
"""E2E de las features nuevas (no parte de los 9 del demo principal):
|
|
|
|
- dom_find_ref_by_text (P0-3): encontrar por texto y clicar por #ref en the-internet.
|
|
- handle_dialog + DialogLog (P1-4): auto-aceptar un confirm() y verificar Count/LastMessage
|
|
reportado por browser_disconnect.
|
|
|
|
Requiere Chrome CDP en 9333 ya corriendo + binario browser_mcp compilado.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
|
|
from mcp_client import MCPClient
|
|
|
|
ROOT = "/home/enmanuel/fn_registry"
|
|
EXE = os.path.join(ROOT, "projects/web_scraping/apps/browser_mcp/browser_mcp")
|
|
PORT = 9333
|
|
|
|
|
|
def main():
|
|
c = MCPClient(EXE, env={"FN_REGISTRY_ROOT": ROOT}, cwd=ROOT,
|
|
stderr_path="/tmp/fn_newfeat_stderr.log")
|
|
c.initialize()
|
|
results = {}
|
|
|
|
# --- P0-3: find_ref_by_text + click_ref ---
|
|
c.call("browser_connect", {"port": PORT})
|
|
c.call("tab_navigate", {"port": PORT, "url": "https://the-internet.herokuapp.com/"})
|
|
c.call("page_wait_load", {"port": PORT, "timeout_ms": 15000})
|
|
find_txt, find_err = c.call("dom_find_ref_by_text",
|
|
{"port": PORT, "text": "Form Authentication"})
|
|
ref = None
|
|
if not find_err and "ref=" in find_txt:
|
|
ref = int(find_txt.split("ref=")[1].split()[0])
|
|
after = ""
|
|
if ref:
|
|
after, _ = c.call("dom_click_ref", {"port": PORT, "ref": ref})
|
|
landed = ("Login Page" in after) or ("Username" in after) or ("/login" in after.lower())
|
|
results["find_ref_by_text"] = {
|
|
"find_response": find_txt, "ref": ref,
|
|
"landed_on_login": landed,
|
|
"verdict": "PASS" if (ref and landed) else "FAIL",
|
|
}
|
|
|
|
# --- P1-4: handle_dialog + DialogLog ---
|
|
c.call("tab_navigate",
|
|
{"port": PORT, "url": "https://the-internet.herokuapp.com/javascript_alerts"})
|
|
c.call("page_wait_load", {"port": PORT, "timeout_ms": 15000})
|
|
c.call("handle_dialog", {"port": PORT, "accept": True})
|
|
# El botón "Click for JS Confirm" dispara confirm("I am a JS Confirm").
|
|
c.call("dom_click_text", {"port": PORT, "text": "Click for JS Confirm"})
|
|
result_text, _ = c.call("page_get_text", {"port": PORT, "selector": "#result"})
|
|
# disconnect reporta el DialogLog (count + último mensaje).
|
|
disc_msg, _ = c.call("browser_disconnect", {"port": PORT})
|
|
accepted = "You clicked: Ok" in result_text
|
|
log_reported = ("dialogs auto-handled: 1" in disc_msg) and ("I am a JS Confirm" in disc_msg)
|
|
results["dialog_log"] = {
|
|
"result_text": result_text.strip(),
|
|
"disconnect_msg": disc_msg,
|
|
"confirm_accepted": accepted,
|
|
"log_reported": log_reported,
|
|
"verdict": "PASS" if (accepted and log_reported) else "FAIL",
|
|
}
|
|
|
|
c.close()
|
|
print(json.dumps(results, ensure_ascii=False, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|