Skip to main content

芒果自动化测试平台 (Mango Automation)

Python Version License

项目简介

芒果自动化测试平台(Mango Automation)是一个多平台UI自动化测试工具,支持Android、iOS、PC和Web端的自动化操作。该平台集成了AI智能元素识别功能,能够通过大模型辅助进行元素定位,提高测试脚本的稳定性和维护效率。

核心功能

  • ✅ 多平台支持:支持Web、Android、iOS、PC桌面应用的自动化测试
  • ✅ AI智能定位:基于大模型的智能元素识别(React Agent),自动修复定位失败问题
  • ✅ 统一驱动封装:跨平台UI驱动封装,提供一致的API接口
  • ✅ 元素操作:支持元素查找、断言、输入模拟等基础操作
  • ✅ 智能重试机制:自动记忆成功/失败的定位表达式,优化后续定位效率

技术架构

mangoautomation/
├── enums/           # 枚举定义
├── exceptions/      # 异常处理模块
├── models/          # 数据模型
├── react_agent/     # AI代理模块(核心)
├── tools/           # 辅助工具
├── uidrive/         # 统一驱动接口
├── uidrives/        # 多平台具体实现(android, ios, pc, web)
└── __init__.py      # 模块初始化

技术栈

  • Playwright: Web端自动化
  • uiautomation: Windows桌面应用自动化
  • uiautomator2 和 uiautodev: Android设备自动化控制
  • adbutils: ADB通信工具
  • OpenAI: 大模型能力支持智能测试
  • Pydantic: 数据模型校验
  • BeautifulSoup4: HTML解析辅助

安装方式

pip安装

pip install mangoautomation

源码安装

git clone https://gitee.com/mao-peng/testkit.git
cd mangoautomation
pip install -r requirements.txt
python setup.py install

快速开始

Web自动化示例

from mangoautomation.uidrive import DriverObject, BaseData
from mangoautomation.models import ElementModel
from mangotools.data_processor import DataProcessor
from mangotools.log_collector import set_log

# 初始化日志和数据处理器
log = set_log('./logs')
test_data = DataProcessor()

# 创建驱动对象
driver_object = DriverObject(log, is_async=True)
driver_object.set_web(web_type=0, web_path="/path/to/chrome")

# 配置基础数据
base_data = BaseData(test_data, log)
base_data.set_url("https://www.baidu.com/")

# 创建元素模型
element_model = ElementModel(
    id=1,
    type=0,  # 元素操作类型
    name="搜索框",
    elements=[
        {
            "exp": 2,  # 定位方式:locator
            "loc": "locator(\"#kw\")",  # 定位表达式
            "sub": None,
            "is_iframe": 0,
            "prompt": "查找元素:搜索框"
        }
    ],
    ope_key="w_input",  # 操作方法
    ope_value=[{"v": "芒果测试平台"}]  # 操作值
)

# 执行自动化操作
async def run_test():
    context, page = await driver_object.web.new_web_page()
    base_data.set_page_context(page, context)
    
    # 创建元素操作对象
    element = AsyncElement(base_data, 0)  # 0表示Web平台
    
    # 打开URL
    await element.open_url()
    
    # 执行元素操作
    await element.element_main(element_model)

# 运行测试
import asyncio
asyncio.run(run_test())

Android自动化示例

# TODO: 添加Android示例

PC桌面应用自动化示例

# TODO: 添加PC示例

AI智能定位功能

芒果自动化平台集成了基于OpenAI的AI智能定位功能,能够:

  1. 当元素定位失败时,自动调用AI重新生成定位表达式
  2. 记忆成功和失败的定位表达式,优化后续定位效率
  3. 支持HTML内容分段处理,解决大页面定位问题
# 启用AI定位功能
base_data = BaseData(test_data, log)
base_data.set_agent(
    True, 
    'your-openai-api-key',
    'https://api.openai.com/v1',  # base_url
    'gpt-4'  # model
)

Docker部署

项目提供了Dockerfile支持容器化部署:

# 构建镜像
docker build -t mango_automation .

# 运行容器
docker run -d --name mango_automation mango_automation

项目结构说明

tests/               # 测试用例目录
├── test_ui_web.py   # Web自动化测试
├── test_ui_and.py   # Android测试
└── demo1.py         # 示例脚本

贡献指南

欢迎提交Issue和Pull Request来改进芒果自动化测试平台。

许可证

本项目采用MIT许可证,详情请见LICENSE文件。

联系方式

如有问题或建议,请联系:729164035@qq.com

项目链接

Metadata

Release files for mangoautomation 2.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mangoautomation 2.0.4
File Size Uploaded Provenance Actions
mangoautomation-2.0.4.tar.gz 59.5 kB Without provenance Details for mangoautomation-2.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mangoautomation 2.0.4
File Interpreter ABI Platform Actions
mangoautomation-2.0.4-py3-none-any.whl Python 3 none any Details for mangoautomation-2.0.4-py3-none-any.whl

Total release size: 145.1 kB

Release files / mangoautomation-2.0.4.tar.gz

Download URL mangoautomation-2.0.4.tar.gz
Size 59.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1c6fb4125e5ef1bcdb78e8caadbddd17e07b28e70e1eddb13128a3c76e48bfe8
BLAKE2b-256 checksum
How to use checksums
7f591d82b2bc8feeede893602dd2207360e0ee556ae718971eb714386476541f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / mangoautomation-2.0.4-py3-none-any.whl

Download URL mangoautomation-2.0.4-py3-none-any.whl
Size 85.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dcc1096f925aa2092603b90fb0ccd6a7dc59daa7f2e5f2ebd0da6f714e96fa6
BLAKE2b-256 checksum
How to use checksums
2d53eb8a8344370e0a56a9d6bfd4acfb59e378f4b6189a95757bda7b282283ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Security for mangoautomation 2.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page