Aller au contenu principal

Service Robonut

wdio-robonut-service est un package tiers, pour plus d'informations veuillez consulter GitHub | npm

Tested Released

image

Description​

wdio-robonut-service est un service multiplateforme (windows, darwin, linux) avec accès à la souris système, au clavier, au presse-papiers, à l'écran et à la recherche de modèles d'images sur l'écran visible avec nutjs sous le capot. Avec ce service, il est possible d'effectuer des déplacements système, des clics, des copies, des collages, des saisies, etc. Il est possible de vérifier l'existence et d'obtenir les coordonnées d'un modèle d'image, de le glisser-déposer, etc.

Installation​

npm install wdio-robonut-service
Config​
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;
};
};
}
Comme service wdio dans wdio.conf.ts​
import RobotService from 'wdio-robonut-service';

const robotConfig: RobotConfig = {};

export const config: Options.Testrunner = {
//-
services: [[RobotService, robotConfig]],
//-
}
Pour wdio standalone/remote​

exécutez-le une fois après l'initialisation du navigateur

import RobotCommands from 'wdio-robonut-service';

const robotConfig: RobotConfig = {};

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

new RobotDirect(robotConfig).instance()

Utilisation​

Point d'accès principal​
browser.robot
Exemples​
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 };
};
}

Fonctionnalités​

  • Interfaces robot
  • Robot d'image
  • Robot d'élément Dom (par localisateurs)

Contraintes​

  • Fonctionne avec un affichage visible (pas en mode headless)
  • Fonctionne dans un seul thread/instance;

Welcome! How can I help?

WebdriverIO AI Copilot