Automated Gherkin scenario generation using artificial intelligence
An intelligent test automation tool that generates Gherkin scenarios for your Jira tasks using AI, then creates and links them automatically in Xray for seamless test management.
- AI-Powered Generation: Uses advanced language models (via Ollama) to generate contextual Gherkin scenarios
- Jira Integration: Automatically fetches tasks from Jira using customizable JQL queries
- Xray Integration: Creates test issues in Xray and links them back to original Jira tasks
- Parallel Processing: Multi-threaded execution for faster scenario generation
- Smart Caching: Caches generated scenarios to avoid redundant AI calls
- Component Detection: Intelligently identifies API components and generates relevant test scenarios
- Comprehensive Logging: Detailed logging with configurable levels and file output
- Highly Configurable: Extensive configuration options via environment variables
- Python 3.8 or higher
- Ollama installed and running locally
- Jira account with API access
- Xray Cloud subscription (or trial)
-
Clone the repository
git clone https://github.com/yourusername/ai-test-generator.git cd ai-test-generator -
Install dependencies
pip install -r requirements.txt
-
Set up Ollama model
# Install a reasoning model (recommended) ollama pull deepseek-r1:14b # Or use a smaller model for faster generation ollama pull qwen2.5:7b
-
Configure environment
cp .env.example .env # Edit .env with your credentials -
Run the generator
python -m src.ai_test_generator.main
Create a .env file with your configuration:
# Jira Configuration
JIRA_BASE_URL=https://your-domain.atlassian.net
JIRA_EMAIL=your-email@company.com
JIRA_API_TOKEN=your-jira-api-token
JIRA_PROJECT_KEY=DEMO
# Xray Configuration
XRAY_CLIENT_ID=your-xray-client-id
XRAY_CLIENT_SECRET=your-xray-client-secret
# AI Model Configuration
AI_MODEL=deepseek-r1:14b
# JQL Query for task selection
JQL_QUERY=project = "{project_key}" AND Sprint in openSprints() AND labels = "automation-ready"- Go to Atlassian Account Settings
- Create a new API token
- Copy the token to
JIRA_API_TOKEN
- Go to Xray Cloud API credentials page
- Create new API key pair
- Copy Client ID and Client Secret to your
.env
from ai_test_generator import AITestGenerator
# Initialize and run
generator = AITestGenerator()
generator.run()# Use custom query to select specific tasks
custom_query = 'project = "MYPROJECT" AND assignee = currentUser() AND labels = "ready-for-automation"'
generator.run(jql_query=custom_query)from ai_test_generator.generators import ScenarioGenerator
from ai_test_generator.managers import ResourceManager
# Generate a single scenario
resource_manager = ResourceManager()
scenario_generator = ScenarioGenerator(resource_manager)
scenario = scenario_generator.generate_gherkin(
"As a user, I want to create a new account so that I can access the system"
)
print(scenario)ai-test-generator/
├── src/ai_test_generator/ # Main package
│ ├── clients/ # API clients (Jira, Xray)
│ ├── config/ # Configuration management
│ ├── generators/ # AI scenario generators
│ ├── managers/ # Resource managers
│ ├── utils/ # Utilities (logging, cache)
│ └── main.py # Entry point
├── resources/ # Example files and templates
│ ├── examples/ # Gherkin examples and API schemas
│ └── templates/ # Template files
├── tests/ # Unit and integration tests
├── docs/ # Documentation
└── scripts/ # Setup and demo scripts
The tool supports various AI models through Ollama:
| Model | Size | Speed | Quality | Use Case |
|---|---|---|---|---|
deepseek-r1:14b |
Large | Slow | Excellent | Production use |
deepseek-r1:8b |
Medium | Medium | Very Good | Balanced option |
qwen2.5:7b |
Small | Fast | Good | Development/testing |
# Install your preferred model
ollama pull deepseek-r1:14b
# Verify installation
ollama listThe tool generates comprehensive Gherkin scenarios like this:
@TEST_DEMO-001
Scenario: @test=DEMO-001 Create new user account via REST API
Given a clean test environment
And valid user registration data:
| field | value |
| name | John Doe |
| email | john@example.com |
| username | johndoe123 |
When a POST request is sent to "/users"
Then http status matches 201
And json path "id" exists and save with key "user_id"
And json path "name" matches string "John Doe"
And json path "email" matches string "john@example.com"
And json path "created_at" existsAdd your own API components by modifying the identify_api_component method:
component_keywords = {
"your-api": ["keyword1", "keyword2", "specific-term"],
"another-api": ["different", "keywords"]
}from ai_test_generator.utils import CacheManager
cache = CacheManager()
# Get cache statistics
stats = cache.get_cache_stats()
print(f"Cache files: {stats['file_count']}")
# Clear old cache files
deleted = cache.cleanup_old_files(max_age_hours=24)
print(f"Deleted {deleted} old files")Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=src/ai_test_generator
# Run specific test file
pytest tests/test_scenario_generator.py -vThe tool provides comprehensive logging:
2024-01-15 10:30:15 - ai_test_generator.AITestGenerator - INFO - Starting AI test generation process...
2024-01-15 10:30:16 - ai_test_generator.JiraClient - INFO - Retrieved 5 tasks from Jira
2024-01-15 10:30:45 - ai_test_generator.ScenarioGenerator - INFO - Generated scenario for DEMO-123
2024-01-15 10:31:20 - ai_test_generator.XrayClient - INFO - Created test DEMO-T001 for task DEMO-123
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone and install in development mode
git clone https://github.com/yourusername/ai-test-generator.git
cd ai-test-generator
pip install -e .
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
# Format code
black src/ tests/Ollama Connection Error
# Check if Ollama is running
ollama list
# Start Ollama service
ollama serveJira Authentication Failed
- Verify your email and API token
- Check if your Jira URL is correct
- Ensure your account has necessary permissions
Xray Integration Issues
- Verify Xray Cloud credentials
- Check if your Jira project has Xray enabled
- Ensure sufficient Xray Cloud quota
This project is licensed under the MIT License - see the LICENSE file for details.