Spaces:
Sleeping
Sleeping
Tu Nombre commited on
Commit ·
22498c9
1
Parent(s): 169c903
Tester: interactua (rellena+clic) antes de juzgar la app
Browse files
app.py
CHANGED
|
@@ -23,13 +23,52 @@ _groq = OpenAI(api_key=GROQ_KEY, base_url="https://api.groq.com/openai/v1") if G
|
|
| 23 |
_executor = ThreadPoolExecutor(max_workers=1)
|
| 24 |
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def _abrir_y_capturar(url):
|
| 27 |
-
"""Abre la URL
|
|
|
|
| 28 |
with sync_playwright() as p:
|
| 29 |
navegador = p.chromium.launch(args=["--no-sandbox", "--disable-dev-shm-usage"])
|
| 30 |
pagina = navegador.new_page(viewport={"width": 1280, "height": 1600})
|
| 31 |
pagina.goto(url, wait_until="networkidle", timeout=45000)
|
| 32 |
-
pagina.wait_for_timeout(
|
|
|
|
|
|
|
| 33 |
texto = pagina.inner_text("body")[:6000]
|
| 34 |
ruta = os.path.join(tempfile.gettempdir(), "captura.png")
|
| 35 |
pagina.screenshot(path=ruta, full_page=True)
|
|
|
|
| 23 |
_executor = ThreadPoolExecutor(max_workers=1)
|
| 24 |
|
| 25 |
|
| 26 |
+
def _interactuar(pagina):
|
| 27 |
+
"""Best-effort: rellena inputs visibles y pulsa un boton de accion real,
|
| 28 |
+
para que el Tester vea la app DESPUES de usarla, no solo al cargar."""
|
| 29 |
+
try:
|
| 30 |
+
inputs = pagina.locator("input[type=text], input[type=number], input:not([type]), textarea").all()
|
| 31 |
+
for inp in inputs[:6]:
|
| 32 |
+
try:
|
| 33 |
+
if not inp.is_visible():
|
| 34 |
+
continue
|
| 35 |
+
tipo = inp.get_attribute("type") or "text"
|
| 36 |
+
inp.fill("5" if tipo == "number" else "prueba")
|
| 37 |
+
except Exception:
|
| 38 |
+
continue
|
| 39 |
+
except Exception:
|
| 40 |
+
pass
|
| 41 |
+
try:
|
| 42 |
+
for btn in pagina.locator("button").all():
|
| 43 |
+
try:
|
| 44 |
+
if not btn.is_visible():
|
| 45 |
+
continue
|
| 46 |
+
texto_btn = (btn.inner_text() or "").strip().lower()
|
| 47 |
+
if any(p in texto_btn for p in ["clear", "limpiar", "borrar", "flag"]):
|
| 48 |
+
continue
|
| 49 |
+
btn.click(timeout=3000)
|
| 50 |
+
pagina.wait_for_timeout(3000)
|
| 51 |
+
try:
|
| 52 |
+
pagina.wait_for_load_state("networkidle", timeout=8000)
|
| 53 |
+
except Exception:
|
| 54 |
+
pass
|
| 55 |
+
break
|
| 56 |
+
except Exception:
|
| 57 |
+
continue
|
| 58 |
+
except Exception:
|
| 59 |
+
pass
|
| 60 |
+
|
| 61 |
+
|
| 62 |
def _abrir_y_capturar(url):
|
| 63 |
+
"""Abre la URL, interactua con la app (rellena+clic), y devuelve
|
| 64 |
+
(texto_visible, ruta_captura) DESPUES de esa interaccion."""
|
| 65 |
with sync_playwright() as p:
|
| 66 |
navegador = p.chromium.launch(args=["--no-sandbox", "--disable-dev-shm-usage"])
|
| 67 |
pagina = navegador.new_page(viewport={"width": 1280, "height": 1600})
|
| 68 |
pagina.goto(url, wait_until="networkidle", timeout=45000)
|
| 69 |
+
pagina.wait_for_timeout(2000)
|
| 70 |
+
_interactuar(pagina)
|
| 71 |
+
pagina.wait_for_timeout(1000)
|
| 72 |
texto = pagina.inner_text("body")[:6000]
|
| 73 |
ruta = os.path.join(tempfile.gettempdir(), "captura.png")
|
| 74 |
pagina.screenshot(path=ruta, full_page=True)
|