← 返回
未分类 中文

微信小程序自动化测试

WeChat Mini Program automation testing toolkit. Supports launching DevTools, page navigation, element interaction, screenshots, console log reading, and more...
微信小程序自动化测试工具包,支持启动开发者工具、页面导航、元素交互、截图、读取控制台日志等功能。
eumenides-k eumenides-k 来源
未分类 clawhub v1.0.0 1 版本 99628.4 Key: 无需
★ 9
Stars
📥 3,037
下载
💾 937
安装
1
版本
#latest

概述

WeChat Mini Program Automation Testing

CRITICAL: Batch Execution Rule

ALWAYS write a single Python script that uses WeappTestRunner to batch ALL operations, then execute it with ONE python call.

Each tool call costs ~30-60s overhead. A test with 10 individual CLI calls takes 5-15 minutes; the same 10 operations batched into one script take ~5 seconds.

Execution pattern

  1. Plan all operations the user needs
  2. Write a single Python script using WeappTestRunner
  3. Run with one python command
  4. Read output and report results

Example

import sys
sys.path.insert(0, r"path_to_weapp-automation_skill\scripts")
from weapp_automation import AutomationConfig, WeappTestRunner

config = AutomationConfig(
    project_path=r"path_to_your_miniapp\my_mini_app",
    ws_endpoint="ws://localhost:9420"
)

runner = WeappTestRunner(config)
results = (runner
    .navigate("pages/index/index")
    .wait(2)
    .screenshot("home.png")
    .click(".category-item")
    .wait(1)
    .screenshot("after_click.png")
    .get_results())

print(runner.get_summary())
for r in results:
    print(r)

Save as a .py file and run with python script.py.


Prerequisites

  1. Install: npm install -g miniprogram-automator
  2. Open WeChat DevTools -> Settings -> Security Settings -> Enable "Service Port"
  3. Ensure the project is imported into DevTools

CLI paths:

  • macOS: /Applications/wechatwebdevtools.app/Contents/MacOS/cli
  • Windows: C:\Program Files (x86)\Tencent\微信web开发者工具\cli.bat

WeappTestRunner Chainable Methods

MethodDescription
---------------------
.navigate(page_path)Navigate to a page
.click(selector)Tap an element
.input(selector, text)Type text into an input field
.screenshot(filename)Take a screenshot
.scroll(selector, direction, distance)Scroll an element
.get_wxml(selector)Extract WXML DOM structure
.get_data(path)Read page data
.wait(seconds)Wait for a duration
.run()Execute all queued steps
.get_results()Execute and return results list
.get_summary()Return pass/fail summary dict

Other APIs

  • WeappAutomation - Single-step API for one-off operations
  • WeappLauncher - Launch/close WeChat DevTools
  • ConsoleReader - Read and analyze console logs
  • PerformanceMonitor - Collect performance metrics
  • TestScenarios - Pre-built test scenario templates (smoke, navigation, form, UI regression, user journey)

For detailed usage, parameters, and examples of all APIs, see references/api_reference.md.


Script Inventory

ScriptPurpose
-----------------
scripts/weapp_launcher.pyLaunch/close WeChat DevTools
scripts/weapp_automation.pyCore automation engine (batch + single-step)
scripts/console_reader.pyConsole log reading and analysis
scripts/test_scenarios.pyPre-defined test scenario templates

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 05:47 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 675 📥 325,236
ai-agent

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,225 📥 267,635
ai-agent

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,376 📥 320,164