self-healing-elements 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. self_healing_elements-0.1.0/PKG-INFO +350 -0
  2. self_healing_elements-0.1.0/README.md +329 -0
  3. self_healing_elements-0.1.0/pyproject.toml +40 -0
  4. self_healing_elements-0.1.0/setup.cfg +4 -0
  5. self_healing_elements-0.1.0/src/self_healing/__init__.py +10 -0
  6. self_healing_elements-0.1.0/src/self_healing/__main__.py +5 -0
  7. self_healing_elements-0.1.0/src/self_healing/api.py +642 -0
  8. self_healing_elements-0.1.0/src/self_healing/capture.py +113 -0
  9. self_healing_elements-0.1.0/src/self_healing/cli.py +230 -0
  10. self_healing_elements-0.1.0/src/self_healing/driver.py +73 -0
  11. self_healing_elements-0.1.0/src/self_healing/engine.py +455 -0
  12. self_healing_elements-0.1.0/src/self_healing/llm_explainer.py +120 -0
  13. self_healing_elements-0.1.0/src/self_healing/logger.py +91 -0
  14. self_healing_elements-0.1.0/src/self_healing/matcher.py +239 -0
  15. self_healing_elements-0.1.0/src/self_healing/ml_neural_ranker.py +204 -0
  16. self_healing_elements-0.1.0/src/self_healing/ml_neural_trainer.py +171 -0
  17. self_healing_elements-0.1.0/src/self_healing/ml_ranker.py +177 -0
  18. self_healing_elements-0.1.0/src/self_healing/ml_trainer.py +186 -0
  19. self_healing_elements-0.1.0/src/self_healing/py.typed +0 -0
  20. self_healing_elements-0.1.0/src/self_healing/registry.py +221 -0
  21. self_healing_elements-0.1.0/src/self_healing/reporter.py +137 -0
  22. self_healing_elements-0.1.0/src/self_healing/semantic_ranker.py +140 -0
  23. self_healing_elements-0.1.0/src/self_healing_elements.egg-info/PKG-INFO +350 -0
  24. self_healing_elements-0.1.0/src/self_healing_elements.egg-info/SOURCES.txt +34 -0
  25. self_healing_elements-0.1.0/src/self_healing_elements.egg-info/dependency_links.txt +1 -0
  26. self_healing_elements-0.1.0/src/self_healing_elements.egg-info/entry_points.txt +2 -0
  27. self_healing_elements-0.1.0/src/self_healing_elements.egg-info/requires.txt +11 -0
  28. self_healing_elements-0.1.0/src/self_healing_elements.egg-info/top_level.txt +1 -0
  29. self_healing_elements-0.1.0/tests/test_api.py +156 -0
  30. self_healing_elements-0.1.0/tests/test_healing.py +146 -0
  31. self_healing_elements-0.1.0/tests/test_llm_explainer.py +98 -0
  32. self_healing_elements-0.1.0/tests/test_logging_reporting.py +266 -0
  33. self_healing_elements-0.1.0/tests/test_ml_ranking.py +293 -0
  34. self_healing_elements-0.1.0/tests/test_neural_ranking.py +67 -0
  35. self_healing_elements-0.1.0/tests/test_registry_migration.py +68 -0
  36. self_healing_elements-0.1.0/tests/test_semantic_matching.py +58 -0
@@ -0,0 +1,350 @@
1
+ Metadata-Version: 2.4
2
+ Name: self-healing-elements
3
+ Version: 0.1.0
4
+ Summary: AI-powered self-healing Selenium locator engine
5
+ Author: LIKITH
6
+ Project-URL: Homepage, https://github.com/LIKITH/self-healing-elements
7
+ Keywords: selenium,self-healing,test-automation,ai,ml
8
+ Requires-Python: >=3.12
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: selenium
11
+ Requires-Dist: pytest
12
+ Requires-Dist: fastapi
13
+ Requires-Dist: uvicorn
14
+ Requires-Dist: pydantic
15
+ Requires-Dist: beautifulsoup4
16
+ Requires-Dist: httpx
17
+ Requires-Dist: xgboost
18
+ Requires-Dist: pandas
19
+ Requires-Dist: scikit-learn
20
+ Requires-Dist: litellm
21
+
22
+ # Self-Healing Elements
23
+
24
+ ```bash
25
+ pip install self-healing-elements
26
+ ```
27
+
28
+ ```python
29
+ from selenium import webdriver
30
+ from selenium.webdriver.common.by import By
31
+ from self_healing import SelfHealingDriver
32
+
33
+ driver = SelfHealingDriver(webdriver.Chrome())
34
+ heading = driver.find_element(By.TAG_NAME, "h1", logical_id="page_heading")
35
+ ```
36
+
37
+ ![Python](https://img.shields.io/badge/Python-3.11-3776AB?logo=python&logoColor=white)
38
+ ![Tests](https://img.shields.io/badge/Tests-41%20Passing-brightgreen)
39
+ ![License](https://img.shields.io/badge/License-MIT-blue.svg)
40
+
41
+ An AI-powered and heuristic-driven self-healing locator framework for web automation. It dynamically detects, heals, and updates broken web element locators (like XPaths and CSS Selectors) using historical attribute metadata and DOM structure analysis.
42
+
43
+ ## Demo
44
+
45
+ ### Quick start (local)
46
+
47
+ ```powershell
48
+ # 1) From the project root
49
+ .venv\Scripts\activate
50
+
51
+ # 2) Install dependencies
52
+ pip install -r requirements.txt
53
+
54
+ # 3) Start the API locally
55
+ uvicorn src.self_healing.api:app --host 0.0.0.0 --port 8000 --reload
56
+ ```
57
+
58
+ Then open:
59
+
60
+ ```text
61
+ http://localhost:8000/
62
+ ```
63
+
64
+ The root route displays the live dashboard with the summary panel, healing event table, and registry viewer.
65
+
66
+ ### How it works
67
+
68
+ The healing flow is:
69
+
70
+ 1. A locator fails or becomes stale.
71
+ 2. The engine loads the stored element profile from SQLite.
72
+ 3. It scans the page and measures similarity across candidate elements.
73
+ 4. It blends a rule-based score with XGBoost, PyTorch, and semantic similarity scores.
74
+ 5. It picks the best candidate and returns a structured explainability payload.
75
+ 6. It writes the updated registry + healing history, and logs the event.
76
+
77
+ #### Example: POST /heal
78
+
79
+ Request payload:
80
+
81
+ ```json
82
+ {
83
+ "logical_id": "id:submit-btn",
84
+ "by": "id",
85
+ "value": "submit-btn",
86
+ "page_source": "<html><body><button id='new-submit-btn' class='btn btn-primary' type='submit'>Submit Form</button></body></html>"
87
+ }
88
+ ```
89
+
90
+ Example response:
91
+
92
+ ```json
93
+ {
94
+ "status": "HEALED",
95
+ "logical_id": "id:submit-btn",
96
+ "original_locator": {"type": "id", "value": "submit-btn"},
97
+ "healed_locator": {"type": "id", "value": "new-submit-btn"},
98
+ "confidence_score": 0.875,
99
+ "explanation": "Successfully healed locator for 'id:submit-btn'. Matched candidate <button> with confidence score 87.50%. Generated new locator: id='new-submit-btn'.",
100
+ "xai_breakdown": {
101
+ "features": {
102
+ "tag_score": 1.0,
103
+ "text_score": 1.0,
104
+ "class_score": 1.0,
105
+ "attributes_score": 0.5,
106
+ "parent_score": 1.0
107
+ },
108
+ "feature_importance": {
109
+ "tag": 0.1,
110
+ "text": 0.3,
111
+ "class": 0.2,
112
+ "parent": 0.15,
113
+ "attributes": 0.125
114
+ },
115
+ "decision_breakdown": {
116
+ "rule_score": 0.875,
117
+ "xgboost_score": 0.91,
118
+ "neural_score": 0.88,
119
+ "semantic_score": 0.82,
120
+ "final_blended_score": 0.875
121
+ },
122
+ "scores": {
123
+ "rule_score": 0.875,
124
+ "ml_score": 0.91,
125
+ "nn_score": 0.88,
126
+ "semantic_score": 0.82,
127
+ "final_score": 0.875
128
+ },
129
+ "confidence_tier": "HIGH",
130
+ "reasoning": "Final score of 87.5% exceeds the auto-healing threshold."
131
+ }
132
+ }
133
+ ```
134
+
135
+ This gives both a human-readable explanation and a machine-readable XAI payload for downstream dashboards, tooling, or analytics.
136
+
137
+ ### Tech stack
138
+
139
+ | Layer | Technology | Purpose |
140
+ | --- | --- | --- |
141
+ | Rules | Heuristic matcher | Fast weighted similarity scoring for tag, text, class, attributes, and parent context |
142
+ | XGBoost | `xgboost` | Learned ranking signal for candidate prioritization |
143
+ | PyTorch | `torch` / custom neural ranker | Secondary learned model signal for confidence scoring |
144
+ | Sentence Transformers | `sentence-transformers` | Semantic similarity for text- and structure-aware matching |
145
+ | LLM | Ollama + LiteLLM | Natural-language explanation generation for healed candidates |
146
+ | API | FastAPI + Uvicorn | REST JSON API and dashboard endpoints |
147
+ | Storage | SQLite | Persistent registry of element profiles and healing history |
148
+ | Containerization | Docker + Docker Compose | Production-style deployment, persistence, and orchestration |
149
+
150
+ ## Features
151
+
152
+ - **Dynamic Locator Healing**: Seamlessly falls back to backup strategies when a primary locator fails.
153
+ - **Smart DOM Similarity Matching**: Uses weighted attributes (IDs, classes, text content, tags) to find the best match for the changed element.
154
+ - **Auto-Update & Persistence**: Stores healed locators back into a local registry to make future runs faster.
155
+ - **Detailed Healing Logs**: Outputs diagnostic reports explaining why a locator was healed and the confidence score.
156
+
157
+ ## Directory Structure
158
+
159
+ ```text
160
+ self-healing-elements/
161
+ ├── docs/ # Architecture, roadmap, problem statements
162
+ ├── src/self_healing/ # Package source code
163
+ │ └── __init__.py
164
+ ├── tests/ # Automated test suites
165
+ ├── .gitignore # Git exclusion rules
166
+ ├── README.md # Project overview
167
+ └── requirements.txt # Project dependencies
168
+ ```
169
+
170
+ ## Getting Started
171
+
172
+ 1. Activate your virtual environment:
173
+ ```powershell
174
+ .venv\Scripts\activate
175
+ ```
176
+ 2. Install dependencies:
177
+ ```powershell
178
+ pip install -r requirements.txt
179
+ ```
180
+ 3. Run tests:
181
+ ```powershell
182
+ pytest
183
+ ```
184
+
185
+ ## Docker / Compose
186
+
187
+ This repository includes a production-style Docker stack with a FastAPI API, background retraining worker, Nginx reverse proxy, and local Ollama service.
188
+
189
+ ### Production stack
190
+
191
+ ```bash
192
+ cp .env.example .env
193
+ make build
194
+ make up
195
+ ```
196
+
197
+ Then open the app through Nginx:
198
+
199
+ ```text
200
+ http://localhost/
201
+ ```
202
+
203
+ ### Local development override
204
+
205
+ ```bash
206
+ cp .env.example .env
207
+ docker compose -f docker-compose.yml -f docker-compose.override.yml up --build
208
+ ```
209
+
210
+ This runs the dev stack with the app surfaced on:
211
+
212
+ ```text
213
+ http://localhost:8000/
214
+ ```
215
+
216
+ ### Useful commands
217
+
218
+ ```bash
219
+ make logs
220
+ make test
221
+ make train
222
+ docker compose down -v
223
+ ```
224
+
225
+ > Note: `make down` and `docker compose down -v` remove the named volumes, so use them carefully if you want to preserve registry or model state.
226
+
227
+ ### TLS certificate note for HTTPS
228
+
229
+ The HTTPS-enabled Nginx config expects a certificate pair in `./certs`:
230
+
231
+ ```bash
232
+ mkdir -p certs
233
+ openssl req -x509 -nodes -newkey rsa:2048 \
234
+ -keyout certs/server.key \
235
+ -out certs/server.crt \
236
+ -days 365 \
237
+ -subj "/CN=localhost"
238
+ ```
239
+
240
+ Then start the stack with the TLS config mounted by `docker-compose.override.yml`.
241
+
242
+ ---
243
+
244
+ ## Docker notes
245
+
246
+ - Named volumes persist the registry, healing event log, and trained model artifacts across restarts.
247
+ - The API reads/writes SQLite state from `/data/registry` and logs from `/data/logs`.
248
+ - The worker retrains from stored healing history and writes model artifacts to `/data/models`.
249
+ - The local LLM service is exposed internally at `http://ollama:11434` for explanation generation.
250
+
251
+ ## Features
252
+
253
+ - **Dynamic Locator Healing**: Seamlessly falls back to backup strategies when a primary locator fails.
254
+ - **Smart DOM Similarity Matching**: Uses weighted attributes (IDs, classes, text content, tags) to find the best match for the changed element.
255
+ - **Auto-Update & Persistence**: Stores healed locators back into a local registry to make future runs faster.
256
+ - **Detailed Healing Logs**: Outputs diagnostic reports explaining why a locator was healed and the confidence score.
257
+
258
+ ## Directory Structure
259
+
260
+ ```text
261
+ self-healing-elements/
262
+ ├── docs/ # Architecture, roadmap, problem statements
263
+ ├── src/self_healing/ # Package source code
264
+ │ └── __init__.py
265
+ ├── tests/ # Automated test suites
266
+ ├── .gitignore # Git exclusion rules
267
+ ├── README.md # Project overview
268
+ └── requirements.txt # Project dependencies
269
+ ```
270
+
271
+ ## Getting Started
272
+
273
+ 1. Activate your virtual environment:
274
+ ```powershell
275
+ .venv\Scripts\activate
276
+ ```
277
+ 2. Install dependencies:
278
+ ```powershell
279
+ pip install -r requirements.txt
280
+ ```
281
+ 3. Run tests:
282
+ ```powershell
283
+ pytest
284
+ ```
285
+
286
+ ## Docker / Compose
287
+
288
+ This repository includes a production-style Docker stack with a FastAPI API, background retraining worker, Nginx reverse proxy, and local Ollama service.
289
+
290
+ ### Production stack
291
+
292
+ ```bash
293
+ cp .env.example .env
294
+ make build
295
+ make up
296
+ ```
297
+
298
+ Then open the app through Nginx:
299
+
300
+ ```text
301
+ http://localhost/
302
+ ```
303
+
304
+ ### Local development override
305
+
306
+ ```bash
307
+ cp .env.example .env
308
+ docker compose -f docker-compose.yml -f docker-compose.override.yml up --build
309
+ ```
310
+
311
+ This runs the dev stack with the app surfaced on:
312
+
313
+ ```text
314
+ http://localhost:8000/
315
+ ```
316
+
317
+ ### Useful commands
318
+
319
+ ```bash
320
+ make logs
321
+ make test
322
+ make train
323
+ t docker compose down -v
324
+ ```
325
+
326
+ > Note: `make down` and `docker compose down -v` remove the named volumes, so use them carefully if you want to preserve registry or model state.
327
+
328
+ ### TLS certificate note for HTTPS
329
+
330
+ The HTTPS-enabled Nginx config expects a certificate pair in `./certs`:
331
+
332
+ ```bash
333
+ mkdir -p certs
334
+ openssl req -x509 -nodes -newkey rsa:2048 \
335
+ -keyout certs/server.key \
336
+ -out certs/server.crt \
337
+ -days 365 \
338
+ -subj "/CN=localhost"
339
+ ```
340
+
341
+ Then start the stack with the TLS config mounted by `docker-compose.override.yml`.
342
+
343
+ ---
344
+
345
+ ## Docker notes
346
+
347
+ - Named volumes persist the registry, healing event log, and trained model artifacts across restarts.
348
+ - The API reads/writes SQLite state from `/data/registry` and logs from `/data/logs`.
349
+ - The worker retrains from stored healing history and writes model artifacts to `/data/models`.
350
+ - The local LLM service is exposed internally at `http://ollama:11434` for explanation generation.
@@ -0,0 +1,329 @@
1
+ # Self-Healing Elements
2
+
3
+ ```bash
4
+ pip install self-healing-elements
5
+ ```
6
+
7
+ ```python
8
+ from selenium import webdriver
9
+ from selenium.webdriver.common.by import By
10
+ from self_healing import SelfHealingDriver
11
+
12
+ driver = SelfHealingDriver(webdriver.Chrome())
13
+ heading = driver.find_element(By.TAG_NAME, "h1", logical_id="page_heading")
14
+ ```
15
+
16
+ ![Python](https://img.shields.io/badge/Python-3.11-3776AB?logo=python&logoColor=white)
17
+ ![Tests](https://img.shields.io/badge/Tests-41%20Passing-brightgreen)
18
+ ![License](https://img.shields.io/badge/License-MIT-blue.svg)
19
+
20
+ An AI-powered and heuristic-driven self-healing locator framework for web automation. It dynamically detects, heals, and updates broken web element locators (like XPaths and CSS Selectors) using historical attribute metadata and DOM structure analysis.
21
+
22
+ ## Demo
23
+
24
+ ### Quick start (local)
25
+
26
+ ```powershell
27
+ # 1) From the project root
28
+ .venv\Scripts\activate
29
+
30
+ # 2) Install dependencies
31
+ pip install -r requirements.txt
32
+
33
+ # 3) Start the API locally
34
+ uvicorn src.self_healing.api:app --host 0.0.0.0 --port 8000 --reload
35
+ ```
36
+
37
+ Then open:
38
+
39
+ ```text
40
+ http://localhost:8000/
41
+ ```
42
+
43
+ The root route displays the live dashboard with the summary panel, healing event table, and registry viewer.
44
+
45
+ ### How it works
46
+
47
+ The healing flow is:
48
+
49
+ 1. A locator fails or becomes stale.
50
+ 2. The engine loads the stored element profile from SQLite.
51
+ 3. It scans the page and measures similarity across candidate elements.
52
+ 4. It blends a rule-based score with XGBoost, PyTorch, and semantic similarity scores.
53
+ 5. It picks the best candidate and returns a structured explainability payload.
54
+ 6. It writes the updated registry + healing history, and logs the event.
55
+
56
+ #### Example: POST /heal
57
+
58
+ Request payload:
59
+
60
+ ```json
61
+ {
62
+ "logical_id": "id:submit-btn",
63
+ "by": "id",
64
+ "value": "submit-btn",
65
+ "page_source": "<html><body><button id='new-submit-btn' class='btn btn-primary' type='submit'>Submit Form</button></body></html>"
66
+ }
67
+ ```
68
+
69
+ Example response:
70
+
71
+ ```json
72
+ {
73
+ "status": "HEALED",
74
+ "logical_id": "id:submit-btn",
75
+ "original_locator": {"type": "id", "value": "submit-btn"},
76
+ "healed_locator": {"type": "id", "value": "new-submit-btn"},
77
+ "confidence_score": 0.875,
78
+ "explanation": "Successfully healed locator for 'id:submit-btn'. Matched candidate <button> with confidence score 87.50%. Generated new locator: id='new-submit-btn'.",
79
+ "xai_breakdown": {
80
+ "features": {
81
+ "tag_score": 1.0,
82
+ "text_score": 1.0,
83
+ "class_score": 1.0,
84
+ "attributes_score": 0.5,
85
+ "parent_score": 1.0
86
+ },
87
+ "feature_importance": {
88
+ "tag": 0.1,
89
+ "text": 0.3,
90
+ "class": 0.2,
91
+ "parent": 0.15,
92
+ "attributes": 0.125
93
+ },
94
+ "decision_breakdown": {
95
+ "rule_score": 0.875,
96
+ "xgboost_score": 0.91,
97
+ "neural_score": 0.88,
98
+ "semantic_score": 0.82,
99
+ "final_blended_score": 0.875
100
+ },
101
+ "scores": {
102
+ "rule_score": 0.875,
103
+ "ml_score": 0.91,
104
+ "nn_score": 0.88,
105
+ "semantic_score": 0.82,
106
+ "final_score": 0.875
107
+ },
108
+ "confidence_tier": "HIGH",
109
+ "reasoning": "Final score of 87.5% exceeds the auto-healing threshold."
110
+ }
111
+ }
112
+ ```
113
+
114
+ This gives both a human-readable explanation and a machine-readable XAI payload for downstream dashboards, tooling, or analytics.
115
+
116
+ ### Tech stack
117
+
118
+ | Layer | Technology | Purpose |
119
+ | --- | --- | --- |
120
+ | Rules | Heuristic matcher | Fast weighted similarity scoring for tag, text, class, attributes, and parent context |
121
+ | XGBoost | `xgboost` | Learned ranking signal for candidate prioritization |
122
+ | PyTorch | `torch` / custom neural ranker | Secondary learned model signal for confidence scoring |
123
+ | Sentence Transformers | `sentence-transformers` | Semantic similarity for text- and structure-aware matching |
124
+ | LLM | Ollama + LiteLLM | Natural-language explanation generation for healed candidates |
125
+ | API | FastAPI + Uvicorn | REST JSON API and dashboard endpoints |
126
+ | Storage | SQLite | Persistent registry of element profiles and healing history |
127
+ | Containerization | Docker + Docker Compose | Production-style deployment, persistence, and orchestration |
128
+
129
+ ## Features
130
+
131
+ - **Dynamic Locator Healing**: Seamlessly falls back to backup strategies when a primary locator fails.
132
+ - **Smart DOM Similarity Matching**: Uses weighted attributes (IDs, classes, text content, tags) to find the best match for the changed element.
133
+ - **Auto-Update & Persistence**: Stores healed locators back into a local registry to make future runs faster.
134
+ - **Detailed Healing Logs**: Outputs diagnostic reports explaining why a locator was healed and the confidence score.
135
+
136
+ ## Directory Structure
137
+
138
+ ```text
139
+ self-healing-elements/
140
+ ├── docs/ # Architecture, roadmap, problem statements
141
+ ├── src/self_healing/ # Package source code
142
+ │ └── __init__.py
143
+ ├── tests/ # Automated test suites
144
+ ├── .gitignore # Git exclusion rules
145
+ ├── README.md # Project overview
146
+ └── requirements.txt # Project dependencies
147
+ ```
148
+
149
+ ## Getting Started
150
+
151
+ 1. Activate your virtual environment:
152
+ ```powershell
153
+ .venv\Scripts\activate
154
+ ```
155
+ 2. Install dependencies:
156
+ ```powershell
157
+ pip install -r requirements.txt
158
+ ```
159
+ 3. Run tests:
160
+ ```powershell
161
+ pytest
162
+ ```
163
+
164
+ ## Docker / Compose
165
+
166
+ This repository includes a production-style Docker stack with a FastAPI API, background retraining worker, Nginx reverse proxy, and local Ollama service.
167
+
168
+ ### Production stack
169
+
170
+ ```bash
171
+ cp .env.example .env
172
+ make build
173
+ make up
174
+ ```
175
+
176
+ Then open the app through Nginx:
177
+
178
+ ```text
179
+ http://localhost/
180
+ ```
181
+
182
+ ### Local development override
183
+
184
+ ```bash
185
+ cp .env.example .env
186
+ docker compose -f docker-compose.yml -f docker-compose.override.yml up --build
187
+ ```
188
+
189
+ This runs the dev stack with the app surfaced on:
190
+
191
+ ```text
192
+ http://localhost:8000/
193
+ ```
194
+
195
+ ### Useful commands
196
+
197
+ ```bash
198
+ make logs
199
+ make test
200
+ make train
201
+ docker compose down -v
202
+ ```
203
+
204
+ > Note: `make down` and `docker compose down -v` remove the named volumes, so use them carefully if you want to preserve registry or model state.
205
+
206
+ ### TLS certificate note for HTTPS
207
+
208
+ The HTTPS-enabled Nginx config expects a certificate pair in `./certs`:
209
+
210
+ ```bash
211
+ mkdir -p certs
212
+ openssl req -x509 -nodes -newkey rsa:2048 \
213
+ -keyout certs/server.key \
214
+ -out certs/server.crt \
215
+ -days 365 \
216
+ -subj "/CN=localhost"
217
+ ```
218
+
219
+ Then start the stack with the TLS config mounted by `docker-compose.override.yml`.
220
+
221
+ ---
222
+
223
+ ## Docker notes
224
+
225
+ - Named volumes persist the registry, healing event log, and trained model artifacts across restarts.
226
+ - The API reads/writes SQLite state from `/data/registry` and logs from `/data/logs`.
227
+ - The worker retrains from stored healing history and writes model artifacts to `/data/models`.
228
+ - The local LLM service is exposed internally at `http://ollama:11434` for explanation generation.
229
+
230
+ ## Features
231
+
232
+ - **Dynamic Locator Healing**: Seamlessly falls back to backup strategies when a primary locator fails.
233
+ - **Smart DOM Similarity Matching**: Uses weighted attributes (IDs, classes, text content, tags) to find the best match for the changed element.
234
+ - **Auto-Update & Persistence**: Stores healed locators back into a local registry to make future runs faster.
235
+ - **Detailed Healing Logs**: Outputs diagnostic reports explaining why a locator was healed and the confidence score.
236
+
237
+ ## Directory Structure
238
+
239
+ ```text
240
+ self-healing-elements/
241
+ ├── docs/ # Architecture, roadmap, problem statements
242
+ ├── src/self_healing/ # Package source code
243
+ │ └── __init__.py
244
+ ├── tests/ # Automated test suites
245
+ ├── .gitignore # Git exclusion rules
246
+ ├── README.md # Project overview
247
+ └── requirements.txt # Project dependencies
248
+ ```
249
+
250
+ ## Getting Started
251
+
252
+ 1. Activate your virtual environment:
253
+ ```powershell
254
+ .venv\Scripts\activate
255
+ ```
256
+ 2. Install dependencies:
257
+ ```powershell
258
+ pip install -r requirements.txt
259
+ ```
260
+ 3. Run tests:
261
+ ```powershell
262
+ pytest
263
+ ```
264
+
265
+ ## Docker / Compose
266
+
267
+ This repository includes a production-style Docker stack with a FastAPI API, background retraining worker, Nginx reverse proxy, and local Ollama service.
268
+
269
+ ### Production stack
270
+
271
+ ```bash
272
+ cp .env.example .env
273
+ make build
274
+ make up
275
+ ```
276
+
277
+ Then open the app through Nginx:
278
+
279
+ ```text
280
+ http://localhost/
281
+ ```
282
+
283
+ ### Local development override
284
+
285
+ ```bash
286
+ cp .env.example .env
287
+ docker compose -f docker-compose.yml -f docker-compose.override.yml up --build
288
+ ```
289
+
290
+ This runs the dev stack with the app surfaced on:
291
+
292
+ ```text
293
+ http://localhost:8000/
294
+ ```
295
+
296
+ ### Useful commands
297
+
298
+ ```bash
299
+ make logs
300
+ make test
301
+ make train
302
+ t docker compose down -v
303
+ ```
304
+
305
+ > Note: `make down` and `docker compose down -v` remove the named volumes, so use them carefully if you want to preserve registry or model state.
306
+
307
+ ### TLS certificate note for HTTPS
308
+
309
+ The HTTPS-enabled Nginx config expects a certificate pair in `./certs`:
310
+
311
+ ```bash
312
+ mkdir -p certs
313
+ openssl req -x509 -nodes -newkey rsa:2048 \
314
+ -keyout certs/server.key \
315
+ -out certs/server.crt \
316
+ -days 365 \
317
+ -subj "/CN=localhost"
318
+ ```
319
+
320
+ Then start the stack with the TLS config mounted by `docker-compose.override.yml`.
321
+
322
+ ---
323
+
324
+ ## Docker notes
325
+
326
+ - Named volumes persist the registry, healing event log, and trained model artifacts across restarts.
327
+ - The API reads/writes SQLite state from `/data/registry` and logs from `/data/logs`.
328
+ - The worker retrains from stored healing history and writes model artifacts to `/data/models`.
329
+ - The local LLM service is exposed internally at `http://ollama:11434` for explanation generation.
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "self-healing-elements"
7
+ version = "0.1.0"
8
+ description = "AI-powered self-healing Selenium locator engine"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ authors = [{ name = "LIKITH" }]
12
+ keywords = ["selenium", "self-healing", "test-automation", "ai", "ml"]
13
+ dependencies = [
14
+ "selenium",
15
+ "pytest",
16
+ "fastapi",
17
+ "uvicorn",
18
+ "pydantic",
19
+ "beautifulsoup4",
20
+ "httpx",
21
+ "xgboost",
22
+ "pandas",
23
+ "scikit-learn",
24
+ "litellm",
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/LIKITH/self-healing-elements"
29
+
30
+ [project.scripts]
31
+ self-healing = "self_healing.cli:main"
32
+
33
+ [tool.setuptools]
34
+ package-dir = {"" = "src"}
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["src"]
38
+
39
+ [tool.setuptools.package-data]
40
+ self_healing = ["py.typed"]