@weapp-vite/miniprogram-automator 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -4
- package/dist/index.d.mts +6 -1
- package/dist/index.mjs +63 -4304
- package/dist/{launch-IFPMxQYb.mjs → launch-Bd3TZy1I.mjs} +1660 -61
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,7 +1,98 @@
|
|
|
1
1
|
# @weapp-vite/miniprogram-automator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 1. 简介
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
`@weapp-vite/miniprogram-automator` 是面向 `weapp-vite` 生态维护的 `miniprogram-automator` 兼容实现,目标是在保留官方心智模型的前提下,提供更现代的 ESM 导出、类型支持与 headless 调试能力。
|
|
6
|
+
|
|
7
|
+
它同时服务于:
|
|
8
|
+
|
|
9
|
+
- `weapp-ide-cli` 的自动化能力
|
|
10
|
+
- 仓库内 WeChat DevTools 相关 e2e 测试
|
|
11
|
+
- 需要直接连接微信开发者工具 WebSocket 协议的 Node 工具
|
|
12
|
+
|
|
13
|
+
## 2. 特性
|
|
14
|
+
|
|
15
|
+
- 对齐官方常见对象模型:`MiniProgram`、`Page`、`Element`、`Native`
|
|
16
|
+
- 提供 `Launcher` 用于启动、连接和复用 DevTools 会话
|
|
17
|
+
- 支持截图、输入、滚动、点击、页面跳转等自动化操作
|
|
18
|
+
- 默认输出现代 ESM 与完整类型声明
|
|
19
|
+
- 内置二维码打印与解码辅助能力,便于配合登录、连接流程调试
|
|
20
|
+
- 支持 headless 自动化启动入口
|
|
21
|
+
|
|
22
|
+
## 3. 安装
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add -D @weapp-vite/miniprogram-automator
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
> **注意**:运行前仍需要本机安装微信开发者工具,并开启服务端口。
|
|
29
|
+
|
|
30
|
+
## 4. 快速开始
|
|
31
|
+
|
|
32
|
+
### 4.1 连接现有会话
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { Launcher } from '@weapp-vite/miniprogram-automator'
|
|
36
|
+
|
|
37
|
+
const launcher = new Launcher()
|
|
38
|
+
const miniProgram = await launcher.connect({
|
|
39
|
+
wsEndpoint: 'ws://127.0.0.1:9420',
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const page = await miniProgram.currentPage()
|
|
43
|
+
console.log(await page.data())
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 4.2 启动并打开项目
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { Launcher } from '@weapp-vite/miniprogram-automator'
|
|
50
|
+
|
|
51
|
+
const launcher = new Launcher()
|
|
52
|
+
const miniProgram = await launcher.launch({
|
|
53
|
+
projectPath: './dist/build/mp-weixin',
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
await miniProgram.reLaunch('/pages/index/index')
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 4.3 使用页面与元素对象
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { Launcher } from '@weapp-vite/miniprogram-automator'
|
|
63
|
+
|
|
64
|
+
const launcher = new Launcher()
|
|
65
|
+
const miniProgram = await launcher.launch({
|
|
66
|
+
projectPath: './dist/build/mp-weixin',
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const page = await miniProgram.currentPage()
|
|
70
|
+
const button = await page.$('.submit')
|
|
71
|
+
|
|
72
|
+
await button?.tap()
|
|
73
|
+
await page.waitFor(500)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 5. 主要导出
|
|
77
|
+
|
|
78
|
+
| 导出 | 说明 |
|
|
79
|
+
| ------------------------- | ---------------------------------------- |
|
|
80
|
+
| `Launcher` | 启动 DevTools、连接 WebSocket、创建会话 |
|
|
81
|
+
| `MiniProgram` | 小程序级操作入口,如页面跳转、获取当前页 |
|
|
82
|
+
| `Page` | 页面级查询与操作入口 |
|
|
83
|
+
| `Element` | 通用节点对象,支持点击、输入、事件触发 |
|
|
84
|
+
| `Native` | 原生能力桥接 |
|
|
85
|
+
| `launchHeadlessAutomator` | headless 启动辅助函数 |
|
|
86
|
+
|
|
87
|
+
## 6. 本地开发
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pnpm --filter @weapp-vite/miniprogram-automator build
|
|
91
|
+
pnpm --filter @weapp-vite/miniprogram-automator test
|
|
92
|
+
pnpm --filter @weapp-vite/miniprogram-automator typecheck
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 7. 相关链接
|
|
96
|
+
|
|
97
|
+
- 仓库:https://github.com/weapp-vite/weapp-vite
|
|
98
|
+
- `weapp-ide-cli`:[../weapp-ide-cli/README.md](../weapp-ide-cli/README.md)
|
package/dist/index.d.mts
CHANGED
|
@@ -265,6 +265,11 @@ interface ILaunchOptions {
|
|
|
265
265
|
cwd?: string;
|
|
266
266
|
runtimeProvider?: 'devtools' | 'headless';
|
|
267
267
|
}
|
|
268
|
+
interface ILauncherSessionMetadata {
|
|
269
|
+
port: number;
|
|
270
|
+
projectPath: string;
|
|
271
|
+
wsEndpoint: string;
|
|
272
|
+
}
|
|
268
273
|
/** Launcher 的实现。 */
|
|
269
274
|
declare class Launcher {
|
|
270
275
|
launch(options: ILaunchOptions): Promise<any>;
|
|
@@ -301,4 +306,4 @@ declare function isPluginPath(p: string): boolean;
|
|
|
301
306
|
/** extractPluginId 的方法封装。 */
|
|
302
307
|
declare function extractPluginId(p: string): string;
|
|
303
308
|
//#endregion
|
|
304
|
-
export { Automator, Connection, ContextElement, CustomElement, Element, IConnectOptions, ILaunchOptions, InputElement, Launcher, MiniProgram, MovableViewElement, Native, Page, ScrollViewElement, SliderElement, SwiperElement, SwitchElement, TextareaElement, Transport, decodeQrCode, extractPluginId, isPluginPath, printQrCode };
|
|
309
|
+
export { Automator, Connection, ContextElement, CustomElement, Element, IConnectOptions, ILaunchOptions, ILauncherSessionMetadata, InputElement, Launcher, MiniProgram, MovableViewElement, Native, Page, ScrollViewElement, SliderElement, SwiperElement, SwitchElement, TextareaElement, Transport, decodeQrCode, extractPluginId, isPluginPath, printQrCode };
|