How to use the @nut-tree/nut-js.Region function in @nut-tree/nut-js

To help you get started, we’ve selected a few @nut-tree/nut-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sakuli / sakuli / packages / sakuli-legacy / src / context / common / actions / screen.function.spec.ts View on Github external
import {getTimestamp, ScreenApi} from "./screen.function";
import {createRegionClass} from "../region";
import {Project, TestExecutionContext} from "@sakuli/core";
import {SimpleLogger} from "@sakuli/commons";
import {FileType} from "@nut-tree/nut-js/dist/lib/file-type.enum";
import {cwd} from "process";
import {join} from "path";

let ctx: TestExecutionContext;
let project: Project;

const testFilename = "testfile.png";
const testPath = "/test/path";
const testConfidence = 0.99;
const testTimeout = 500;
const expectedRegion = new Region(0, 0, 100, 100);

beforeEach(() => {
    ctx = new TestExecutionContext(new SimpleLogger());
    project = new Project("");
});

describe("ScreenApi", () => {
    it("should call `screen.find` with suitable Region", async () => {
        // GIVEN
        const TestRegion = createRegionClass(ctx, project);
        const testRegion = new TestRegion(0, 0, 100, 100);
        screen.find = jest.fn(() => Promise.resolve(expectedRegion));

        // WHEN
        await ScreenApi.find(testFilename, testPath, testConfidence, testRegion);
github sakuli / sakuli / packages / sakuli-legacy / src / context / common / actions / screen.function.ts View on Github external
return new Promise(async (resolve, reject) => {
            try {
                screen.config.resourceDirectory = path;
                const result = await screen.find(filename, {
                    confidence,
                    searchRegion: new NutRegion(
                        left,
                        top,
                        width,
                        height
                    )
                });
                resolve({
                    left: result.left,
                    top: result.top,
                    width: result.width,
                    height: result.height
                });
            } catch (e) {
                reject(e);
            }
        });
github sakuli / sakuli / packages / sakuli-legacy / src / context / common / actions / mouse.function.ts View on Github external
const toNutRegion = async (region: Region): Promise => {
    return new NutRegion(
        await region.getX() || 0,
        await region.getY() || 0,
        await region.getW() || await ScreenApi.width(),
        await region.getH() || await ScreenApi.height()
    );
};