selenium-python-ai-agent 0.2.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.
- selenium_python_ai_agent-0.2.0/LICENSE +21 -0
- selenium_python_ai_agent-0.2.0/PKG-INFO +412 -0
- selenium_python_ai_agent-0.2.0/README.md +382 -0
- selenium_python_ai_agent-0.2.0/pyproject.toml +44 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/__init__.py +20 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/agents/__init__.py +5 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/agents/coder.py +505 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/agents/definitions.py +152 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/agents/healer.py +638 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/agents/planner.py +279 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/bdd/__init__.py +15 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/bdd/gherkin_advisor.py +189 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/bdd/templates.py +98 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/cli.py +314 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/core/__init__.py +3 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/core/orchestrator.py +189 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/scanner/__init__.py +3 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/scanner/project_scanner.py +452 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/selenium/__init__.py +6 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/selenium/base_page.py +447 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/selenium/driver_factory.py +222 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/selenium/error_map.py +235 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/selenium/locator_advisor.py +247 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/selenium/locator_scanner.py +502 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/__init__.py +26 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/code_validator.py +96 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/config_manager.py +81 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/json_utils.py +103 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/llm.py +240 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/logger.py +37 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/paths.py +57 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/spec_writer.py +126 -0
- selenium_python_ai_agent-0.2.0/selenium_agent/utils/url_extractor.py +52 -0
- selenium_python_ai_agent-0.2.0/selenium_python_ai_agent.egg-info/PKG-INFO +412 -0
- selenium_python_ai_agent-0.2.0/selenium_python_ai_agent.egg-info/SOURCES.txt +40 -0
- selenium_python_ai_agent-0.2.0/selenium_python_ai_agent.egg-info/dependency_links.txt +1 -0
- selenium_python_ai_agent-0.2.0/selenium_python_ai_agent.egg-info/entry_points.txt +2 -0
- selenium_python_ai_agent-0.2.0/selenium_python_ai_agent.egg-info/requires.txt +6 -0
- selenium_python_ai_agent-0.2.0/selenium_python_ai_agent.egg-info/top_level.txt +1 -0
- selenium_python_ai_agent-0.2.0/setup.cfg +4 -0
- selenium_python_ai_agent-0.2.0/tests/test_agent_enhancements.py +335 -0
- selenium_python_ai_agent-0.2.0/tests/test_path_handling.py +128 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ankit Tripathi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: selenium-python-ai-agent
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: AI-powered multi-agent framework to plan, generate and heal Selenium Python tests (pytest + pytest-bdd)
|
|
5
|
+
Author: Ankit Tripathi
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AnkitDeepBlue/selenium-python-ai-agent
|
|
8
|
+
Project-URL: Repository, https://github.com/AnkitDeepBlue/selenium-python-ai-agent
|
|
9
|
+
Project-URL: Issues, https://github.com/AnkitDeepBlue/selenium-python-ai-agent/issues
|
|
10
|
+
Keywords: selenium,testing,ai,agent,automation,qa,claude,openai,bdd,pytest-bdd,gherkin
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Testing
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: anthropic>=0.25.0
|
|
24
|
+
Requires-Dist: openai>=1.30.0
|
|
25
|
+
Requires-Dist: selenium>=4.0.0
|
|
26
|
+
Requires-Dist: pytest>=8.0.0
|
|
27
|
+
Requires-Dist: pytest-bdd>=7.0.0
|
|
28
|
+
Requires-Dist: webdriver-manager>=4.0.0
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# Selenium Python AI Agent 🤖
|
|
32
|
+
|
|
33
|
+
> AI-powered multi-agent framework that **plans**, **generates**, and **heals** Selenium Python tests automatically — working the way **Playwright's test agents** do, but for Selenium.
|
|
34
|
+
> Supports **Anthropic Claude** and **OpenAI ChatGPT** as LLM backends.
|
|
35
|
+
|
|
36
|
+
[](https://pypi.org/project/selenium-python-ai-agent/)
|
|
37
|
+
[](https://python.org)
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🧠 How It Works — 3 Agents
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Your Instruction
|
|
46
|
+
│
|
|
47
|
+
▼
|
|
48
|
+
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
|
49
|
+
│ PLANNER │─────▶│ GENERATOR │─────▶│ HEALER │
|
|
50
|
+
│ │ │ │ │ │
|
|
51
|
+
│ live DOM scan│ │ POM code from│ │ run → rescan │
|
|
52
|
+
│ (+ optional │ │ plan, self- │ │ live DOM → │
|
|
53
|
+
│ site explore)│ │ verified │ │ fix → verify │
|
|
54
|
+
│ → specs/*.md │ │ (syntax + │ │ (final fix │
|
|
55
|
+
│ specs/*.json │ architecture)│ │ always re-run)│
|
|
56
|
+
└──────────────┘ └──────────────┘ └──────────────┘
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Every agent uses real DOM locators** — a real browser is opened headlessly before planning and healing, so the LLM never guesses selectors.
|
|
60
|
+
|
|
61
|
+
**Plans are reviewable artifacts** — like Playwright's planner agent, the Planner saves a human-readable Markdown plan plus a machine-readable JSON plan to `specs/`. Review or edit the plan, then generate from it.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## ⚡ Quick Start
|
|
66
|
+
|
|
67
|
+
### 1. Install
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install selenium-python-ai-agent
|
|
71
|
+
pip install python-dotenv # recommended — load keys from .env
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 2. Set API Keys
|
|
75
|
+
|
|
76
|
+
Create a `.env` file in your project root (git-ignored automatically):
|
|
77
|
+
|
|
78
|
+
```env
|
|
79
|
+
OPENAI_API_KEY=sk-...
|
|
80
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. One-Time Config Setup
|
|
84
|
+
|
|
85
|
+
Works with **any OpenAI or Anthropic model** — pick the one that fits your budget and complexity:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# any of these (or any other model your API key can access):
|
|
89
|
+
selenium-agent config --provider openai --model gpt-4o-mini # fast & cheap
|
|
90
|
+
selenium-agent config --provider openai --model gpt-4o # strong all-rounder
|
|
91
|
+
selenium-agent config --provider openai --model gpt-5 # most intelligent (reasoning)
|
|
92
|
+
selenium-agent config --provider anthropic --model claude-sonnet-5 # strong all-rounder
|
|
93
|
+
selenium-agent config --provider anthropic --model claude-fable-5 # most intelligent
|
|
94
|
+
|
|
95
|
+
selenium-agent config --base-url https://www.saucedemo.com # default URL for all runs
|
|
96
|
+
selenium-agent config --headless # (--no-headless to turn off)
|
|
97
|
+
selenium-agent config --show # verify saved config
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> 💡 For simple flows `gpt-4o-mini` / `claude-haiku-4-5` are fine; for **multi-page/complex flows** use `gpt-4o`, `gpt-5`, `claude-sonnet-5` or `claude-fable-5` — noticeably better plans and one-shot code.
|
|
101
|
+
|
|
102
|
+
### 4. Generate & Run Tests
|
|
103
|
+
|
|
104
|
+
Describe **any workflow on any web app** in plain English — the examples below are just examples.
|
|
105
|
+
|
|
106
|
+
**Two ways to give the target URL** — a one-off flag, or save it once in config:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Option A: pass the URL for this run (it is also saved to config for next time)
|
|
110
|
+
selenium-agent "add an item to cart and checkout as guest" --url https://your-app.com
|
|
111
|
+
|
|
112
|
+
# Option B: save it once, then never pass it again
|
|
113
|
+
selenium-agent config --base-url https://your-app.com
|
|
114
|
+
selenium-agent "test the login page" # uses saved base_url
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Full flow: plan → generate → heal (default)
|
|
119
|
+
selenium-agent "test the login page"
|
|
120
|
+
|
|
121
|
+
# Plan first, review, then generate (Playwright-agents workflow)
|
|
122
|
+
selenium-agent --plan-only "test the checkout flow"
|
|
123
|
+
# → specs/test-the-checkout-flow.md (read/edit this)
|
|
124
|
+
# → specs/test-the-checkout-flow.json
|
|
125
|
+
selenium-agent --from-plan specs/test-the-checkout-flow.json
|
|
126
|
+
|
|
127
|
+
# Something broke later (UI changed, locator died)? Heal it:
|
|
128
|
+
selenium-agent --heal-only generated_tests/tests/test_checkout.py
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 🏗️ Works Inside YOUR Existing Framework
|
|
134
|
+
|
|
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
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# First, see what the scanner detects about your project (read-only)
|
|
139
|
+
selenium-agent --scan /path/to/your/project
|
|
140
|
+
|
|
141
|
+
# Then generate tests that FIT INTO it
|
|
142
|
+
selenium-agent "test the invoice creation flow" --project /path/to/your/project
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The built-in **ProjectScanner** detects and follows:
|
|
146
|
+
|
|
147
|
+
| What it detects | Effect on generated code |
|
|
148
|
+
|---|---|
|
|
149
|
+
| Your folder layout (`pages/`, `page_objects/`, `tests/`, `e2e/`, …) | Files are written into **your** folders |
|
|
150
|
+
| Your base page class (`BasePage`, `PageBase`, `AbstractPage`, …) | Page objects **extend your class**, with your import path |
|
|
151
|
+
| Your test framework (pytest / pytest-bdd / unittest) | Matching test style |
|
|
152
|
+
| Your naming conventions (`test_login.py` vs `LoginTest.py`, `login_page.py` vs `LoginPage.py`) | Same naming |
|
|
153
|
+
| Your `conftest.py` and driver fixture | Reused — not overwritten |
|
|
154
|
+
| Your import style (absolute/relative) and sample code | Generated code follows your style |
|
|
155
|
+
|
|
156
|
+
`--heal-only` also works directly on your existing test files — the healer auto-discovers the page objects your tests import.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 🤝 Claude Code Integration — `init-agents`
|
|
161
|
+
|
|
162
|
+
The Selenium equivalent of `npx playwright init-agents --loop=claude`:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
selenium-agent init-agents # into current project
|
|
166
|
+
selenium-agent init-agents --project /path/to/project
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
This installs three Claude Code subagents:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
.claude/agents/selenium-test-planner.md ← plans tests, saves specs/
|
|
173
|
+
.claude/agents/selenium-test-generator.md ← generates code from specs/
|
|
174
|
+
.claude/agents/selenium-test-healer.md ← runs, debugs & fixes tests
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Then, inside Claude Code:
|
|
178
|
+
|
|
179
|
+
> "use selenium-test-planner to plan tests for https://www.saucedemo.com"
|
|
180
|
+
> "use selenium-test-generator to generate the tests from specs/login.json"
|
|
181
|
+
> "use selenium-test-healer to fix tests/test_login.py"
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 📋 All Commands
|
|
186
|
+
|
|
187
|
+
### Generate Tests (Main Command)
|
|
188
|
+
|
|
189
|
+
The instruction is **free-form natural language** — it works for **any application and any workflow**, not just login pages. The planner opens *your* URL in a real browser and builds the plan from your app's actual DOM.
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
selenium-agent "<describe any workflow to test>" --url <your-app-url>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Example instructions (any app, any flow):
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
selenium-agent "test the login page" # uses saved config + URL
|
|
199
|
+
selenium-agent "search for 'laptop' and verify results show prices" --url https://demo.opencart.com
|
|
200
|
+
selenium-agent "register a new account and verify the welcome banner" --url https://myapp.internal
|
|
201
|
+
selenium-agent "fill the contact form and verify the thank-you message" --url https://mycompany.com/contact
|
|
202
|
+
selenium-agent "login as admin, create an invoice and verify it appears in the list" --url https://erp.mycompany.com
|
|
203
|
+
selenium-agent "add two items to cart, remove one, then checkout as guest" --url https://shop.example.org
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Flags (combine with any instruction):
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
selenium-agent "..." --url https://staging.myapp.com # override saved URL once (also saved)
|
|
210
|
+
selenium-agent "..." --no-heal # generate only, skip healing
|
|
211
|
+
selenium-agent "..." --mode bdd # Gherkin .feature files
|
|
212
|
+
selenium-agent "..." --headless # no visible browser
|
|
213
|
+
selenium-agent "..." --explore 3 # explore up to 3 more pages while planning
|
|
214
|
+
selenium-agent "..." --output-dir my_tests/ # custom output folder
|
|
215
|
+
selenium-agent "..." --project /path/to/project # fit into YOUR existing framework
|
|
216
|
+
selenium-agent "..." --model gpt-5 # override model for this run
|
|
217
|
+
selenium-agent "..." --max-retries 8 # more healer attempts (default: 5)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### `--plan-only` — Preview & Persist the Test Plan
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
selenium-agent --plan-only "test the login page"
|
|
224
|
+
selenium-agent --plan-only "end-to-end purchase flow with checkout and logout" --explore 2
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Saves `specs/<slug>.md` (human-readable) + `specs/<slug>.json` (generator input),
|
|
228
|
+
built from a **real DOM scan** — scenarios, locators, wait strategies.
|
|
229
|
+
|
|
230
|
+
**Smart planning includes:**
|
|
231
|
+
- **Live DOM scan first** — selectors come from your actual page, never guessed
|
|
232
|
+
- **SPA-aware scanning** — polls until React/Vue/Angular apps finish rendering (boot animations included)
|
|
233
|
+
- **Relevance-ranked site exploration** (`--explore N`) — follows the links that match *your instruction* (a sign-up flow explores the register page, a checkout flow explores the cart), multi-hop: pages linked from explored pages are reachable too
|
|
234
|
+
- **Selector uniqueness verification** — every CSS/XPath is counted against the live DOM; ambiguous selectors are scoped to a unique ancestor or flagged, so the wrong twin element is never picked
|
|
235
|
+
- **Text & value elements captured** — labels, displayed values, status badges get locators too (for "read the X shown on the page" workflows)
|
|
236
|
+
- **Dropdown options captured** — `<select>` option texts are scanned so planned test data matches real options
|
|
237
|
+
- **CAPTCHA / bot-protection detection** — reported honestly as a blocker instead of doomed retries (never bypassed)
|
|
238
|
+
|
|
239
|
+
### `--from-plan` — Generate From a Saved/Edited Plan
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
selenium-agent --from-plan specs/test-the-login-page.json
|
|
243
|
+
selenium-agent --from-plan specs/test-the-login-page.json --no-heal
|
|
244
|
+
selenium-agent --from-plan specs/test-the-login-page.json --headless
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Smart generation includes:**
|
|
248
|
+
- **Deterministic scaffolding** — the `driver` fixture lives in a framework-generated `conftest.py`, never LLM-written (an entire class of collection errors is impossible by construction)
|
|
249
|
+
- **Self-verification before saving** — every file is syntax-checked (`ast`), architecture-checked (no `By`/locators/DriverFactory in test files) and completeness-checked (page objects AND tests present), with one automatic LLM repair round
|
|
250
|
+
- **Unique runtime test data** — entity-creating flows (sign-ups, records) get uuid-based emails/names, and **strong unique passwords** (never `Password@123`-style patterns that breach-list validators reject)
|
|
251
|
+
- **Complete form filling** — "fill the form" means every scanned input/select, not just the fields named in the instruction
|
|
252
|
+
|
|
253
|
+
### `--heal-only` — Fix Existing Tests
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
selenium-agent --heal-only generated_tests/tests/test_login.py
|
|
257
|
+
|
|
258
|
+
# Heal tests living in YOUR project (page objects auto-discovered from imports)
|
|
259
|
+
selenium-agent --heal-only src/tests/test_checkout.py --project /path/to/your/project
|
|
260
|
+
|
|
261
|
+
# Heal one test only (other tests preserved verbatim)
|
|
262
|
+
selenium-agent --heal-only generated_tests/tests/test_login.py \
|
|
263
|
+
--test test_login_locked_out_user
|
|
264
|
+
|
|
265
|
+
# pytest -k syntax works too
|
|
266
|
+
selenium-agent --heal-only generated_tests/tests/test_login.py \
|
|
267
|
+
--test "locked_out or invalid_password"
|
|
268
|
+
|
|
269
|
+
# Stubborn failure? Give it more rounds and a stronger model
|
|
270
|
+
selenium-agent --heal-only generated_tests/tests/test_login.py --max-retries 8 --model gpt-5
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Smart healing includes:**
|
|
274
|
+
- **Failure-time diagnostics** — on every failure the run reports `FAILURE_URL` (the exact page the browser was on), `FAILURE_ERRORS` (visible alert/validation messages) and `FAILURE_PAGE_TEXT`, so the healer debugs from evidence, not guesses
|
|
275
|
+
- **Live DOM re-scan of the failing page(s)** — locator fixes come from ground truth, grouped per page so locators are never borrowed from the wrong page
|
|
276
|
+
- Selenium-specific error classification (SeleniumErrorMap) before the LLM is asked — including SPA patterns like "the URL never changes, assert an in-page indicator instead"
|
|
277
|
+
- Every fix is **validated** (syntax + architecture) — a broken fix never overwrites a working file
|
|
278
|
+
- The final fix is **always verified** with a test run (never "fixed and hoped")
|
|
279
|
+
- Pure-Python failures (imports, collection) skip browser scans — attempts are spent where they matter
|
|
280
|
+
- Missing locators added to page objects (never to test files); `By` imports stripped from tests
|
|
281
|
+
- Targeted mode restores any test functions the LLM accidentally drops
|
|
282
|
+
- CAPTCHA-blocked flows are reported as blocked instead of endlessly "fixed"
|
|
283
|
+
|
|
284
|
+
### `--scan` — Inspect an Existing Project
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
selenium-agent --scan /path/to/existing/project
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Detects folder layout, base page class, test framework, driver setup, naming
|
|
291
|
+
conventions and import style — so generated code fits **into** the project.
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## 🛡️ Battle-Hardened BasePage
|
|
296
|
+
|
|
297
|
+
Generated code runs on a `BasePage` that survives real-world DOM messiness:
|
|
298
|
+
|
|
299
|
+
- **Duplicate-element tolerance** — when one selector matches several elements (desktop form + hidden mobile drawer with the same ids, wrapper sharing its id with the input inside), it picks the *displayed, editable, in-viewport* one instead of crashing
|
|
300
|
+
- **Fuzzy dropdown matching** — `select_by_text("United States")` still works when the option is literally `"United States of America (the)"`
|
|
301
|
+
- **`safe_type()`** — typing verified after entry, with a JS + React-event fallback for stubborn SPA inputs
|
|
302
|
+
- **Fluent waits everywhere** — `fluent_wait(locator, 'visible'|'clickable'|'present'|'invisible')`; no `time.sleep()` anywhere
|
|
303
|
+
- **Forgiving locator input** — a raw selector string accidentally passed where a locator tuple belongs is auto-normalized instead of crashing
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## 🏗️ Generated Output Structure
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
specs/
|
|
311
|
+
├── test-the-login-page.md ← reviewable test plan (Planner output)
|
|
312
|
+
└── test-the-login-page.json ← machine-readable plan (Generator input)
|
|
313
|
+
generated_tests/
|
|
314
|
+
├── pages/
|
|
315
|
+
│ └── login_page.py ← Page Object (locators live here)
|
|
316
|
+
├── tests/
|
|
317
|
+
│ └── test_login.py ← pytest test file (no raw locators)
|
|
318
|
+
└── conftest.py ← framework-provided driver fixture + failure diagnostics
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**Architecture enforced by the agents:**
|
|
322
|
+
- Locators are **always** class constants in page objects: `LOGIN_BUTTON = (By.CSS_SELECTOR, '[data-test="login-button"]')`
|
|
323
|
+
- Test files reference by name: `page.LOGIN_BUTTON` — no `By`, no raw strings, no DriverFactory
|
|
324
|
+
- One page object per page — multi-page flows get one class each
|
|
325
|
+
- All waits via `fluent_wait(locator, condition)` — no `time.sleep()`
|
|
326
|
+
- `wait_for_url()` after every navigation, `page.safe_type()` for React/SPA forms
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## 🏢 Enterprise-Grade Reliability
|
|
331
|
+
|
|
332
|
+
| Concern | What the framework does |
|
|
333
|
+
|---|---|
|
|
334
|
+
| LLM flakiness | Automatic retries with exponential backoff on rate limits / 5xx / timeouts |
|
|
335
|
+
| Malformed LLM JSON | Native JSON modes (OpenAI `json_object`, Anthropic prefill) + robust extraction: fences, prose, trailing commas, truncation repair |
|
|
336
|
+
| Broken generated code | Every file `ast`-validated + architecture-validated before saving; automatic repair round |
|
|
337
|
+
| Broken "fixes" | Healer rejects invalid fixes — never overwrites working files |
|
|
338
|
+
| Unverified fixes | Final heal attempt always followed by a verification test run |
|
|
339
|
+
| Guessed selectors | Live DOM scans with per-selector **uniqueness verification** |
|
|
340
|
+
| Client-side apps | SPA-aware scan polling — waits for React/Vue/Angular to actually render |
|
|
341
|
+
| Flaky duplicate DOM | BasePage prefers displayed/editable/in-viewport elements among duplicates |
|
|
342
|
+
| Colliding test data | Runtime-unique emails/names + strong unique passwords by rule |
|
|
343
|
+
| Bot protection | CAPTCHA detected and reported — never bypassed, never blindly retried |
|
|
344
|
+
| Hung test runs | pytest executed with a hard timeout |
|
|
345
|
+
| Existing projects | ProjectScanner detects your BasePage, layout & conventions; code fits in |
|
|
346
|
+
| Reasoning models | OpenAI gpt-5*/o* token budgets handled (reasoning tokens accounted for) |
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## 🔧 All CLI Flags Reference
|
|
351
|
+
|
|
352
|
+
| Flag | Description | Default |
|
|
353
|
+
|------|-------------|---------|
|
|
354
|
+
| `--provider` | `anthropic` or `openai` | from config |
|
|
355
|
+
| `--model` | Any model of that provider, for this run | from config |
|
|
356
|
+
| `--api-key` | API key (prefer .env instead) | env var |
|
|
357
|
+
| `--url` | Base URL for this run (also saved to config) | from config |
|
|
358
|
+
| `--mode` | `pytest` or `bdd` | from config (`pytest`) |
|
|
359
|
+
| `--headless` | Headless browser | from config (`false`) |
|
|
360
|
+
| `--explore N` | Explore up to N extra same-origin pages while planning (relevance-ranked, multi-hop) | `0` |
|
|
361
|
+
| `--output-dir` | Where to save generated files | `generated_tests` |
|
|
362
|
+
| `--project` | Fit into existing project path | — |
|
|
363
|
+
| `--max-retries` | Healer fix attempts | `5` |
|
|
364
|
+
| `--no-heal` | Skip healing after codegen | `false` |
|
|
365
|
+
| `--plan-only` | Save + show plan, no code | `false` |
|
|
366
|
+
| `--from-plan FILE` | Generate from saved plan JSON | — |
|
|
367
|
+
| `--heal-only FILE` | Heal specific file(s) | — |
|
|
368
|
+
| `--test TEST_NAME` | Target specific test (with `--heal-only`) | — |
|
|
369
|
+
| `--scan PATH` | Scan existing project structure | — |
|
|
370
|
+
| `--version` | Show version | — |
|
|
371
|
+
|
|
372
|
+
Subcommands: `selenium-agent config …`, `selenium-agent init-agents …`, `selenium-agent help`
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## 🤖 Supported Models
|
|
377
|
+
|
|
378
|
+
**Any chat model from OpenAI or Anthropic works** — pass it via `--model` or save it with `selenium-agent config --model <name>`. Recommendations:
|
|
379
|
+
|
|
380
|
+
| Provider | Model | Best for |
|
|
381
|
+
|----------|-------|----------|
|
|
382
|
+
| OpenAI | `gpt-4o-mini` | Simple flows, lowest cost |
|
|
383
|
+
| OpenAI | `gpt-4o` | Strong default for real projects |
|
|
384
|
+
| OpenAI | `gpt-5` / `gpt-5-mini` | Complex multi-page flows (reasoning models — token budgets handled automatically) |
|
|
385
|
+
| Anthropic | `claude-fable-5` | Most intelligent — hardest multi-page flows |
|
|
386
|
+
| Anthropic | `claude-opus-4-8` | Complex flows, high quality |
|
|
387
|
+
| Anthropic | `claude-sonnet-5` | Strong default for real projects |
|
|
388
|
+
| Anthropic | `claude-haiku-4-5-20251001` | Simple flows, lowest cost |
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## 📦 Requirements
|
|
393
|
+
|
|
394
|
+
- Python 3.9+
|
|
395
|
+
- Chrome browser installed
|
|
396
|
+
- API key from Anthropic **or** OpenAI
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## 🤝 Contributing
|
|
401
|
+
|
|
402
|
+
PRs welcome! See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## 📄 License
|
|
407
|
+
|
|
408
|
+
MIT — free to use, modify, distribute.
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
*Built with ❤️ by [Ankit Tripathi](https://github.com/AnkitDeepBlue)*
|