A powerful, cross-platform Python library for desktop UI testing and automation
Project description
PyUI Automation
A powerful, cross-platform Python library for desktop UI testing and automation with advanced features including visual testing, performance monitoring, and accessibility checking.
Features
- ๐ฅ๏ธ Cross-Platform Support (Windows, Linux, macOS)
- ๐ Multiple Element Finding Strategies
- ๐ฑ๏ธ Advanced Input Simulation
- ๐ธ Visual Testing and Comparison
- โก Performance Monitoring and Testing
- โฟ Accessibility Testing
- ๐ Application Management
- ๐ Comprehensive Reporting
Quick Start
from pyui_automation import UIAutomation
# Initialize automation
ui = UIAutomation()
# Find and interact with elements
button = ui.find_element(by="name", value="Submit")
button.click()
# Visual testing
ui.take_screenshot("before.png")
button.click()
ui.take_screenshot("after.png")
ui.compare_images("before.png", "after.png", threshold=0.95)
# OCR capabilities
text = ui.recognize_text("screenshot.png")
print(f"Found text: {text}")
# Performance monitoring
with ui.measure_performance() as perf:
button.click()
print(f"Click took: {perf.duration}ms")
# Accessibility testing
violations = ui.check_accessibility(button)
for v in violations:
print(f"Violation: {v.description}")
Installation
# Install required dependencies
pip install -r requirements.txt
# Install development dependencies
pip install -r requirements-dev.txt
Examples
Finding Elements
# Find by name
element = ui.find_element(by="name", value="Submit")
# Find by ID
element = ui.find_element(by="id", value="submit-button")
# Find by class name
element = ui.find_element(by="class", value="btn-primary")
# Find with timeout
element = ui.find_element(by="name", value="Submit", timeout=10)
# Find multiple elements
elements = ui.find_elements(by="class", value="list-item")
Mouse and Keyboard Input
# Mouse actions
ui.click(x=100, y=200)
ui.double_click(x=100, y=200)
ui.right_click(x=100, y=200)
ui.drag_and_drop(start_x=100, start_y=200, end_x=300, end_y=400)
# Keyboard input
ui.type_text("Hello World")
ui.press_key("enter")
ui.press_keys(["ctrl", "c"])
Visual Testing
# Basic screenshot comparison
ui.take_screenshot("baseline.png")
# ... perform actions ...
ui.take_screenshot("current.png")
diff = ui.compare_images("baseline.png", "current.png")
assert diff.similarity > 0.95
# Region-based comparison
region = (100, 100, 200, 200) # x, y, width, height
ui.take_screenshot("region.png", region=region)
# With masking
mask = ui.create_mask()
mask.add_region((100, 100, 200, 200))
diff = ui.compare_images("baseline.png", "current.png", mask=mask)
OCR and Text Recognition
# Basic text recognition
text = ui.recognize_text("screenshot.png")
# With region
region = (100, 100, 200, 200)
text = ui.recognize_text("screenshot.png", region=region)
# With confidence threshold
text = ui.recognize_text("screenshot.png", confidence=0.8)
# Find text location
locations = ui.find_text("Submit", "screenshot.png")
for x, y in locations:
print(f"Found 'Submit' at ({x}, {y})")
Performance Testing
# Basic performance measurement
with ui.measure_performance() as perf:
button.click()
print(f"Operation took: {perf.duration}ms")
# Custom metrics
with ui.measure_performance() as perf:
perf.start_metric("database")
# ... database operations ...
perf.end_metric("database")
perf.start_metric("rendering")
# ... rendering operations ...
perf.end_metric("rendering")
print(f"Database: {perf.get_metric('database')}ms")
print(f"Rendering: {perf.get_metric('rendering')}ms")
Accessibility Testing
# Check single element
violations = ui.check_accessibility(button)
# Check entire window
window = ui.get_active_window()
violations = ui.check_accessibility(window, recursive=True)
# With custom rules
rules = {
"contrast": {"min_ratio": 4.5},
"text_size": {"min_size": 12}
}
violations = ui.check_accessibility(button, rules=rules)
Code Coverage
---------- coverage: platform win32, python 3.12.0-final-0 -----------
Name Stmts Miss Cover
----------------------------------------------------------
pyui_automation/__init__.py 8 0 100%
pyui_automation/accessibility.py 136 8 94%
pyui_automation/application.py 138 62 55%
pyui_automation/backends/__init__.py 14 7 50%
pyui_automation/backends/base.py 33 0 100%
pyui_automation/backends/linux.py 75 58 23%
pyui_automation/backends/macos.py 94 76 19%
pyui_automation/backends/windows.py 218 56 74%
pyui_automation/core.py 246 246 0%
pyui_automation/core/__init__.py 5 0 100%
pyui_automation/core/config.py 28 0 100%
pyui_automation/core/factory.py 37 2 95%
pyui_automation/core/session.py 74 13 82%
pyui_automation/core/utils.py 36 24 33%
pyui_automation/di.py 29 0 100%
pyui_automation/elements.py 83 83 0%
pyui_automation/elements/__init__.py 5 0 100%
pyui_automation/elements/base.py 40 3 92%
pyui_automation/elements/button.py 13 0 100%
pyui_automation/elements/input.py 25 11 56%
pyui_automation/elements/window.py 25 0 100%
pyui_automation/exceptions.py 11 0 100%
pyui_automation/input.py 202 106 48%
pyui_automation/logging.py 39 0 100%
pyui_automation/ocr.py 79 15 81%
pyui_automation/optimization.py 75 75 0%
pyui_automation/performance.py 142 45 68%
pyui_automation/utils/__init__.py 4 0 100%
pyui_automation/utils/file.py 47 33 30%
pyui_automation/utils/image.py 101 36 64%
pyui_automation/utils/validation.py 31 0 100%
pyui_automation/visual.py 168 25 85%
pyui_automation/wait.py 44 23 48%
----------------------------------------------------------
TOTAL 2305 1007 56%
Coverage Highlights
๐ข High Coverage (90-100%)
- Core Components:
exceptions.py,logging.py,validation.py,di.py - Base Classes:
backends/base.py,elements/button.py,elements/window.py - Configuration:
core/config.py,core/factory.py - Accessibility Testing:
accessibility.py(94%)
๐ก Medium Coverage (50-89%)
- Visual Testing:
visual.py(85%) - Core Session:
core/session.py(82%) - OCR:
ocr.py(81%) - Windows Backend:
backends/windows.py(74%) - Performance:
performance.py(68%) - Image Utils:
utils/image.py(64%) - Input Elements:
elements/input.py(56%) - Application:
application.py(55%)
๐ด Low Coverage (<50%)
- Core Implementation:
core.py(0%) - Elements Base:
elements.py(0%) - Optimization:
optimization.py(0%) - Platform Backends:
linux.py(23%),macos.py(19%) - File Utils:
utils/file.py(30%) - Core Utils:
core/utils.py(33%) - Input Handling:
input.py(48%),wait.py(48%)
Areas for Improvement
- Core Implementation (
core.py,elements.py): Need comprehensive test coverage - Platform Backends: Improve Linux and macOS testing
- Input Handling: Add more test cases for input simulation and wait conditions
- Optimization: Implement test suite for performance optimization module
Project Structure
pyui_automation/
โโโ core/
โ โโโ config.py # Configuration management
โ โโโ factory.py # Component factories
โ โโโ session.py # Main automation session
โ โโโ utils.py # Core utilities
โโโ elements/
โ โโโ base.py # Base element class
โ โโโ window.py # Window element
โ โโโ controls/ # UI control elements
โโโ backends/
โ โโโ windows.py # Windows implementation
โ โโโ linux.py # Linux implementation
โ โโโ macos.py # macOS implementation
โโโ utils/
โโโ image.py # Image processing
โโโ ocr.py # Text recognition
โโโ performance.py # Performance monitoring
Testing
# Run all tests
pytest
# Run with coverage
pytest --cov=pyui_automation
# Run specific test module
pytest tests/test_visual.py
# Run with verbose output
pytest -v
# Run tests matching pattern
pytest -k "test_visual or test_ocr"
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and ensure coverage
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyui_automation-0.1.0.tar.gz.
File metadata
- Download URL: pyui_automation-0.1.0.tar.gz
- Upload date:
- Size: 65.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93f73339d769ec9886ef7460e23a3c83c97b1347bbe9ad2b660b80232b941ce0
|
|
| MD5 |
12b8d71b0aa293ed16a80cc3188d1d57
|
|
| BLAKE2b-256 |
7b28b672a7f16785f6ac81073a1f30e5e19c10d1bd1bb7f77a1153d52c90bf35
|
File details
Details for the file pyui_automation-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyui_automation-0.1.0-py3-none-any.whl
- Upload date:
- Size: 48.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0910100a0ce6dfdc5c4c261dc7a1776e64da456b99c18c63994833b3bc1945f1
|
|
| MD5 |
eaf85267115053f18a36d5315d3e9a77
|
|
| BLAKE2b-256 |
d9a0f8e934a5b6570e053d0f4fe9645f9c8d38871ddc4bec141dec402501ddd4
|