Skip to main content

测试工具

Project description

芒果自动化测试平台 (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桌面应用自动化
  • uiautomator2uiautodev: 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

项目链接

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

mangoautomation-1.1.36.tar.gz (9.6 MB view details)

Uploaded Source

Built Distribution

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

mangoautomation-1.1.36-py3-none-any.whl (9.7 MB view details)

Uploaded Python 3

File details

Details for the file mangoautomation-1.1.36.tar.gz.

File metadata

  • Download URL: mangoautomation-1.1.36.tar.gz
  • Upload date:
  • Size: 9.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for mangoautomation-1.1.36.tar.gz
Algorithm Hash digest
SHA256 73bae83bef62f5b17825e9a658e6bf20856bfe8e83ae54a51345d63f3303f74d
MD5 cce3ce420cfd7737012972ab16a8a3b4
BLAKE2b-256 c8a52959af5c6b7962156dcf0ffe29acffe165801e7c46b92143f3984e035370

See more details on using hashes here.

File details

Details for the file mangoautomation-1.1.36-py3-none-any.whl.

File metadata

File hashes

Hashes for mangoautomation-1.1.36-py3-none-any.whl
Algorithm Hash digest
SHA256 4528097d83bf86acd64e98aa3454f7f4600c9f9052d2dd006162c6795de3f9ad
MD5 87c27cfe06a02ed32e15617390ca5e50
BLAKE2b-256 8fd8c8a06c31fe07d5270f7bd8b7399b2105339b37a1d87ea943cb5ba4b5a4a0

See more details on using hashes here.

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