# rahulgarg01/healx architecture

> Architecture diagram of the GitHub repository rahulgarg01/healx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahulgarg01/healx
- Repository: https://github.com/rahulgarg01/healx

## Overview

##### Project Type and Purpose
- This is a Java-based open-source test automation framework/library (HealX) that enhances Selenium WebDriver with self-healing capabilities.
- Purpose: wrap Selenium calls, detect broken locators at runtime, and recover them via database-backed heuristics so tests remain robust against UI changes.

a. Test Suite (Your automated tests)
b. Selenium WebDriver (e.g., ChromeDriver)
c. CustomWebDriver & FirstRunDriver (wrapper/adapters around Selenium)
d. HealX Engine (healing logic)
- NormalRun (attribute/combination-based recovery)
- FirstRun (initial capture of locator data)
- Details utility (reflection-based locator name resolution)
e. RemoteDB (MongoDB or configured store)
f. Database (MongoDB instance)

1. Test Suite → (initialize) → CustomWebDriver or FirstRunDriver
2. CustomWebDriver.findElement(...) → underlying Selenium WebDriver
3. On NoSuchElementException:
→ CustomWebDriver catches exception
→ invokes HealX Engine (NormalRun)
→ NormalRun queries RemoteDB for stored element attributes
→ RemoteDB → MongoDB (read/write)
→ HealX Engine tries alternate locator strategies
→ CustomWebDriver retries findElement with healed locator
4. FirstRunDriver (on first execution) intercepts findElement:
→ captures attributes & position (via FirstRun)
→ writes locator data to RemoteDB → MongoDB
5. Details utility is invoked by both NormalRun and FirstRun to map exception to locator name.

##### Architectural Patterns & Principles
- Adapter/Decorator: CustomWebDriver and FirstRunDriver wrap Selenium WebDriver to extend behavior without modifying client code.
- Strategy Pattern: HealX applies different healing strategies in sequence (attribute-based, combination-based, position-based).
- DAO/Repository: RemoteDB abstracts MongoDB interactions for persisting locator metadata.
- Single Responsibility: each class (Details, HealX, FirstRun, NormalRun) has a clear focus in the healing pipeline.

##### Technologies & Frameworks
- Java 8+, Maven for build management
- Selenium WebDriver
- MongoDB (or any configured RemoteDB)
- Reflection API (in Details)
- JUnit/TestNG (implied by src/test)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Test & WebDriver Layer
    TS["Test Suite"]:::test
    PO["Page Objects"]:::test
    CD["CustomWebDriver"]:::test
    FRD["FirstRunDriver"]:::test
    SW["Selenium WebDriver"]:::test

    %% HealX Engine Layer
    subgraph "HealX Engine"
        direction TB
        HX["HealX Engine"]:::engine
        NR["NormalRun"]:::engine
        FR["FirstRun"]:::engine
        DT["Details utility"]:::engine
    end

    %% Database Layer
    subgraph "Database Layer"
        direction TB
        RDB["RemoteDB"]:::db
        MDB[(MongoDB)]:::db
    end

    %% Resources
    POM["Project POM"]:::resource
    README["README"]:::resource

    %% Connections - Initialization
    TS -->|"initialize"| CD
    TS -->|"initialize"| FRD
    TS --> PO

    %% Find Element Flow
    CD -->|"findElement call"| SW
    FRD -->|"findElement call"| SW

    %% FirstRun Data Capture
    FRD -->|"capture locator data"| FR
    FR -->|"invoke Details utility"| DT
    FR -->|"write locator data"| RDB
    RDB -->|"persist/read"| MDB

    %% Exception Handling & Healing
    CD -->|"catch NoSuchElementException"| HX
    HX --> NR
    NR -->|"invoke Details utility"| DT
    NR -->|"query/create locator data"| RDB
    RDB -->|"persist/read"| MDB
    NR -->|"retry with healed locator"| CD

    %% Resources Links
    TS --> POM
    TS --> README

    %% Click Events
    click TS "https://github.com/rahulgarg01/healx/blob/main/src/test/java/test.java"
    click CD "https://github.com/rahulgarg01/healx/blob/main/src/main/java/SelfHealing/CustomWebDriver.java"
    click FRD "https://github.com/rahulgarg01/healx/blob/main/src/main/java/SelfHealing/FirstRunDriver.java"
    click HX "https://github.com/rahulgarg01/healx/blob/main/src/main/java/SelfHealing/HealX.java"
    click NR "https://github.com/rahulgarg01/healx/blob/main/src/main/java/SelfHealing/NormalRun.java"
    click FR "https://github.com/rahulgarg01/healx/blob/main/src/main/java/SelfHealing/FirstRun.java"
    click DT "https://github.com/rahulgarg01/healx/blob/main/src/main/java/SelfHealing/Details.java"
    click RDB "https://github.com/rahulgarg01/healx/blob/main/src/main/java/SelfHealing/RemoteDB.java"
    click PO "https://github.com/rahulgarg01/healx/blob/main/src/main/java/pages/Page.java"
    click POM "https://github.com/rahulgarg01/healx/blob/main/pom.xml"
    click README "https://github.com/rahulgarg01/healx/blob/main/README.md"

    %% Styles
    classDef test fill:#e0f7e9,stroke:#2e7d32,stroke-width:2px
    classDef engine fill:#e3f2fd,stroke:#1565c0,stroke-width:2px
    classDef db fill:#fff3e0,stroke:#ef6c00,stroke-width:2px
    classDef resource fill:#f5f5f5,stroke:#9e9e9e,stroke-width:1px,stroke-dasharray: 5 5
```
