Skip to main content

AI-powered UI automation testing library

Project description

UI-Zero

English | 中文

A Python library for AI-powered UI automation testing. This library provides command-line tools for automated UI testing using computer vision and AI models.

Features

  • Android device automation via ADB
  • AI-powered UI element recognition and interaction
  • Command-line interface for test execution
  • Support for multiple AI models (Doubao, Ark, etc.)
  • Comprehensive screenshot and interaction capabilities
  • Internationalization Support - Auto-detects system language with Chinese/English interface
  • Professional Localization - Uses gettext for industry-standard internationalization

Installation

Using uv (recommended):

uv add ui-zero

Or using pip:

pip install ui-zero

Development Installation

# Clone the repository
git clone https://github.com/Roland0511/ui-zero.git
cd ui-zero

# Install development dependencies with uv
uv sync

# Or using pip
pip install -e ".[dev]"

Setup Environment Variables

This library uses ByteDance's UI-TARS model for AI-powered UI recognition. Follow the deployment guide to deploy the model and obtain an API key.

For Chinese users, see UI-TARS 模型部署教程.

After deployment, set the following environment variables in your system:

# Set the API key in your environment
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="your_api_base_url_here"

Environment Requirements

For Computer

  • Python 3.10+
  • Android SDK with ADB installed
  • Connected Android device with USB debugging enabled

For Android Device

  • Android 8.0+ (API level 26+)
  • USB debugging enabled
  • ADBKeyboard installed for text input support

Command Line Usage

After installation, you can use the uiz command:

# Run with test case file
uiz --testcase test_case.json

# Run with direct commands
uiz --command "find and click settings icon"

# List available devices
uiz --list-devices

# Use specific device
uiz --device DEVICE_ID --command "find and click settings icon"

# Enable debug mode
uiz --debug --command "search for Wi-Fi settings, then click"

# Disable history feature
uiz --no-history --command "open app"

# Show help information
uiz --help

Python API Usage

from ui_zero import AndroidAgent, ADBTool

# Initialize ADB and agent
adb_tool = ADBTool()
agent = AndroidAgent(adb_tool)

# Run a test step
result = agent.run("find search bar and type 'hello world'")

# Execute with callbacks
def on_screenshot(img_bytes):
    print(f"Screenshot size: {len(img_bytes)} bytes")

def on_action(prompt, action):
    print(f"Executing action: {action.action}")

result = agent.run(
    "click settings button",
    screenshot_callback=on_screenshot,
    preaction_callback=on_action
)

Internationalization Features

UI-Zero supports automatic localization based on system language:

Automatic Language Detection

The system automatically detects the following environment variables and sets the appropriate language:

  • LANG
  • LC_ALL
  • LC_MESSAGES

Manual Language Setting

from ui_zero.localization import set_language

# Set to Chinese
set_language('zh_CN')

# Set to English
set_language('en_US')

Supported Languages

  • Chinese (Simplified): zh_CN
  • English (US): en_US

Development Guide

Code Quality Checks

# Code formatting
uv run black ui_zero/

# Import sorting
uv run isort ui_zero/

# Type checking
uv run mypy ui_zero/

# Linting
uv run flake8 ui_zero/

Running Tests

# Run all tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=ui_zero

# Run localization tests
uv run pytest tests/test_localization.py -v

Translation Management

Compile translation files:

# Compile all .po files to .mo files
uv run python scripts/compile_translations.py

Manual localization testing:

# Run localization manual tests
uv run python tests/test_localization.py --manual

Project Structure

ui_zero/
├── __init__.py           # Package initialization
├── cli.py               # Command line interface
├── agent.py             # Android automation agent
├── adb.py               # ADB tool class
├── localization.py      # Internationalization manager
├── locale/              # Translation files directory
│   ├── messages.pot     # Translation template
│   ├── zh_CN/LC_MESSAGES/
│   │   ├── ui_zero.po   # Chinese translation source
│   │   └── ui_zero.mo   # Chinese binary file
│   └── en_US/LC_MESSAGES/
│       ├── ui_zero.po   # English translation source
│       └── ui_zero.mo   # English binary file
└── models/              # AI model integrations
    ├── __init__.py
    ├── arkmodel.py      # Ark model base class
    └── doubao_ui_tars.py # Doubao UI-TARS model

Test Case Format

Create a test_case.json file:

[
    "find and click settings icon",
    "scroll to bottom",
    "click about phone",
    "go back"
]

Environment Variables

Variable Description Example
ARK_API_KEY UI-TARS model API key your_api_key_here
OPENAI_API_KEY OpenAI compatible API key sk-...
OPENAI_BASE_URL OpenAI compatible API base URL https://api.openai.com/v1
LANG System language (auto-detected) en_US.UTF-8

Troubleshooting

Common Issues

  1. ADB command not available

    # Ensure Android SDK is installed and added to PATH
    export PATH=$PATH:$ANDROID_HOME/platform-tools
    
  2. Device connection issues

    # Check device connection
    adb devices
    
    # Restart ADB service
    adb kill-server && adb start-server
    
  3. API key issues

    # Ensure environment variable is set
    echo $ARK_API_KEY
    
  4. Text input issues

    • Ensure ADBKeyboard app is installed on device
    • Enable ADBKeyboard as input method in device settings

Contributing

Contributions are welcome! Please see the Contributing Guide for details.

License

MIT License - see the LICENSE file for details.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ui_zero-0.1.1.tar.gz (111.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ui_zero-0.1.1-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file ui_zero-0.1.1.tar.gz.

File metadata

  • Download URL: ui_zero-0.1.1.tar.gz
  • Upload date:
  • Size: 111.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ui_zero-0.1.1.tar.gz
Algorithm Hash digest
SHA256 581823998a8d7e1ea2c8fc00a68c191cbd09323433fb95414663235aa2ee597c
MD5 5089f891e0f22373151177b41fc9b8e9
BLAKE2b-256 3a9fadfc2d907b509bf9406116d9167980074879ce4f763212293b194a72f9f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ui_zero-0.1.1.tar.gz:

Publisher: python-publish.yml on Roland0511/ui-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ui_zero-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ui_zero-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ui_zero-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9183419c8a6b49145801a4deeb3d78c021e57737a982f1ba76ccb0373a3bed82
MD5 af0c62d7bf107870de61376306fd04eb
BLAKE2b-256 fa72ecd0ef62e083c616ca49ada9a7e407806b279f91db0c10fc988be8e95f1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ui_zero-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on Roland0511/ui-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page