测试工具
Project description
芒果自动化测试平台 (Mango Automation)
项目简介
芒果自动化测试平台(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智能定位功能,能够:
- 当元素定位失败时,自动调用AI重新生成定位表达式
- 记忆成功和失败的定位表达式,优化后续定位效率
- 支持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
项目链接
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 mangoautomation-1.1.40.tar.gz.
File metadata
- Download URL: mangoautomation-1.1.40.tar.gz
- Upload date:
- Size: 9.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45f53a0b5261f4757f054d14107bea8262cd9470e861ca582ff1b88b0f66fd18
|
|
| MD5 |
7133739bef8e681cbe0a0cc08717665b
|
|
| BLAKE2b-256 |
77f7d7e84bc26abd2311d865edb550a9973005151adcb8c333ca47afc9e72954
|
File details
Details for the file mangoautomation-1.1.40-py3-none-any.whl.
File metadata
- Download URL: mangoautomation-1.1.40-py3-none-any.whl
- Upload date:
- Size: 10.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46cf779ec37b9ff9f9bfbbeaf07b5a899d95b742688a59dd40fbd5ee7a90d264
|
|
| MD5 |
3daf2bf407775972e28ab94bf9867ba6
|
|
| BLAKE2b-256 |
a201a69ff2080243e18823826807931724b80bcbc454a5f6aa57298d64d6dc7e
|