@nut-tree/nut-js
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.1 • Public • Published

    nut.js (Native UI Toolkit)

    GitHub Actions
    Master Create tagged release
    Develop Create snapshot release

    SonarCloud badge SonarCloud Coverage

    Downloads per month @nut-tree/nut-js

    Console - Developer Tool of the Week

    Please visit

    nutjs.dev

    for detailed documentation and tutorials


    About

    logo

    nut.js is a cross-platform native UI automation / 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.

    Sponsoring

    nut.js is developed with community in mind.

    A huge "Thank you!" goes out to all sponsors who make open source a bit more sustainable!

    Reiss Cashmore Chet Corcos Stephan Petzl


    Mighty browser logo

    Demo

    Check out this demo video to get a first impression of what nut.js is capable of.

    nut.js demo video

    Tutorials

    Please consult the project website at nutjs.dev for in-depth tutorials

    Examples

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

    API Docs

    nut.js provides public API documentation auto-generated by TypeDoc.

    Community

    Feel free to join our Discord community

    Modules

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

    Clipboard

    • [x] Copy text to clipboard
    • [x] Paste text from clipboard

    Keyboard

    • [x] Support for standard US keyboard layout
    • [x] Support for multimedia keys

    Mouse

    • [x] Support for mouse movement
    • [x] Support for mouse scroll
    • [x] Configurable movement speed
    • [x] Mouse drag

    Window

    • [x] List all windows
    • [x] Retrieve active window
    • [x] Retrieve window title
    • [x] Retrieve window size and position

    Screen

    • [x] Find an image on screen (requires an additional provider package like e.g. nut-tree/template-matcher)
    • [x] Find all image occurrences on screen
    • [x] Wait for an image to appear on screen (requires an additional provider package like e.g. nut-tree/template-matcher)
    • [x] Retrieve RGBA color information on screen
    • [x] Hooks to trigger actions based on images (requires an additional provider package like e.g. nut-tree/template-matcher)
    • [x] Highlighting screen regions

    Integration

    • [x] Jest
    • [x] Electron

    Sample

    The following snippet shows a valid nut.js example:

    "use strict";
    
    const { mouse, left, right, up, down, straightTo, centerOf, Region} = 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));
    };
    
    (async () => {
        await square();
        await mouse.move(
            straightTo(
                centerOf(
                    new Region(100, 100, 200, 300)
                )
            )
        );
    })();

    Installation

    Prerequisites

    This section lists runtime requirements for nut.js on the respective target platform.

    Windows

    In order to install nut.js on Windows, please make sure to have the Microsoft Visual C++ Redistributable installed.

    In case you're running Windows 10 N, please make sure to have the Media Feature Pack installed as well.

    macOS

    On macOS, Xcode command line tools are required. You can install them by running

    xcode-select --install

    Attention:

    In case you're experiencing problems like your mouse not moving or your keyboard not typing, please make sure to give the process you're executing your tests with accessibility permissions.

    nut.js will give you a subtle hint in case permissions are lacking:

    ##### WARNING! The application running this script is not a trusted process! Please visit https://github.com/nut-tree/nut.js#macos #####

    When an application wants to use accessibility features, a permission pop-up should be shown. If not, you could try to manually add the application you're running the script from.

    Settings -> Security & Privacy -> Privacy tab -> Accessibility -> Add...

    For example, if you want to execute your node script in e.g. iTerm2, you'd have to add iTerm.app to the list. When running your script from a built-in terminal in e.g. VSCode or IntelliJ, you'd have to add the respective IDE.

    accessibility permissions screen

    Linux

    Depending on your distribution, Linux setups may differ.

    In general, nut.js requires

    • libXtst

    Installation on *buntu distributions:

    sudo apt-get install libxtst-dev

    Setups on other distributions might differ.

    Install nut.js

    Running

    npm i @nut-tree/nut-js

    or

    yarn add @nut-tree/nut-js

    will install nut.js and its required dependencies.

    Snapshot releases

    nut.js also provides snapshot releases which allows to test upcoming features.

    Running

    npm i @nut-tree/nut-js@next

    or

    yarn add @nut-tree/nut-js@next

    will install the most recent development release of nut.js.

    Attention: While snapshot releases are great to work with upcoming features before a new stable release, it is still a snapshot release. Please bear in mind that things might change and / or break on snapshot releases, so it is not recommended using them in production.

    Install

    npm i @nut-tree/nut-js

    DownloadsWeekly Downloads

    4,490

    Version

    2.1.1

    License

    Apache-2.0

    Unpacked Size

    529 kB

    Total Files

    361

    Last publish

    Collaborators

    • s1hofmann