SeleniumCodeGen is a sophisticated tool designed to accelerate UI automation by transforming manual browser interactions into clean, maintainable Python code. By combining a Chrome Extension (Manifest V3) for recording and a FastAPI backend for code generation, it produces production-ready tests using the Page Object Model (POM), Allure reporting, and self-healing locator logic.
Writing UI tests manually is often time-consuming and prone to selector brittleness. SeleniumCodeGen solves this by:
- Capturing Actions: Intelligently recording clicks, inputs, and navigations directly in the browser.
- Generating Smart Code: Using a dedicated backend to structure code into Page Objects, ensuring DRY (Don't Repeat Yourself) principles.
- Resilience: Implementing "healing locators" and automatic scrolling within a robust
BasePageclass to reduce test flakiness. - AI Enhancement: Optional integration with local LLMs (via Ollama) to generate human-readable step names and optimized CSS selectors.
- Page Object Model (POM) Support: Automatically generates separate files/classes for page elements and test logic.
- Self-Healing Locators: The generated
BasePageincludes logic to find elements even if primary selectors change. - Allure Integration: Full support for
@allure.step,@allure.feature, and@allure.titledecorators for beautiful reporting. - Data-Driven Testing (DDT): Support for variables and environment-specific configurations.
- Conditional Logic: Record
IF/ELSEblocks directly from the browser extension. - LLM-Powered: Integration with Ollama (Llama3) for semantic step naming and smart element identification.
- Advanced Assertions: Dedicated "Assert Mode" to visually select elements for validation.
The project consists of two core modules:
The "brain" of the operation. It receives JSON-serialized recording data and outputs structured Python code.
- Core Logic:
app/code_generator.pyhandles the template-based generation. - Database: SQLite (via SQLAlchemy) manages user licenses and access control.
- Validation: Pydantic schemas ensure data integrity between the extension and the server.
A high-performance recorder built on Manifest V3.
- Content Script: Injected into pages to capture events and provide visual feedback (element highlighting).
- Side Panel: A modern UI for managing test cases, collections, and generation settings.
- Offscreen Canvas: Used for capturing and cropping element-specific screenshots.
- Python 3.9+
- Google Chrome (or Chromium-based browser)
- [Optional] Ollama for AI features.
# Clone the repository
git clone https://github.com/Rostezkiy/Selenium-CodeGen.git
cd SeleniumCodeGen
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Start the server
uvicorn app.main:app --reloadTo use the generator, you need a local license key:
curl -X POST "http://127.0.0.1:8000/api/v1/dev/create-user-and-license?email=admin@example.com"Copy the license_key from the response.
- Open Chrome and navigate to
chrome://extensions/. - Enable Developer mode (top right).
- Click Load unpacked and select the
clientfolder from this project. - Open the Extension Options and paste your License Key.
- Record: Open the Side Panel, enter a Page Class name, and hit
Start Recording. - Interact: Perform actions on any website. Use the right-click context menu to add specific assertions or waits.
- Configure: In the side panel, toggle POM generation or BasePage inclusion.
- Generate: Click
Generate Code. The Python code is instantly copied to your clipboard. - Run:
pytest my_generated_test.py --alluredir=./allure-results
- Backend: FastAPI, SQLAlchemy, Pydantic, Jinja2.
- Frontend: JavaScript (ES6+), Chrome Extension API (MV3), SortableJS.
- Testing Frameworks: Selenium WebDriver, Pytest, Allure.
- AI/ML: Ollama API integration.
#selenium #autotest #fastapi #python #chrome-extension #automation #testing #allure #page-object-model #self-healing-tests #llm #ollama #test-automation-framework
Distributed under the MIT License. See LICENSE for more information.
Developed for QA Engineers who value their time.