跳至主要内容

Robonut 服务

wdio-robonut-service 是一个第三方包,更多信息请参见 GitHub | npm

Tested Released

image

描述

wdio-robonut-service 是一个跨平台(Windows、Darwin、Linux)服务,可以使用系统鼠标、键盘、剪贴板、屏幕,并在可见屏幕上搜索图像模板 nutjs。使用此服务可以执行系统移动、点击、复制、粘贴、输入等操作。可以检查图像模板是否存在并获取其坐标,对其进行拖放等等。

安装

npm install wdio-robonut-service
配置
interface RobotConfig {
mouseConfig?: { autoDelayMs: number; mouseSpeed: number };
screenConfig?: { confidence: number; autoHighlight: boolean; highlightDurationMs: number; highlightOpacity: number; resourceDirectory: string };
keyboardConfig?: { autoDelayMs: number };
imageFinder?: {
confidence?: number;
providerData?: {
methodType?: MethodNameType;
scaleSteps?: Array<number>;
searchMultipleScales?: boolean;
isRotation: boolean,
rotationOption?: { range?: number; overLap?: number; minDstLength?: number };
debug?: boolean;
roi?: Region;
};
};
}
像 wdio 服务一样在 wdio.conf.ts 中
import RobotService from 'wdio-robonut-service';

const robotConfig: RobotConfig = {};

export const config: Options.Testrunner = {
//-
services: [[RobotService, robotConfig]],
//-
}
适用于 wdio 独立/远程

在浏览器初始化后执行它一次

import RobotCommands from 'wdio-robonut-service';

const robotConfig: RobotConfig = {};

new RobotCommands(browser, robotConfig).addCommands()
独立
const robotConfig: RobotConfig = {};

new RobotDirect(robotConfig).instance()

用法

主要访问点
browser.robot
示例
async function dragAndDropImage(imageDrag: ImageElement,imageDrop: ImageElement, timeout: number = 10000) {
await browser.robot.image.dragAndDrop(
{ pathToImage: imageDrag.pathToImage},
{ pathToImage: imageDrop.pathToImage},
{ highLight: timeout/10 , waitTimeout:timeout });
}

async function dragAndDropImageWithNestedImage(imageDrag: ImageElement,imageDrop: ImageElement, timeout: number = 10000 ) {
await browser.robot.image.dragAndDrop(
{ pathToImage: imageDrag.pathToImage, pathToNestedImage: imageDrag.pathToNestedImage },
{ pathToImage: imageDrop.pathToImage, pathToNestedImage: imageDrop.pathToNestedImage },
{ highLight: timeout/10 , waitTimeout:timeout },
);
}

async function clickImage(image: ImageElement,
options: WaitUntilOptions = { interval: 2500, timeout: 10000 }) {
await browser.robot.image.waitForImageDisplayed(image, options);
const location = await browser.robot.image.finder.findMatch({ needle: image.pathToImage });
const point = await browser.robot.rect.centerOf(location.location);
await browser.robot.mouse.move(await browser.robot.rect.straightTo(point));
await browser.robot.mouse.click(Button.LEFT);
}

async function isWaitForImageDisplayed(image: ImageElement,
options: WaitUntilOptions = { interval: 2500, timeout: 10000 }) {
try {
return (await browser.waitUntil(
async () => {
return !!(await browser.robot.image.finder.findMatch({ needle: image.pathToImage })).location;
}, options
)) as true;
} catch {
return false;
}
}

API

    interface Browser {
robot: {
rect: {
straightTo: (target: Point | Promise<Point>) => Promise<Point[]>;
centerOf: (target: Region | Promise<Region>) => Promise<Point>;
randomPointIn: (target: Region | Promise<Region>) => Promise<Point>;
};
image: {
finder: TemplateMatchingFinder;
reader: { imageResource: (fileName: string) => Promise<Image>; loadImage: (parameters: string) => Promise<Image>; saveImage: (parameters: ImageWriterParameters) => Promise<void> };
clickImage: (image: ImageElement, options: WaitUntilOptions) => Promise<void>;
isWaitForImageDisplayed: (image: ImageElement, options?: WaitUntilOptions) => Promise<boolean>;
waitForImageDisplayed: (image: ImageElement, options?: WaitUntilOptions) => Promise<true | void>;
highlightDisplayedImage: (image: ImageElement, options?: WaitUntilOptions & { highLight?: number }) => Promise<void>;
dragAndDrop: (dragImage: ImageElement, dropImage: ImageElement, options?: RobotDragAndDropType) => Promise<void>;
};
mouse: MouseClass;
screen: ScreenClass;
keyboard: KeyboardClass;
windowApiProvider: WindowProviderInterface;
clipboard: { sys: SysClipboard; virt: ClipboardClass };
};
}

功能

  • 机器人接口
  • 图像机器人
  • DOM 元素机器人(通过定位器)

限制

  • 使用可见显示(非无头)
  • 在一个线程/实例中工作;

欢迎!我如何帮助您?

WebdriverIO AI Copilot