This project demonstrates a Self-Healing Automation Framework designed to solve common causes of "flaky" tests in UI automation.
Instead of failing when a selector changes or an element loads slowly, this framework detects the failure, applies a "Smart Wait" or "Backup Strategy" to find the element, and then self-corrects the source code to prevent future failures.
- Language: Python
- Library: Playwright (Sync API)
- Concept: Design Pattern (Wrapper / Healer)
- Smart Locator Recovery: If an ID changes (e.g.,
#submit->#new-id), the script automatically tries backup strategies (Text, CSS Classes, Attributes). - Auto-Correction: Once a valid locator is found, the script rewrites its own source code to permanently fix the test.
- Resilience to Timing: Handles network lags and late-loading elements automatically.
- Stale Element Handling: Detects DOM refreshes and re-queries elements to prevent stale reference errors.
run_test.py- The main driver script that runs the test scenarios.auto_healer.py- The "Brain" of the project. Contains the logic for detection, diagnosis, and file patching.index.html- A custom dashboard simulation that intentionally creates 3 types of errors (Broken ID, Late Load, Stale Element) to test the healer.
- The test attempts to click an element using a primary selector.
- If it fails, it catches the exception and enters a Healing Loop.
- It iterates through a list of
fallbacks(Text, Name, Class). - Upon success, it updates
run_test.pywith the new working selector.
Created as a Proof of Concept for building resilient automation frameworks.