selenium-python-ai-agent 0.2.0__tar.gz → 0.2.2__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.
- {selenium_python_ai_agent-0.2.0/selenium_python_ai_agent.egg-info → selenium_python_ai_agent-0.2.2}/PKG-INFO +11 -5
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/README.md +10 -4
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/pyproject.toml +1 -1
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/__init__.py +1 -1
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/coder.py +64 -1
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/healer.py +20 -4
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/cli.py +32 -4
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/core/orchestrator.py +4 -2
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/scanner/project_scanner.py +32 -10
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/config_manager.py +1 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/llm.py +20 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2/selenium_python_ai_agent.egg-info}/PKG-INFO +11 -5
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/tests/test_agent_enhancements.py +87 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/tests/test_path_handling.py +1 -1
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/LICENSE +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/__init__.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/definitions.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/planner.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/bdd/__init__.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/bdd/gherkin_advisor.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/bdd/templates.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/core/__init__.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/scanner/__init__.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/selenium/__init__.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/selenium/base_page.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/selenium/driver_factory.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/selenium/error_map.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/selenium/locator_advisor.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/selenium/locator_scanner.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/__init__.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/code_validator.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/json_utils.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/logger.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/paths.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/spec_writer.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/url_extractor.py +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_python_ai_agent.egg-info/SOURCES.txt +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_python_ai_agent.egg-info/dependency_links.txt +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_python_ai_agent.egg-info/entry_points.txt +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_python_ai_agent.egg-info/requires.txt +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_python_ai_agent.egg-info/top_level.txt +0 -0
- {selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: selenium-python-ai-agent
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: AI-powered multi-agent framework to plan, generate and heal Selenium Python tests (pytest + pytest-bdd)
|
|
5
5
|
Author: Ankit Tripathi
|
|
6
6
|
License: MIT
|
|
@@ -135,11 +135,17 @@ selenium-agent --heal-only generated_tests/tests/test_checkout.py
|
|
|
135
135
|
Most teams don't start from scratch — they already have a Selenium project. Point the agent at it with `--project` and it **adapts to your structure instead of imposing its own**:
|
|
136
136
|
|
|
137
137
|
```bash
|
|
138
|
-
# First, see what the scanner detects about your project (read-only)
|
|
138
|
+
# First, see what the scanner detects about your project (read-only).
|
|
139
|
+
# The path is SAVED to config — you never need to repeat it.
|
|
139
140
|
selenium-agent --scan /path/to/your/project
|
|
140
141
|
|
|
141
|
-
#
|
|
142
|
-
selenium-agent "test the invoice creation flow"
|
|
142
|
+
# From now on every run fits into it automatically:
|
|
143
|
+
selenium-agent "test the invoice creation flow"
|
|
144
|
+
selenium-agent "test the user permissions page"
|
|
145
|
+
|
|
146
|
+
# Manage the saved project:
|
|
147
|
+
selenium-agent config --project /other/project # switch
|
|
148
|
+
selenium-agent config --project none # clear
|
|
143
149
|
```
|
|
144
150
|
|
|
145
151
|
The built-in **ProjectScanner** detects and follows:
|
|
@@ -359,7 +365,7 @@ generated_tests/
|
|
|
359
365
|
| `--headless` | Headless browser | from config (`false`) |
|
|
360
366
|
| `--explore N` | Explore up to N extra same-origin pages while planning (relevance-ranked, multi-hop) | `0` |
|
|
361
367
|
| `--output-dir` | Where to save generated files | `generated_tests` |
|
|
362
|
-
| `--project` |
|
|
368
|
+
| `--project` | Existing project path (saved to config — set once) | from config |
|
|
363
369
|
| `--max-retries` | Healer fix attempts | `5` |
|
|
364
370
|
| `--no-heal` | Skip healing after codegen | `false` |
|
|
365
371
|
| `--plan-only` | Save + show plan, no code | `false` |
|
|
@@ -105,11 +105,17 @@ selenium-agent --heal-only generated_tests/tests/test_checkout.py
|
|
|
105
105
|
Most teams don't start from scratch — they already have a Selenium project. Point the agent at it with `--project` and it **adapts to your structure instead of imposing its own**:
|
|
106
106
|
|
|
107
107
|
```bash
|
|
108
|
-
# First, see what the scanner detects about your project (read-only)
|
|
108
|
+
# First, see what the scanner detects about your project (read-only).
|
|
109
|
+
# The path is SAVED to config — you never need to repeat it.
|
|
109
110
|
selenium-agent --scan /path/to/your/project
|
|
110
111
|
|
|
111
|
-
#
|
|
112
|
-
selenium-agent "test the invoice creation flow"
|
|
112
|
+
# From now on every run fits into it automatically:
|
|
113
|
+
selenium-agent "test the invoice creation flow"
|
|
114
|
+
selenium-agent "test the user permissions page"
|
|
115
|
+
|
|
116
|
+
# Manage the saved project:
|
|
117
|
+
selenium-agent config --project /other/project # switch
|
|
118
|
+
selenium-agent config --project none # clear
|
|
113
119
|
```
|
|
114
120
|
|
|
115
121
|
The built-in **ProjectScanner** detects and follows:
|
|
@@ -329,7 +335,7 @@ generated_tests/
|
|
|
329
335
|
| `--headless` | Headless browser | from config (`false`) |
|
|
330
336
|
| `--explore N` | Explore up to N extra same-origin pages while planning (relevance-ranked, multi-hop) | `0` |
|
|
331
337
|
| `--output-dir` | Where to save generated files | `generated_tests` |
|
|
332
|
-
| `--project` |
|
|
338
|
+
| `--project` | Existing project path (saved to config — set once) | from config |
|
|
333
339
|
| `--max-retries` | Healer fix attempts | `5` |
|
|
334
340
|
| `--no-heal` | Skip healing after codegen | `false` |
|
|
335
341
|
| `--plan-only` | Save + show plan, no code | `false` |
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "selenium-python-ai-agent"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.2"
|
|
8
8
|
description = "AI-powered multi-agent framework to plan, generate and heal Selenium Python tests (pytest + pytest-bdd)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/coder.py
RENAMED
|
@@ -245,6 +245,51 @@ Output valid JSON only, no markdown:
|
|
|
245
245
|
]}}
|
|
246
246
|
"""
|
|
247
247
|
|
|
248
|
+
PROJECT_NATIVE_SYSTEM_PROMPT = """
|
|
249
|
+
You are an expert Selenium Python engineer extending an EXISTING test
|
|
250
|
+
framework. The project profile below — especially its sample code — is the
|
|
251
|
+
ONLY architecture reference. You are a guest in this codebase: mirror its
|
|
252
|
+
patterns exactly, never import your own.
|
|
253
|
+
|
|
254
|
+
{project_context}
|
|
255
|
+
|
|
256
|
+
══ HARD RULES ══
|
|
257
|
+
|
|
258
|
+
1. FILE LOCATIONS — write ONLY into the project's own folders:
|
|
259
|
+
page objects → {pages_dir}/
|
|
260
|
+
test files → {tests_dir}/
|
|
261
|
+
FORBIDDEN: creating new top-level folders (generated_tests/, output/, ...).
|
|
262
|
+
|
|
263
|
+
2. ARCHITECTURE — copy the sample page object's style exactly: same base
|
|
264
|
+
class (or none), same helper/service/logger imports, same constructor
|
|
265
|
+
signature, same method style. Do NOT import selenium_agent modules
|
|
266
|
+
unless the samples themselves do.
|
|
267
|
+
|
|
268
|
+
3. DRIVER — the project's conftest.py already provides the fixture named
|
|
269
|
+
'{fixture_name}'. Test functions accept it as a parameter:
|
|
270
|
+
def test_something({fixture_name}):
|
|
271
|
+
NEVER define fixtures, NEVER create drivers, NEVER assume the fixture
|
|
272
|
+
is called 'driver' if the project calls it something else.
|
|
273
|
+
|
|
274
|
+
4. IMPORTS — follow the project's import style shown in the samples
|
|
275
|
+
(e.g. 'from pages.login_page import LoginPage').
|
|
276
|
+
|
|
277
|
+
══ QUALITY RULES (always apply) ══
|
|
278
|
+
- Use ONLY locators from the plan / DOM scan — never invent
|
|
279
|
+
- Unique runtime test data for entity-creating flows:
|
|
280
|
+
import uuid; unique = uuid.uuid4().hex[:8]
|
|
281
|
+
email = "qa." + unique + "@example.com"; password = "Xk9#" + unique + "!Qz"
|
|
282
|
+
- Fill EVERY form field the scan shows, not just the ones named
|
|
283
|
+
- Assert POST-action outcomes (what changes/appears), never pre-action text
|
|
284
|
+
- No time.sleep(), no pytest.skip() placeholders, no TODO steps
|
|
285
|
+
|
|
286
|
+
Output valid JSON only, no markdown:
|
|
287
|
+
{{"files": [
|
|
288
|
+
{{"filename": "{pages_dir}/<name>_page.py", "content": "..."}},
|
|
289
|
+
{{"filename": "{tests_dir}/test_<name>.py", "content": "..."}}
|
|
290
|
+
]}}
|
|
291
|
+
"""
|
|
292
|
+
|
|
248
293
|
REPAIR_PROMPT = """
|
|
249
294
|
The code you generated has validation errors. Fix them and return the
|
|
250
295
|
COMPLETE corrected set of files in the same JSON format.
|
|
@@ -270,7 +315,7 @@ class CoderAgent:
|
|
|
270
315
|
mode = plan.get("mode", "pytest")
|
|
271
316
|
logger.info(f"💻 Generating [{mode.upper()}] code (headless={plan.get('headless', False)})...")
|
|
272
317
|
|
|
273
|
-
system_prompt =
|
|
318
|
+
system_prompt = self._system_prompt_for(mode, project_profile)
|
|
274
319
|
user_prompt = self._build_user_prompt(plan, project_profile, mode)
|
|
275
320
|
max_tokens = self._token_budget(plan)
|
|
276
321
|
|
|
@@ -375,6 +420,24 @@ class CoderAgent:
|
|
|
375
420
|
|
|
376
421
|
# ── Prompt building ────────────────────────────────────────────────
|
|
377
422
|
|
|
423
|
+
@staticmethod
|
|
424
|
+
def _system_prompt_for(mode: str, project_profile=None) -> str:
|
|
425
|
+
"""
|
|
426
|
+
Standalone mode teaches the framework's own BasePage architecture.
|
|
427
|
+
Project mode REPLACES that entirely: the user's existing framework
|
|
428
|
+
(its samples, folders, fixture name) is the only reference —
|
|
429
|
+
supplementing a strong default architecture with a small 'fit in'
|
|
430
|
+
note demonstrably loses to the baked-in style.
|
|
431
|
+
"""
|
|
432
|
+
if project_profile is not None and mode != "bdd":
|
|
433
|
+
return PROJECT_NATIVE_SYSTEM_PROMPT.format(
|
|
434
|
+
project_context=project_profile.to_llm_context(),
|
|
435
|
+
pages_dir=project_profile.pages_dir.rstrip("/"),
|
|
436
|
+
tests_dir=project_profile.tests_dir.rstrip("/"),
|
|
437
|
+
fixture_name=project_profile.driver_fixture_name,
|
|
438
|
+
)
|
|
439
|
+
return CODER_SYSTEM_PROMPT_BDD if mode == "bdd" else CODER_SYSTEM_PROMPT_PYTEST
|
|
440
|
+
|
|
378
441
|
def _build_user_prompt(self, plan: dict, project_profile, mode: str) -> str:
|
|
379
442
|
project_context = ""
|
|
380
443
|
if project_profile:
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/healer.py
RENAMED
|
@@ -483,7 +483,8 @@ class HealerAgent:
|
|
|
483
483
|
|
|
484
484
|
# ── Main heal loop ─────────────────────────────────────────────────
|
|
485
485
|
|
|
486
|
-
def heal(self, saved_files: list[str], test_filter: str | None = None
|
|
486
|
+
def heal(self, saved_files: list[str], test_filter: str | None = None,
|
|
487
|
+
project_profile=None) -> dict:
|
|
487
488
|
resolved = self._resolve_paths(saved_files)
|
|
488
489
|
|
|
489
490
|
extra = self._auto_discover_related_files(resolved)
|
|
@@ -519,7 +520,8 @@ class HealerAgent:
|
|
|
519
520
|
|
|
520
521
|
logger.warning(f"❌ Failed on attempt {attempt}")
|
|
521
522
|
try:
|
|
522
|
-
applied = self._fix_once(resolved, output, test_filter, scan_cache
|
|
523
|
+
applied = self._fix_once(resolved, output, test_filter, scan_cache,
|
|
524
|
+
project_profile=project_profile)
|
|
523
525
|
except LLMJSONError as exc:
|
|
524
526
|
logger.error(f"💥 Healer LLM returned unusable JSON: {exc}")
|
|
525
527
|
applied = False
|
|
@@ -537,7 +539,8 @@ class HealerAgent:
|
|
|
537
539
|
return {"status": "failed", "attempts": self.max_retries, "output": output}
|
|
538
540
|
|
|
539
541
|
def _fix_once(self, resolved: dict[str, Path], output: str,
|
|
540
|
-
test_filter: str | None, scan_cache: dict[str, str]
|
|
542
|
+
test_filter: str | None, scan_cache: dict[str, str],
|
|
543
|
+
project_profile=None) -> bool:
|
|
541
544
|
"""One LLM fix round. Returns True if at least one file was updated."""
|
|
542
545
|
known_fix = SeleniumErrorMap.get_fix_summary(output)
|
|
543
546
|
|
|
@@ -582,6 +585,18 @@ class HealerAgent:
|
|
|
582
585
|
system_prompt = HEALER_SYSTEM_PROMPT
|
|
583
586
|
target_instruction = ""
|
|
584
587
|
|
|
588
|
+
project_instruction = ""
|
|
589
|
+
if project_profile is not None:
|
|
590
|
+
project_instruction = (
|
|
591
|
+
f"\n\n🏗️ EXISTING-PROJECT MODE — this codebase has its OWN "
|
|
592
|
+
f"architecture. The profile below OVERRIDES the default "
|
|
593
|
+
f"architecture/import rules above: mirror the project's "
|
|
594
|
+
f"patterns exactly, never convert files to the "
|
|
595
|
+
f"selenium_agent BasePage style, and tests use the fixture "
|
|
596
|
+
f"named '{project_profile.driver_fixture_name}'.\n\n"
|
|
597
|
+
f"{project_profile.to_llm_context()}\n"
|
|
598
|
+
)
|
|
599
|
+
|
|
585
600
|
raw = self.client.generate_text(
|
|
586
601
|
system_prompt=system_prompt,
|
|
587
602
|
user_prompt=(
|
|
@@ -589,7 +604,8 @@ class HealerAgent:
|
|
|
589
604
|
f"SELENIUM ERROR ANALYSIS:\n{known_fix}\n\n"
|
|
590
605
|
f"{locator_context}\n"
|
|
591
606
|
f"PYTEST OUTPUT:\n{self._trim_output(output)}\n"
|
|
592
|
-
f"{target_instruction}
|
|
607
|
+
f"{target_instruction}"
|
|
608
|
+
f"{project_instruction}\n"
|
|
593
609
|
f"CURRENT CODE:\n{files_text}"
|
|
594
610
|
),
|
|
595
611
|
max_tokens=8000,
|
|
@@ -27,6 +27,8 @@ def _handle_config(argv):
|
|
|
27
27
|
p.add_argument("--headless", dest="headless", action="store_true", default=None)
|
|
28
28
|
p.add_argument("--no-headless", dest="headless", action="store_false", default=None)
|
|
29
29
|
p.add_argument("--mode", choices=["pytest", "bdd"])
|
|
30
|
+
p.add_argument("--project", help="Existing project to fit tests into "
|
|
31
|
+
"(use 'none' to clear)")
|
|
30
32
|
p.add_argument("--show", action="store_true", help="Print current config")
|
|
31
33
|
args = p.parse_args(argv)
|
|
32
34
|
|
|
@@ -35,6 +37,9 @@ def _handle_config(argv):
|
|
|
35
37
|
print(json.dumps(config_manager.load(), indent=2))
|
|
36
38
|
return
|
|
37
39
|
|
|
40
|
+
if args.project and args.project.lower() in ("none", "clear", "off"):
|
|
41
|
+
args.project = "" # empty string clears it (consumers treat "" as unset)
|
|
42
|
+
|
|
38
43
|
updates = {k: v for k, v in vars(args).items() if v is not None and k != "show"}
|
|
39
44
|
if not updates:
|
|
40
45
|
p.print_help()
|
|
@@ -115,8 +120,8 @@ def _handle_help():
|
|
|
115
120
|
--headless headless browser
|
|
116
121
|
--explore N scan N extra same-origin pages while planning
|
|
117
122
|
--output-dir where to save files (default: generated_tests)
|
|
118
|
-
--project path to
|
|
119
|
-
--max-retries healer retries (default:
|
|
123
|
+
--project existing project path (auto-saved to config)
|
|
124
|
+
--max-retries healer retries (default: 5)
|
|
120
125
|
--no-heal skip healing
|
|
121
126
|
--plan-only preview plan only (saved to specs/)
|
|
122
127
|
--from-plan generate from saved plan JSON
|
|
@@ -196,7 +201,7 @@ Other examples:
|
|
|
196
201
|
parser.add_argument("--test", default=None, metavar="TEST_NAME",
|
|
197
202
|
help="Specific test function to run/heal. "
|
|
198
203
|
"e.g. --test test_login_locked_out_user")
|
|
199
|
-
parser.add_argument("--version", action="version", version="selenium-agent 0.2.
|
|
204
|
+
parser.add_argument("--version", action="version", version="selenium-agent 0.2.2")
|
|
200
205
|
|
|
201
206
|
args = parser.parse_args()
|
|
202
207
|
|
|
@@ -210,6 +215,11 @@ Other examples:
|
|
|
210
215
|
except Exception as e:
|
|
211
216
|
print(f"❌ Scan failed: {e}")
|
|
212
217
|
sys.exit(1)
|
|
218
|
+
# Remember the project — future runs fit into it automatically,
|
|
219
|
+
# no need to repeat --project every time.
|
|
220
|
+
config_manager.save({"project": args.scan})
|
|
221
|
+
print(f"\n💾 Project saved to config — future runs will fit into it.")
|
|
222
|
+
print(f" (change: selenium-agent config --project <path> | clear: --project none)")
|
|
213
223
|
sys.exit(0)
|
|
214
224
|
|
|
215
225
|
# ── Merge config + CLI args ───────────────────────────────────────
|
|
@@ -220,6 +230,16 @@ Other examples:
|
|
|
220
230
|
"mode": args.mode,
|
|
221
231
|
})
|
|
222
232
|
|
|
233
|
+
# `--model gpt-5` without `--provider` must not hit the default
|
|
234
|
+
# (Anthropic) API — the model name itself tells us the provider.
|
|
235
|
+
# An explicit --provider flag always wins.
|
|
236
|
+
if args.provider is None and cfg.get("model"):
|
|
237
|
+
from selenium_agent.utils.llm import infer_provider_for_model
|
|
238
|
+
inferred = infer_provider_for_model(cfg["model"])
|
|
239
|
+
if inferred and inferred != cfg.get("provider"):
|
|
240
|
+
logger.info(f"🧭 Model '{cfg['model']}' implies provider '{inferred}'")
|
|
241
|
+
cfg["provider"] = inferred
|
|
242
|
+
|
|
223
243
|
# URL priority: --url flag > extracted from instruction > saved base_url
|
|
224
244
|
from selenium_agent.utils.url_extractor import extract_url
|
|
225
245
|
override_url = args.url
|
|
@@ -235,6 +255,14 @@ Other examples:
|
|
|
235
255
|
config_manager.save({"base_url": args.url})
|
|
236
256
|
logger.info(f"💾 base_url saved: {args.url}")
|
|
237
257
|
|
|
258
|
+
# Project priority: --project flag > saved config. Persist like --url.
|
|
259
|
+
project_root = args.project or (cfg.get("project") or None)
|
|
260
|
+
if args.project and args.project != cfg.get("project"):
|
|
261
|
+
config_manager.save({"project": args.project})
|
|
262
|
+
logger.info(f"💾 project saved: {args.project}")
|
|
263
|
+
elif not args.project and project_root:
|
|
264
|
+
logger.info(f"🏗️ Using saved project: {project_root}")
|
|
265
|
+
|
|
238
266
|
# ── Build orchestrator ────────────────────────────────────────────
|
|
239
267
|
try:
|
|
240
268
|
agent = Orchestrator(
|
|
@@ -245,7 +273,7 @@ Other examples:
|
|
|
245
273
|
max_heal_retries=args.max_retries or 5,
|
|
246
274
|
auto_heal=not args.no_heal,
|
|
247
275
|
mode=cfg["mode"],
|
|
248
|
-
project_root=
|
|
276
|
+
project_root=project_root,
|
|
249
277
|
headless=cfg["headless"],
|
|
250
278
|
explore_pages=args.explore,
|
|
251
279
|
)
|
|
@@ -148,7 +148,8 @@ class Orchestrator:
|
|
|
148
148
|
return self.coder.code(plan, project_profile=self.project_profile)
|
|
149
149
|
|
|
150
150
|
def heal_only(self, file_paths: list, test_filter: str | None = None) -> dict:
|
|
151
|
-
return self.healer.heal(file_paths, test_filter=test_filter
|
|
151
|
+
return self.healer.heal(file_paths, test_filter=test_filter,
|
|
152
|
+
project_profile=self.project_profile)
|
|
152
153
|
|
|
153
154
|
def scan_only(self, project_root: str) -> str:
|
|
154
155
|
from selenium_agent.scanner.project_scanner import ProjectScanner
|
|
@@ -183,7 +184,8 @@ class Orchestrator:
|
|
|
183
184
|
heal_result = None
|
|
184
185
|
if self.auto_heal:
|
|
185
186
|
logger.info("\n🩺 STEP 3: HEALER")
|
|
186
|
-
heal_result = self.healer.heal(saved_files
|
|
187
|
+
heal_result = self.healer.heal(saved_files,
|
|
188
|
+
project_profile=self.project_profile)
|
|
187
189
|
else:
|
|
188
190
|
logger.info("\n⏭️ Auto-heal skipped")
|
|
189
191
|
return saved_files, heal_result
|
|
@@ -54,6 +54,7 @@ class ProjectProfile:
|
|
|
54
54
|
# Driver setup
|
|
55
55
|
driver_setup: str = "fixture" # fixture | setUp | class-level
|
|
56
56
|
driver_scope: str = "function" # function | class | module
|
|
57
|
+
driver_fixture_name: str = "driver" # actual fixture name (e.g. 'browser')
|
|
57
58
|
browser: str = "chrome"
|
|
58
59
|
headless: bool = False
|
|
59
60
|
|
|
@@ -91,7 +92,8 @@ class ProjectProfile:
|
|
|
91
92
|
f"BDD detected : {self.has_bdd}",
|
|
92
93
|
f"Base Page class : {self.base_page_class}",
|
|
93
94
|
f"Base Page import : {self.base_page_import or 'not detected'}",
|
|
94
|
-
f"Driver setup : {self.driver_setup} (scope={self.driver_scope}
|
|
95
|
+
f"Driver setup : {self.driver_setup} (scope={self.driver_scope}, "
|
|
96
|
+
f"fixture name='{self.driver_fixture_name}')",
|
|
95
97
|
f"Browser : {self.browser} (headless={self.headless})",
|
|
96
98
|
f"Test file pattern : {self.test_file_prefix}<name>.py",
|
|
97
99
|
f"Page file pattern : <name>{self.page_file_suffix}.py",
|
|
@@ -169,12 +171,18 @@ class ProjectScanner:
|
|
|
169
171
|
# ── Detection methods ─────────────────────────────────────────────
|
|
170
172
|
|
|
171
173
|
def _detect_folders(self):
|
|
172
|
-
"""Find pages, tests, features, steps directories.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
"""Find pages, tests, features, steps directories.
|
|
175
|
+
|
|
176
|
+
Shallowest directory wins: a project's real `pages/` at the root
|
|
177
|
+
must beat any deeper `something/pages/` twin."""
|
|
178
|
+
all_dirs = sorted(
|
|
179
|
+
(d for d in self.root.rglob("*")
|
|
180
|
+
if d.is_dir() and not self._is_ignored(d)),
|
|
181
|
+
key=lambda d: len(d.parts),
|
|
182
|
+
)
|
|
183
|
+
dir_names: dict = {}
|
|
184
|
+
for d in all_dirs:
|
|
185
|
+
dir_names.setdefault(d.name.lower(), d)
|
|
178
186
|
|
|
179
187
|
for name in self.PAGES_DIRS:
|
|
180
188
|
if name in dir_names:
|
|
@@ -301,11 +309,19 @@ class ProjectScanner:
|
|
|
301
309
|
continue
|
|
302
310
|
|
|
303
311
|
# Fixture pattern
|
|
304
|
-
if "@pytest.fixture" in content and "driver" in content:
|
|
312
|
+
if "@pytest.fixture" in content and "driver" in content.lower():
|
|
305
313
|
self.profile.driver_setup = "fixture"
|
|
306
314
|
scope_match = re.search(r'@pytest\.fixture\s*\(\s*scope=["\'](\w+)["\']', content)
|
|
307
315
|
if scope_match:
|
|
308
316
|
self.profile.driver_scope = scope_match.group(1)
|
|
317
|
+
# The fixture NAME matters — generated tests must request the
|
|
318
|
+
# project's actual fixture ('browser', 'web_driver', ...),
|
|
319
|
+
# not assume it is called 'driver'.
|
|
320
|
+
name_match = re.search(
|
|
321
|
+
r"@pytest\.fixture(?:\([^)]*\))?\s*\ndef\s+(\w+)\s*\(", content
|
|
322
|
+
)
|
|
323
|
+
if name_match and f.name == "conftest.py":
|
|
324
|
+
self.profile.driver_fixture_name = name_match.group(1)
|
|
309
325
|
|
|
310
326
|
# unittest setUp pattern
|
|
311
327
|
elif "def setUp(self)" in content:
|
|
@@ -445,8 +461,14 @@ class ProjectScanner:
|
|
|
445
461
|
continue
|
|
446
462
|
|
|
447
463
|
def _is_ignored(self, path: Path) -> bool:
|
|
448
|
-
"""Skip venv, cache, git, node_modules etc.
|
|
464
|
+
"""Skip venv, cache, git, node_modules etc.
|
|
465
|
+
|
|
466
|
+
Also skips the agent's OWN output folders (generated_tests/, specs/):
|
|
467
|
+
scanning them would make the profile describe the agent's previous
|
|
468
|
+
output instead of the user's real framework — circular pollution.
|
|
469
|
+
"""
|
|
449
470
|
ignored = {".venv", "venv", "__pycache__", ".git", ".idea",
|
|
450
471
|
"node_modules", ".pytest_cache", "dist", "build",
|
|
451
|
-
".eggs", "*.egg-info", ".tox", ".mypy_cache"
|
|
472
|
+
".eggs", "*.egg-info", ".tox", ".mypy_cache",
|
|
473
|
+
"generated_tests", "specs"}
|
|
452
474
|
return any(part in ignored for part in path.parts)
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/llm.py
RENAMED
|
@@ -37,6 +37,26 @@ _NON_RETRYABLE = (
|
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
def infer_provider_for_model(model: str | None) -> str | None:
|
|
41
|
+
"""
|
|
42
|
+
Infer the provider from a model name — 'gpt-5' implies OpenAI,
|
|
43
|
+
'claude-fable-5' implies Anthropic.
|
|
44
|
+
|
|
45
|
+
Fresh installs have no saved config, so `--model gpt-5` without
|
|
46
|
+
`--provider openai` would otherwise send an OpenAI model to the
|
|
47
|
+
default (Anthropic) API and fail with a confusing auth/model error.
|
|
48
|
+
Returns None when the name matches no known family.
|
|
49
|
+
"""
|
|
50
|
+
if not model:
|
|
51
|
+
return None
|
|
52
|
+
m = model.strip().lower()
|
|
53
|
+
if m.startswith(("gpt-", "o1", "o3", "o4", "chatgpt")):
|
|
54
|
+
return "openai"
|
|
55
|
+
if m.startswith("claude"):
|
|
56
|
+
return "anthropic"
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
|
|
40
60
|
def normalize_provider(provider: str | None) -> str:
|
|
41
61
|
normalized = (provider or DEFAULT_PROVIDER).strip().lower()
|
|
42
62
|
if normalized not in API_KEY_ENV_VARS:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: selenium-python-ai-agent
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: AI-powered multi-agent framework to plan, generate and heal Selenium Python tests (pytest + pytest-bdd)
|
|
5
5
|
Author: Ankit Tripathi
|
|
6
6
|
License: MIT
|
|
@@ -135,11 +135,17 @@ selenium-agent --heal-only generated_tests/tests/test_checkout.py
|
|
|
135
135
|
Most teams don't start from scratch — they already have a Selenium project. Point the agent at it with `--project` and it **adapts to your structure instead of imposing its own**:
|
|
136
136
|
|
|
137
137
|
```bash
|
|
138
|
-
# First, see what the scanner detects about your project (read-only)
|
|
138
|
+
# First, see what the scanner detects about your project (read-only).
|
|
139
|
+
# The path is SAVED to config — you never need to repeat it.
|
|
139
140
|
selenium-agent --scan /path/to/your/project
|
|
140
141
|
|
|
141
|
-
#
|
|
142
|
-
selenium-agent "test the invoice creation flow"
|
|
142
|
+
# From now on every run fits into it automatically:
|
|
143
|
+
selenium-agent "test the invoice creation flow"
|
|
144
|
+
selenium-agent "test the user permissions page"
|
|
145
|
+
|
|
146
|
+
# Manage the saved project:
|
|
147
|
+
selenium-agent config --project /other/project # switch
|
|
148
|
+
selenium-agent config --project none # clear
|
|
143
149
|
```
|
|
144
150
|
|
|
145
151
|
The built-in **ProjectScanner** detects and follows:
|
|
@@ -359,7 +365,7 @@ generated_tests/
|
|
|
359
365
|
| `--headless` | Headless browser | from config (`false`) |
|
|
360
366
|
| `--explore N` | Explore up to N extra same-origin pages while planning (relevance-ranked, multi-hop) | `0` |
|
|
361
367
|
| `--output-dir` | Where to save generated files | `generated_tests` |
|
|
362
|
-
| `--project` |
|
|
368
|
+
| `--project` | Existing project path (saved to config — set once) | from config |
|
|
363
369
|
| `--max-retries` | Healer fix attempts | `5` |
|
|
364
370
|
| `--no-heal` | Skip healing after codegen | `false` |
|
|
365
371
|
| `--plan-only` | Save + show plan, no code | `false` |
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/tests/test_agent_enhancements.py
RENAMED
|
@@ -333,3 +333,90 @@ def test_token_budget_uses_structure_not_keywords():
|
|
|
333
333
|
"locators": [],
|
|
334
334
|
}
|
|
335
335
|
assert coder._token_budget(big) == 12000
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def test_infer_provider_from_model_name():
|
|
339
|
+
from selenium_agent.utils.llm import infer_provider_for_model
|
|
340
|
+
|
|
341
|
+
assert infer_provider_for_model("gpt-5") == "openai"
|
|
342
|
+
assert infer_provider_for_model("gpt-4o-mini") == "openai"
|
|
343
|
+
assert infer_provider_for_model("o3-mini") == "openai"
|
|
344
|
+
assert infer_provider_for_model("claude-fable-5") == "anthropic"
|
|
345
|
+
assert infer_provider_for_model("claude-sonnet-5") == "anthropic"
|
|
346
|
+
assert infer_provider_for_model("some-unknown-model") is None
|
|
347
|
+
assert infer_provider_for_model(None) is None
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def test_config_persists_project(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
|
351
|
+
from selenium_agent.utils import config_manager
|
|
352
|
+
|
|
353
|
+
monkeypatch.chdir(tmp_path)
|
|
354
|
+
config_manager.save({"project": "/path/to/my/framework"})
|
|
355
|
+
cfg = config_manager.load()
|
|
356
|
+
assert cfg["project"] == "/path/to/my/framework"
|
|
357
|
+
|
|
358
|
+
# Clearing: empty string is treated as unset by consumers
|
|
359
|
+
config_manager.save({"project": ""})
|
|
360
|
+
assert (config_manager.load()["project"] or None) is None
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
# ── project-native mode ────────────────────────────────────────────────
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def _make_fake_project(tmp_path: Path):
|
|
367
|
+
(tmp_path / "pages").mkdir()
|
|
368
|
+
(tmp_path / "tests").mkdir()
|
|
369
|
+
(tmp_path / "generated_tests" / "pages").mkdir(parents=True)
|
|
370
|
+
(tmp_path / "pages" / "home_page.py").write_text(
|
|
371
|
+
"from utils.helpers import HelperBot\n\nclass HomePage:\n def __init__(self, driver):\n self.bot = HelperBot(driver)\n"
|
|
372
|
+
)
|
|
373
|
+
(tmp_path / "generated_tests" / "pages" / "old_page.py").write_text(
|
|
374
|
+
"from selenium_agent.selenium.base_page import BasePage\nclass OldPage(BasePage):\n pass\n"
|
|
375
|
+
)
|
|
376
|
+
(tmp_path / "tests" / "conftest.py").write_text(
|
|
377
|
+
"import pytest\nfrom selenium import webdriver\n\n"
|
|
378
|
+
"@pytest.fixture(scope=\"session\")\ndef browser():\n"
|
|
379
|
+
" d = webdriver.Chrome()\n yield d\n d.quit()\n"
|
|
380
|
+
)
|
|
381
|
+
(tmp_path / "tests" / "test_home.py").write_text(
|
|
382
|
+
"def test_home(browser):\n assert browser\n"
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def test_scanner_ignores_own_output_and_prefers_shallow_dirs(tmp_path: Path):
|
|
387
|
+
from selenium_agent.scanner.project_scanner import ProjectScanner
|
|
388
|
+
|
|
389
|
+
_make_fake_project(tmp_path)
|
|
390
|
+
profile = ProjectScanner(str(tmp_path)).scan()
|
|
391
|
+
|
|
392
|
+
assert profile.pages_dir == "pages" # not generated_tests/pages
|
|
393
|
+
assert "selenium_agent" not in profile.sample_page_code # own output excluded
|
|
394
|
+
assert "HelperBot" in profile.sample_page_code # the REAL project style
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def test_scanner_detects_fixture_name(tmp_path: Path):
|
|
398
|
+
from selenium_agent.scanner.project_scanner import ProjectScanner
|
|
399
|
+
|
|
400
|
+
_make_fake_project(tmp_path)
|
|
401
|
+
profile = ProjectScanner(str(tmp_path)).scan()
|
|
402
|
+
|
|
403
|
+
assert profile.driver_fixture_name == "browser"
|
|
404
|
+
assert "fixture name='browser'" in profile.to_llm_context()
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def test_project_native_prompt_replaces_default_architecture(tmp_path: Path):
|
|
408
|
+
from selenium_agent.agents.coder import CoderAgent
|
|
409
|
+
from selenium_agent.scanner.project_scanner import ProjectScanner
|
|
410
|
+
|
|
411
|
+
_make_fake_project(tmp_path)
|
|
412
|
+
profile = ProjectScanner(str(tmp_path)).scan()
|
|
413
|
+
prompt = CoderAgent._system_prompt_for("pytest", profile)
|
|
414
|
+
|
|
415
|
+
assert "def test_something(browser):" in prompt
|
|
416
|
+
assert "generated_tests/" in prompt # named as FORBIDDEN
|
|
417
|
+
assert "HelperBot" in prompt # project's sample code included
|
|
418
|
+
assert "selenium_agent.selenium.base_page" not in prompt # our BasePage gone
|
|
419
|
+
|
|
420
|
+
# Standalone mode is unchanged
|
|
421
|
+
standalone = CoderAgent._system_prompt_for("pytest", None)
|
|
422
|
+
assert "selenium_agent.selenium.base_page" in standalone
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/tests/test_path_handling.py
RENAMED
|
@@ -25,7 +25,7 @@ def make_healer(output_dir: Path) -> HealerAgent:
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def test_package_import_exposes_public_api():
|
|
28
|
-
assert selenium_agent.__version__ == "0.2.
|
|
28
|
+
assert selenium_agent.__version__ == "0.2.2"
|
|
29
29
|
assert selenium_agent.SeleniumAgent.__name__ == "Orchestrator"
|
|
30
30
|
|
|
31
31
|
|
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/agents/planner.py
RENAMED
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/bdd/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/bdd/templates.py
RENAMED
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/core/__init__.py
RENAMED
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/scanner/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/json_utils.py
RENAMED
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/logger.py
RENAMED
|
File without changes
|
{selenium_python_ai_agent-0.2.0 → selenium_python_ai_agent-0.2.2}/selenium_agent/utils/paths.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|