CukeTest自动化API
CukeTest 提供了一个专用库 cuketest,用于操作自身界面和获取运行信息。  
注意:此库仅用于自动化 CukeTest 本身。若需自动化其他应用,请使用以
"leanpro."为前缀的自动化 API,详见 附录:CukeTest自动化API。
如何引入
可以通过以下方式引入 cuketest 库,或直接在 CukeTest 中通过“工具箱” -> “Cucumber” 拖拽生成相关操作:
JavaScript
Python
const { CukeTest } = require("cuketest");from leanproAuto import CukeTestcuketest 库概览
cuketest 库主要提供一个 CukeTest 对象,类型定义如下:
JavaScript
Python
export class CukeTest {
    static minimize(): void;
    static maximize(): void;
    static restore(): void;
    static connect(options: ClientConnectOptions, caps?: DesiredCapabilities | ICapabilities): Promise<IAuto>;
    static info(): Promise<RunInfo>;
}class CukeTest(SyncBase):
    def minimize() -> None
    def maximize() -> None
    def restore() -> None
    def info(key: Optional[str]=None) -> TypedDict示例:在测试运行期间最小化 CukeTest 窗口,并在测试完成后恢复:
JavaScript
Python
const { CukeTest } = require("cuketest");
CukeTest.minimize();
// 执行测试操作
CukeTest.restore();from leanproAuto import CukeTest
CukeTest.minimize()
# 执行测试操作
CukeTest.restore()minimize()
最小化 CukeTest 窗口。
- 返回值: 不返回任何值。
maximize()
最大化 CukeTest 窗口。
- 返回值: 不返回任何值。
restore()
将 CukeTest 窗口恢复到正常大小,等效于手动点击窗口的“还原”操作。
- 返回值: 不返回任何值。
connect(options: ClientConnectOptions, caps?: DesiredCapabilities)
连接到远程自动化执行端(Worker),返回远程自动化的 auto 对象。
更多说明请参考:远程自动化。
info()
获取当前运行时的相关信息,返回一个异步的 RunInfo 对象。
- 返回值:Promise<RunInfo>,返回一个RunInfo类型对象。
运行时信息 RunInfo
调用 CukeTest.info() 后返回的对象结构如下:
JavaScript
interface RunInfo {
    readonly argv: string[];  // 启动时的命令行参数
    readonly profile: Profile;  // 当前运行配置对象
}- argv(- string[]):启动 CukeTest 时使用的命令行参数,例如- ["--run", "--format", "html"]。
- profile(- Profile):当前执行使用的运行配置对象。
运行配置对象 Profile
运行配置对象的定义如下:
JavaScript
interface Profile {
    name: string,
    format: string[],
    out: string,
    screenId: string,
    screenName: string,
    runItems: string[],
    custom: string
}字段说明:
| 字段 | 类型 | 描述 | 
|---|---|---|
| name | string | 运行配置的名称 | 
| format | string[] | 报告输出格式,支持选项见 运行配置:报告格式 | 
| out | string | 报告输出目录,未指定时默认为项目的 reports文件夹 | 
| screenId | string | 录制运行视频的屏幕编号,未设置时不录制 | 
| screenName | string | 录制屏幕的名称,作用同 screenId | 
| runItems | string[] | 指定运行的 feature 文件或文件夹 | 
| custom | string | 自定义运行参数 | 
比如,在脚本运行中希望获取当前运行配置的名称,则可以写作如下:
JavaScript
Python
const { CukeTest } = require("cuketest");
let info = await CukeTest.info();
console.log(`当前运行配置的名称为: ${info.profile.name}`)from leanproAuto import CukeTest
info = CukeTest.info()
print(f"当前运行配置名称为: {info['profile']['name']}")