快速开始

    智能小程序自动化 SDK 主要包含以下功能:

    • 可以控制小程序跳转到指定页面
    • 可以获取小程序页面数据
    • 可以获取小程序页面元素信息
    • 可以调用 swan 对象上任意接口
    • 基础库版本为 3.40.0 及以上
    • 开发者工具 版本为 2.22.0 及以上
    • 开发者工具已登录且具有项目 appid 的开发权限(也可选择使用)

    引入 SDK 编写控制脚本,参考以下示例:

    1. (async () => {
    2. const smartProgram = await automator.launch({
    3. cliPath: 'path/to/cli',
    4. projectPath: 'path/to/project'
    5. const page = await smartProgram.reLaunch('/pages/component/component');
    6. await page.waitFor(500);
    7. const element = await page.$('.item');
    8. console.log(await element.attribute('class'));
    9. await page.waitFor(200);
    10. console.log(await element.attribute('class'));
    11. })();

    关于 SDK 提供的接口,更多详细用法可以参考 Automator、、Page、。