Skip to content

Repository files navigation

nut.js (Native UI Toolkit) Build Status Greenkeeper badge SonarCloud badge SonarCloud Coverage

Native UI testing / automation with node.js


Built with Robot Built with opencv4nodejs

About

logo

nut.js is a cross-platform native UI testing tool.

It allows for native UI interactions via keyboard and / or mouse, but additionally gives you the possibility to navigate the screen based on image matching.

Sample

The following snippet shows a valid NUT example (on macOS)

"use strict";

const { keyboard, Key, mouse, left, right, up, down } = require("@nut-tree/nut-js");

const square = async () => {
  await mouse.move(right(500));
  await mouse.move(down(500));
  await mouse.move(left(500));
  await mouse.move(up(500));
};

const openSpotlight = async () => {
  await keyboard.pressKey(Key.LeftSuper);
  await keyboard.pressKey(Key.Space);
  await keyboard.releaseKey(Key.Space);
  await keyboard.releaseKey(Key.LeftSuper);
};

describe("Basic test", () => {
  it("Should run a simple test", async () => {
    await square();
    await openSpotlight();
    await keyboard.type("calculator");
    await keyboard.type(Key.Return);
  });
});

Installation

Running

npm i @nut-tree/nut-js

or

yarn add @nut-tree/nut-js

will install nut.js and its required dependencies.

The installation process assumes you do not have an existing OpenCV installation and will try to build it from source via opencv4nodejs.

Building OpenCV from scratch requires a cmake installation.

In case you already have an OpenCV installation (version 3.x.x required, e.g. via brew install opencv@3 or else), you can disable the build process via environment variable:

export OPENCV4NODEJS_DISABLE_AUTOBUILD=1

or

set OPENCV4NODEJS_DISABLE_AUTOBUILD=1

Please make sure to also install all required peer dependencies:

Examples

nut-tree/trailmix contains a set of ready to use examples which demo the usage ot nut.js.

Modules

This list gives an overview on currently implemented and planned functionality. It's work in progress and will undergo constant modification.

Clipboard

  • Copy text to clipboard
  • Paste text from clipboard

Keyboard

  • Support for standard US keyboard layout
  • Support for German special characters

Mouse

  • Support for mouse movement
  • Support for mouse scroll
  • Configurable movement speed
  • Mouse drag

Process

  • Retrieve the region of a process window

Screen

  • findOnScreen
  • waitFor
  • Hooks to trigger actions based on images

Integration

  • Jest

About

Native UI testing / controlling with node

Topics

Resources

Contributing

Stars

2.9k stars

Watchers

23 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages