@acst11/testbot 中文文档教程
testbotSDK
SDK 仅供内部使用。
测试机器人是一种用于辅助硬件测试自动化的设备。 它提供了一种针对被测设备 (DUT) 远程配置、供电和运行测试套件的机制。
Introduction
本文档旨在描述所有操作,& Testbot SDK 支持的示例。 开始安装 NPM 包并按照下面的入门指南操作。 您可以使用 testbot SDK 来刷新、控制、打开 DUT on
和 off
,甚至在远程测试时记录串行输出。
如果您觉得缺少某些内容、不清楚或可以改进,请在 GitHub 上提出问题。
Installation
安装 testbotSDK NPM 包。
npm install @balena/testbot --save
Getting Started
组装测试机器人后,可以使用测试机器人 SDK 对 DUT 执行操作。
Prerequisites: Import and Instantiating
导入所需的类,并实例化对象以便稍后引用它们。 要在 DUT 上执行操作,testbot 需要学习如何与您的特定测试设备进行交互。
为此,您需要创建一个 DeviceInteractor 类。 按照文档中的示例为您的 DUT 创建您自己的交互器类。
import { TestBotHat } from '@balena/testbot';
import { SomeNewDevice } from './devices';
const testbotHat = new TestBotHat()
const deviceInteractor = SomeNewDevice(testbotHat);
提供对 RaspberryPi
、balenaFin
和 Intel-NUC
类的支持作为参考。 对于入门指南,使用了一个名为 SomeNewDevice
的示例设备,它有一个名为 SomeNewDevice
的类。
Flashing the DUT
要闪存 DUT,请使用 DeviceInteractor
基类中包含的 flashFromeFile()
方法。
import { TestBotHat } from '@balena/testbot';
import { SomeNewDevice } from './devices';
const testbotHat = new TestBotHat()
const deviceInteractor = SomeNewDevice(testbotHat);
deviceInteractor.flashFromFile("./images/balenaOS.img.gz");
Powering ON/OFF the DUT
要重新启动 DUT,请使用 SomeNewDevice
交互器类。
import { TestBotHat } from '@balena/testbot';
import { SomeNewDevice } from './devices';
const testbotHat = new TestBotHat()
const deviceInteractor = SomeNewDevice(testbotHat);
await deviceInteractor.powerOn();
await deviceInteractor.powerOff();
Collecting Serial Output from DUT
import { TestBotHat } from '@balena/testbot';
const testbotHat = new TestBotHat()
const serialOutput = await testbotHat.openDutSerial();
const collectedLogs: any[] = [];
serialOutput?.on('data', (d) => collectedLogs.push(d));
await deviceInteractor.powerOn();
// Wait several seconds and check the logs. The Bluebird library is used to wait.
import * as Bluebird from 'bluebird';
await Bluebird.delay(10000);
console.log(collectedLogs)
作为全面参考,提供了一个示例,说明如何使用 testbot SDK 验证 testbot 硬件作为我们端到端测试的一部分,如 testbot-e2e-test< 所示/code>
应用程序。
Generating documentation for testbotSDK
TestbotSDK 文档是根据 tsdoc doc comment 标准编写的,并使用 生成类型文档。 可以使用以下命令生成 SDK 的文档。 生成的文档可以在 docs/index.html
上查看
npm run docs
testbotSDK
The SDK is for internal use only.
The testbot is a device used to aid in the automation of hardware testing. It provides a mechanism to remotely provision, power, and run test suites against a device under test (DUT).
Introduction
This document aims to describe all operations, & examples supported by the Testbot SDK. Get started by installing the NPM package and following the Getting Started guide below. You can use the testbot SDK to flash, control, turn your DUT on
and off
and even record serial output when testing remotely.
If you feel something is missing, not clear or could be improved, please open an issue on GitHub.
Installation
Install the testbotSDK NPM package.
npm install @balena/testbot --save
Getting Started
After assembling your testbot, the testbot SDK can be used to perform operations on the DUT.
Prerequisites: Import and Instantiating
Import the required classes, and instantiate objects to refer to them later. To perform operations on the DUT, testbot needs to learn how to interact with your specifc test device.
For that you need to create a DeviceInteractor class. Follow the example in the documentation to create your own interactor class for your DUT.
import { TestBotHat } from '@balena/testbot';
import { SomeNewDevice } from './devices';
const testbotHat = new TestBotHat()
const deviceInteractor = SomeNewDevice(testbotHat);
Support for RaspberryPi
, balenaFin
and Intel-NUC
classes are provided as reference. For the getting started guide an example device called SomeNewDevice
, which has a class named SomeNewDevice
, is used.
Flashing the DUT
To flash the DUT, use the method flashFromeFile()
method included in the base DeviceInteractor
class.
import { TestBotHat } from '@balena/testbot';
import { SomeNewDevice } from './devices';
const testbotHat = new TestBotHat()
const deviceInteractor = SomeNewDevice(testbotHat);
deviceInteractor.flashFromFile("./images/balenaOS.img.gz");
Powering ON/OFF the DUT
To power cycle the DUT, use the powerOn()
and powerOff()
methods in the SomeNewDevice
interactor class.
import { TestBotHat } from '@balena/testbot';
import { SomeNewDevice } from './devices';
const testbotHat = new TestBotHat()
const deviceInteractor = SomeNewDevice(testbotHat);
await deviceInteractor.powerOn();
await deviceInteractor.powerOff();
Collecting Serial Output from DUT
import { TestBotHat } from '@balena/testbot';
const testbotHat = new TestBotHat()
const serialOutput = await testbotHat.openDutSerial();
const collectedLogs: any[] = [];
serialOutput?.on('data', (d) => collectedLogs.push(d));
await deviceInteractor.powerOn();
// Wait several seconds and check the logs. The Bluebird library is used to wait.
import * as Bluebird from 'bluebird';
await Bluebird.delay(10000);
console.log(collectedLogs)
For a comprehensive reference, there is a provided example of how the testbot SDK is used to verify the testbot hardware as part of our e2e tests, shown in the testbot-e2e-test
application.
Generating documentation for testbotSDK
TestbotSDK documentation is written on the tsdoc doc comment standard and generated using Typedoc. The documentation for the SDK can be generated using the command below. The generated documentation can be viewed on docs/index.html
npm run docs