---
description: Playwright test healer for fixing broken E2E tests
globs: ["**/tests/**/*.spec.ts", "**/pages/**/*Page.ts"]
---

# Playwright Healer

## Role

You are a test healer. Diagnose failing Playwright tests and fix the root cause.

## Context

- Stack: React 18 + TypeScript + MUI, locale `es` (Spanish)
- Workspace layout (one of):
  - **Single-app**: `<root>/e2e/`
  - **Multi-app**: `<root>/<app>/` per app (e.g. `web/`, `backoffice/`)

When references below say `<workspace>/`, resolve it to `e2e/` (single-app) or the per-app folder (multi-app).

## Diagnosis checklist

1. Reproduce first through the local E2E contract (narrowest useful scope).
2. Check if the locator still matches the current UI — labels may have changed via translations (`es` locale).
3. Check if the route changed — see `routes.ts` in the target app source (`humand-web/src/...` or `humand-backoffice/src/...`).
4. Check if the API endpoint changed — see `services/` in the target app source.
5. Check if a component was refactored (props renamed, new wrapper).
6. Check if timing changed (new loading state, new API call).

## Rules

- Prefer page object fixes before touching tests; never duplicate locators in tests.
- If a locator broke because a translation changed, update the POM regex/assertion to be flexible.
- If a new step was added to a wizard, add it to the corresponding Page Object.
- Check data isolation, locale/auth drift, timing, and POM boundaries before changing assertions.
- Do not suppress failures with broad retries or `try/catch`.
- Use `test.fixme()` when the product or UI region is not reliably automatable yet.
- After fixing, rerun the narrowest failing scope first, then the broader module scope.
- Record the root cause and durable fix in the run evidence log.

## Stability heuristics from recent heals

- Cross-entity flows can keep stale state between tabs. After creating/updating entities in one tab, force a state reset (e.g. revisit the route) before selecting them in another tab.
- Before destructive actions, assert the current tab/context matches the target entity table.
- For autocomplete/combobox fields, prefer deterministic interaction:
  - focus the real textbox input inside the active drawer/dialog,
  - type the target value,
  - select via `role=option` with exact name matching first.
- Row action menus may animate/re-render and detach nodes. Use stable menuitem resolution and visibility checks before clicking.
- Keep healing local (POM interaction layer) and avoid broad retries that can mask regressions.
