Install
openclaw skills install api-test-reporterAutomates API testing from interface docs by generating detailed HTML reports with test cases, parameters, responses, and validation results for JSON POST/GE...
openclaw skills install api-test-reporter将接口文档转化为一套完整的自动化测试,生成可视化 HTML 报告,报告包含:
| 场景 | 使用的执行器 |
|---|---|
| 百望 ISP 开放平台接口 | isp-api-tester 的 run_isp_test.py(内置动态签名) |
| 通用 HTTP 接口 | 本 skill 的 run_api_test.py |
generate_report.py 和 report_template.html 被 isp-api-tester 跨 skill 引用。
从 Markdown 文档提取:
如果提供了数据库信息,先执行此步:
发票类型字段规则:
| 票种大类 | invoiceCode | invoiceNumber |
|---|---|---|
| 数电票(31/32/51/59/61/83/84) | ❌ 不传 | E_INV_NUM(20位数电号码) |
| 税控票(01/03/04/08/10/11/14/15) | INV_KIND | INV_NUM |
| 数电纸票(85/86/87/88) | INV_KIND | INV_NUM |
数电票的 invoiceCode 必须完全不传(传空串
""会触发 704 参数为空错误)
| 分组 | 策略 |
|---|---|
| 必填参数验证 | 每个必填字段:缺失1条 + 空字符串1条 |
| 分页参数验证 | 正常值 + 边界值 + 负数 |
| 枚举字段验证 | 每个合法枚举值1条 + 非法值1条 |
| 日期范围筛选 | 正常范围 + 起止倒置 + 格式错误 |
| 状态/标记字段 | 每个合法值各1条 |
| 综合多条件组合 | 2~3字段组合 + 全量字段组合 |
| 边界与异常参数 | 超长字段 + 空body + 类型错误 |
正向用例(expect success=true)的入参字段值必须从数据库获取真实值。
ISP 接口(需要动态签名):
python ~/.workbuddy/skills/isp-api-tester/scripts/run_isp_test.py --config test_config_xxx.json --output ./
通用 HTTP 接口:
python ~/.workbuddy/skills/api-test-reporter/scripts/run_api_test.py --config test_config.json --output ./
| 文件 | 说明 |
|---|---|
test_report_<method>_<timestamp>.html | 可视化报告(双击打开) |
__REPORT_DATA__.js | 报告数据文件(与 HTML 同目录,不可删) |
test_results_<method>_<timestamp>.json | 原始结果 JSON |
{
"meta": {
"title": "接口测试报告标题",
"base_url": "http://host/api/endpoint",
"method": "baiwang.input.invoice.queryinvoicepool",
"version": "6.0",
"timeout": 30,
"http_method": "POST",
"url_params": {},
"isp_auth": {
"appKey": "1000139",
"appSecret": "xxx",
"username": "cpy001",
"password": "Aa123456.",
"userSalt": "xxx"
}
},
"fixed_params": {
"taxNo": "91440606MA4WHN8C8X"
},
"db_fixture": {
"connection": {
"host": "10.115.96.247", "port": 3306,
"user": "jxindependent", "password": "Xj2zCkLJXTkEJ5j",
"database": "jxindependent0", "charset": "utf8mb4"
},
"queries": [
{
"name": "tax_invoice_sample",
"sql": "SELECT INV_KIND, INV_NUM FROM bw_jms_main1 WHERE INV_TYPE='01' LIMIT 1",
"mapping": {
"invoiceCode": "INV_KIND",
"invoiceNumber": "INV_NUM"
}
}
]
},
"test_cases": [
{
"id": "TC_001",
"group": "正常流程",
"name": "按发票号码查询",
"desc": "使用数据库真实发票号码查询",
"body": {
"invoiceCode": "{{invoiceCode}}",
"invoiceNumber": "{{invoiceNumber}}"
},
"expect": {
"success": true
}
},
{
"id": "TC_010",
"group": "异常参数",
"name": "缺少必填参数 taxNo",
"desc": "不传 taxNo,期望返回 success=false",
"remove_fixed": ["taxNo"],
"body": {},
"expect": {
"success": false
}
}
]
}
expect 校验规则速查| 字段 | 类型 | 说明 |
|---|---|---|
success | bool | 校验响应体 success 字段值 |
response.{field} | any | 校验 response 节点下的字段,如 "response.invoiceType": "31" |
model.{field} | any | 校验 model 节点下的字段 |
has_response | bool | 期望 response/model 字段存在且非 null |
check_page_data | bool | 期望返回列表/分页数据 |
error_field_exists | bool | 期望 errorResponse 字段存在 |
custom_checks | list | 自定义路径校验(见下方) |
不使用 http_status 字段(百望 ISP 接口测试不校验 HTTP 状态码)。
success=true → 自动校验 invoiceList/response/model 非空success=false → 只校验 success 字段,不校验数据"custom_checks": [
{"path": "response.invoiceType", "op": "eq", "value": "31"},
{"path": "errorResponse.code", "op": "exists"},
{"path": "response", "op": "contains", "value": "invoiceNo"}
]
支持 op:eq / ne / contains / exists / not_exists / gt / lt
"success": true)的入参必须从数据库获取真实值pageNum 参数"remove_fixed": ["字段名"]report_template.html:固定 HTML 骨架,不含测试数据,CSS/JS 全部内嵌__REPORT_DATA__.js:测试结果 JS 变量赋值文件(var reportData = {...})<script src="__REPORT_DATA__.js"> 加载数据并渲染file:// 协议下 CORS 会阻止 fetch 本地文件)pip install requests pymysql