feat(mini_program): 小程序端从 Playwright 切换为 miniprogram-automator

驱动方式: Python pytest → subprocess → node runner.js → miniprogram-automator → 微信开发者工具
架构: tests/web/mini_program/automator/ (Node.js) + conftest.py (Python subprocess 桥接)

前置条件: 微信开发者工具 + 开启服务端口 + npm install + uni-app build:mp-weixin
This commit is contained in:
xst
2026-07-15 17:34:25 +08:00
parent 03e152baab
commit b822428a2a
9 changed files with 393 additions and 112 deletions
+68
View File
@@ -0,0 +1,68 @@
# 司机端小程序 — miniprogram-automator
## 环境搭建
### 1. 安装微信开发者工具
- [下载地址](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html)
- 安装后打开**设置 → 安全 → 安全**,开启**服务端口**
### 2. 安装 Node.js 依赖
```bash
cd tests/web/mini_program/automator
npm install
```
### 3. 编译 uni-app 为微信小程序
```bash
# 回到项目根目录(即 uni-app 源码所在目录)
npm run build:mp-weixin
```
### 4. 配置 test_config.yaml
```yaml
mini_program:
project_path: "E:/path/to/your/uniapp/dist/dev/mp-weixin" # uni-app 编译产物目录
dev_tool_path: "C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat"
```
## 运行
```bash
pytest tests/web/mini_program/ -v -m p0
```
## 原理
```
pytest 用例
↓ conftest.py: subprocess
node runner.js --action smoke --project-path ...
↓ miniprogram-automator API
微信开发者工具(开启服务端口)
小程序运行
返回 JSON { ok, message, screenshot }
Python 断言
```
## 可用 actions
| action | 参数 | 说明 |
| :--- | :--- | :--- |
| `smoke` | — | 启动小程序并检查首页 |
| `navigate` | `page=/pages/xxx/xxx` | 导航到指定页面 |
| `element` | `element-action=tap/exists` `selector=.class` | 操作/检查元素 |
## 注意事项
- **登录**:首次在开发者工具中手动登录,后续 `miniprogram-automator` 启动默认复用登录态
- **截图**:输出到 `output/screenshots/mini_program/`
- **CI**:微信开发者工具必须安装在 CI 机器上,且需要 GUI 环境(不能纯 headless