WPF Inventory Management App - Automation Testing Framework¶
A comprehensive automation testing framework for the WPF Inventory Management Application using PyWinAuto, pytest, and performance monitoring tools.
Technologies: Performance Testing • PyTest • PyWinAuto • Python • UI Automation • WPF
A comprehensive automation testing framework for the WPF Inventory Management Application using PyWinAuto, pytest, and performance monitoring tools.
📂 Project Path:
python\automation-testing🔗 GitHub Repository: https://github.com/AmalieShi/amalie_projects
Overview¶
This framework provides:
UI Automation: Complete automation of WPF application using PyWinAuto
Performance Testing: Monitor CPU, memory, and throughput during bulk operations
Test Data Generation: Realistic product data with permutations for comprehensive testing
Continuous Integration Ready: Structured for CI/CD pipelines with detailed reporting
Project Structure¶
wpf-inventory-app/
├── config.py # Configuration and application paths
├── conftest.py # PyTest fixtures and app lifecycle management
├── data_generator.py # Test data generation utilities
├── requirements.txt # Python dependencies
├── README.md # This file
├── test_oracles/ # Test data and oracles
│ ├── product_data.json # Base product templates
│ ├── performance_test_products.json # Generated performance test data
│ └── general_test_products.json # Generated general test data
├── tests/ # Test suites
│ ├── test_basic_functionality.py # Basic CRUD and UI tests
│ ├── test_performance.py # Performance and stress tests
│ └── __init__.py
├── screenshots/ # Failure screenshots (auto-created)
└── performance_results/ # Performance test results (auto-created)
Quick Start¶
Prerequisites¶
WPF Application: Ensure the WPF Inventory Management App is built:
cd C:\projects\github\amalie_projects\csharp\desktop-apps\wpf dotnet build
Python Environment: Python 3.8+ recommended
python -m venv venv venv\Scripts\activate # Windows # or source venv/bin/activate # Linux/Mac
Install Dependencies:
pip install -r requirements.txt
Running Tests¶
Basic Functionality Tests:
pytest tests/test_basic_functionality.py -v
Performance Tests:
pytest tests/test_performance.py -v -m "not slow"
Full Performance Suite (includes 100-item bulk test):
pytest tests/test_performance.py -v
All Tests with HTML Report:
pytest -v --html=report.html --self-contained-html
Parallel Execution:
pytest -n auto -v
Performance Testing¶
Bulk Insert Performance Test¶
The framework includes a comprehensive performance test that:
Inserts 100 products continuously
Monitors CPU, memory, thread count, and handle usage
Measures insertion throughput and response times
Generates detailed performance reports
Key Metrics Tracked:
Throughput: Products inserted per second
Response Time: Average time per insertion
Memory Usage: Peak and average memory consumption
CPU Usage: Processing overhead
UI Responsiveness: Interface lag under load
Performance Results¶
Results are automatically saved to performance_results/ with detailed JSON reports containing:
Execution timestamps
Success/failure rates
Performance statistics
Resource utilization metrics
Configuration¶
Application Paths (config.py)¶
The framework automatically detects the WPF application executable:
Debug Build:
bin/Debug/net8.0-windows/WpfInventoryApp.exeRelease Build:
bin/Release/net8.0-windows/WpfInventoryApp.exe
Control Identifiers¶
All UI controls are identified using AutomationProperties.AutomationId:
CONTROL_IDS = {
"product_name_textbox": "product_name_textbox",
"add_product_button": "add_product_button",
"products_datagrid": "products_display_grid",
# ... more controls
}
Test Settings¶
Customize test behavior:
TEST_SETTINGS = {
"app_startup_timeout": 10, # Application startup wait time
"element_timeout": 5, # UI element search timeout
"bulk_insert_count": 100, # Number of products for performance test
"screenshot_on_failure": True, # Capture screenshots on test failure
}
Test Data Generation¶
Product Data Templates¶
The framework generates realistic test data using configurable templates in test_oracles/product_data.json:
Categories: Electronics, Clothing, Home & Garden, etc.
Name Variations: Adjectives, colors, sizes
Price Ranges: Category-appropriate pricing
SKU Patterns: Formatted with random IDs
Data Generator Usage¶
from data_generator import ProductDataGenerator
generator = ProductDataGenerator()
# Generate single product
product = generator.generate_random_product()
# Generate batch for testing
products = generator.generate_product_batch(50)
# Generate performance test data
perf_data = generator.generate_performance_test_data(100)
Test Categories¶
Basic Functionality Tests¶
Application Startup: Verify app launches correctly
UI Element Presence: Check all controls are accessible
Single Product Addition: Test basic CRUD operations
Form Validation: Test input validation and error handling
Search Functionality: Test product search features
Data Grid Interaction: Test table/grid operations
Performance Tests¶
Bulk Insert Performance: 100-product continuous insertion
Memory Stability: Monitor memory leaks during extended operation
UI Responsiveness: Measure interface lag under load
Failure Diagnostics¶
Automatic Screenshots: Screenshots are captured on test failures and saved to screenshots/
Detailed Logging: Comprehensive logging with timestamps and context
Performance Profiles: Detailed resource usage reports for performance analysis
Extending the Framework¶
Adding New Tests¶
Create test files in
tests/directoryUse the
app_windowfixture for application accessUse
performance_monitorfixture for resource monitoringFollow the established patterns for control identification
Adding New Controls¶
Update
CONTROL_IDSinconfig.pywith AutomationIdEnsure WPF app has corresponding
AutomationProperties.AutomationIdsetCreate helper methods in test classes for control interaction
Custom Test Data¶
Extend
product_data.jsonwith new templatesModify
ProductDataGeneratorfor custom data patternsCreate specialized data generation methods as needed
Performance Benchmarks¶
Expected Performance Targets:
Insertion Rate: > 0.2 products/second
Average Response: < 5 seconds per insertion
UI Response: < 1 second average, < 3 seconds maximum
Memory Growth: < 50% increase during bulk operations
Peak Memory: < 500 MB
Troubleshooting¶
Common Issues¶
Application Not Found:
Ensure WPF app is built:
dotnet buildCheck paths in
config.pyVerify executable exists in expected location
Control Not Found:
Verify AutomationId matches between test and WPF app
Check if control is visible and enabled
Increase timeout values if needed
Performance Test Failures:
Close other applications to free resources
Run tests on a dedicated test machine
Adjust performance thresholds in test assertions
Debug Mode¶
# Run with verbose logging
pytest -v -s --log-cli-level=INFO
# Run single test with full output
pytest tests/test_basic_functionality.py::TestBasicFunctionality::test_add_single_product -v -s
Reporting¶
HTML Reports: Use --html=report.html for detailed test reports
Performance Reports: JSON files with detailed metrics in performance_results/
Screenshots: Automatic failure screenshots in screenshots/
Console Output: Real-time logging with progress indicators
Contributing¶
When adding new tests or features:
Follow existing code patterns and naming conventions
Add appropriate logging and error handling
Update this README with new functionality
Ensure tests are reliable and not flaky
Add performance assertions where appropriate
License¶
This testing framework is part of the Amalie Development Portfolio project.