bat-driver

6.7.5 • Public • Published

Bat Driver

Bat Driver 是智能小程序自动化测试引擎 betterAutoTest 的 client lib 库,提供了一系列的 API 用于操控智能小程序。

快速开始

Node.js

const BatDriver = require('bat-driver');
const fs = require('fs');

const agentInfo = {host: 'localhost', port: 8090};
const smartappKey = 'ccccccKCYawUcfCxivhfmhhhCICGK0IX'; // 被测小程序的 appkey

let driver;
let res;

const main = async () => {
    try {
        // 初始化 driver
        driver = new BatDriver();
        await driver.init(agentInfo);

        // 获取当前在连的空闲设备
        res = await driver.device.idle({type: 'android'}); 
        if (0 === res.length) {
            console.log('无设备连接');
            process.exit();
        }

        // 设定被测设备
        driver.device.set({type: 'android', id: res[0]});

        // 设定被测小程序
        driver.smartapp.set({host: 'baiduboxapp', type: 'swan', id: smartappKey});

        // 打开小程序
        await driver.smartapp.open();

        // 获取页面的 dom 树
        await driver.smartapp.source()

        // 关闭 driver
        driver.close();
    }
    catch (err) {
        console.log('调用异常', err.message);
    }
}

main();

API 列表

设备管理

device.idle 获取空闲设备列表
参数说明
参数名 类型 是否必填 默认值 说明
type string - 设备类型:android | ios
调用示例
await driver.device.idle({type: 'android'});
返回示例
['123b9db9']
device.list 获取设备列表
参数说明
参数名 类型 是否必填 默认值 说明
type string - 设备类型:android | ios
调用示例
await driver.device.list({type: 'android'});
返回示例
['123b9db9']
device.get 获取指定设备信息
参数说明:无参数
调用示例
await driver.device.get();
返回示例
{smartapps: {}}
device.set 指定设备
参数说明
参数名 类型 是否必填 默认值 说明
type string - 设备类型:android | ios
id number - 设备id
调用示例
await driver.device.set({type: 'android', id: '123b9db9'});
返回示例:无返回值

小程序操作

smartapp.set 指定小程序
参数说明
参数名 类型 是否必填 默认值 说明
host string - baiduboxapp
type string - 小程序传 swan,小游戏传 swangame
id number - 小程序 appkey
调用示例
await driver.smartapp.set();
返回示例:无返回
smartapp.open 打开小程序
参数说明:无参数
调用示例
await driver.smartapp.open();
返回示例
true

测试

npm run test

如何贡献

联系我们

维护者

邱立楷

讨论

百度Hi讨论群:2148505

Readme

Keywords

none

Package Sidebar

Install

npm i bat-driver

Weekly Downloads

25

Version

6.7.5

License

MIT

Unpacked Size

81.2 kB

Total Files

18

Last publish

Collaborators

  • sharenaive