Skip to content

Commit f9420fd

Browse files
authored
Merge pull request #55 from nut-tree/develop
Release 1.0.0
2 parents c779202 + e8f2313 commit f9420fd

35 files changed

+1362
-651
lines changed

README.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# nut.js (Native UI Toolkit) [![Build Status](https://travis-ci.com/nut-tree/nut.js.svg?branch=master)](https://travis-ci.com/nut-tree/nut.js) [![Greenkeeper badge](https://badges.greenkeeper.io/nut-tree/nut.js.svg)](https://greenkeeper.io/) [![SonarCloud badge](https://sonarcloud.io/api/project_badges/measure?project=nut-tree%3Anut.js&metric=alert_status)](https://sonarcloud.io/dashboard?id=nut-tree%3Anut.js) [![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=nut-tree%3Anut.js&metric=coverage)](https://sonarcloud.io/component_measures?id=nut-tree%3Anut.js&metric=coverage)
22
<p align="center">
3-
Native UI testing / controlling with node.js
3+
Native UI testing / automation with node.js
44
</p>
55
<br/>
66
<p align="center">
7-
<a target="_blank" href="http://getrobot.net">
7+
<a target="_blank" href="https://robotjs.io/">
88
<img src="https://img.shields.io/badge/Built_with-ROBOT-C86414.svg?style=flat-square" alt="Built with Robot" />
99
</a>
1010
<a target="_blank" href="https://github.com/justadudewhohacks/opencv4nodejs">
@@ -28,13 +28,13 @@ The following snippet shows a valid NUT example (on macOS)
2828
```js
2929
"use strict";
3030

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

3333
const square = async () => {
34-
await mouse.move(movement.right(500));
35-
await mouse.move(movement.down(500));
36-
await mouse.move(movement.left(500));
37-
await mouse.move(movement.up(500));
34+
await mouse.move(right(500));
35+
await mouse.move(down(500));
36+
await mouse.move(left(500));
37+
await mouse.move(up(500));
3838
};
3939

4040
const openSpotlight = async () => {
@@ -55,6 +55,43 @@ describe("Basic test", () => {
5555

5656
```
5757

58+
# Installation
59+
60+
Running
61+
62+
```bash
63+
npm i @nut-tree/nut-js
64+
```
65+
66+
or
67+
68+
```bash
69+
yarn add @nut-tree/nut-js
70+
```
71+
72+
will install nut.js and its required dependencies.
73+
74+
The installation process assumes you do not have an existing OpenCV installation and will try to build it from source via [opencv4nodejs](https://github.com/justadudewhohacks/opencv4nodejs).
75+
76+
Building OpenCV from scratch requires a [cmake](https://cmake.org/) installation.
77+
78+
In case you already have an OpenCV installation (version 3.x.x required, e.g. via `brew install opencv@3` or [else](https://docs.opencv.org/3.4/df/d65/tutorial_table_of_content_introduction.html)), you can disable the build process via environment variable:
79+
80+
```bash
81+
export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
82+
```
83+
84+
or
85+
86+
```bash
87+
set OPENCV4NODEJS_DISABLE_AUTOBUILD=1
88+
```
89+
90+
Please make sure to also install all required peer dependencies:
91+
92+
- [opencv4nodejs](https://github.com/justadudewhohacks/opencv4nodejs#how-to-install)
93+
- [robotjs](http://robotjs.io/docs/building)
94+
5895
# Examples
5996

6097
[nut-tree/trailmix](https://github.com/nut-tree/trailmix) contains a set of ready to use examples which demo the usage ot nut.js.
@@ -88,8 +125,8 @@ It's work in progress and will undergo constant modification.
88125
## Screen
89126

90127
- [x] findOnScreen
91-
- [ ] waitFor
92-
- [ ] Hooks to trigger actions based on images
128+
- [x] waitFor
129+
- [x] Hooks to trigger actions based on images
93130

94131
## Integration
95132

index.e2e.spec.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { assert, Key, keyboard, Location, mouse, movement, screen } from "./index";
1+
import { assert, centerOf, Key, keyboard, mouse, screen, straightTo } from "./index";
22

33
const openXfceMenu = async () => {
4-
const menu = await screen.find("menu.png");
5-
await mouse.move(await movement.straightTo(Location.centerOf(menu)));
4+
await mouse.move(straightTo(centerOf(screen.find("menu.png"))));
65
await mouse.leftClick();
76
await mouse.leftClick();
87
};
@@ -14,22 +13,18 @@ const run = async (cmd: string) => {
1413
};
1514

1615
const calculate = async () => {
17-
const plus = await screen.find("plus.png");
18-
await mouse.move(await movement.straightTo(Location.centerOf(plus)));
16+
await mouse.move(straightTo(centerOf(screen.find("plus.png"))));
1917
await mouse.leftClick();
20-
const one = await screen.find("one.png");
21-
await mouse.move(await movement.straightTo(Location.centerOf(one)));
18+
await mouse.move(straightTo(centerOf(screen.find("one.png"))));
2219
await mouse.leftClick();
23-
const zero = await screen.find("zero.png");
24-
await mouse.move(await movement.straightTo(Location.centerOf(zero)));
20+
await mouse.move(straightTo(centerOf(screen.find("zero.png"))));
2521
await mouse.leftClick();
2622
await mouse.leftClick();
2723
await keyboard.type(Key.Enter);
2824
};
2925

3026
const close = async () => {
31-
const x = await screen.find("close.png");
32-
await mouse.move(await movement.straightTo(Location.centerOf(x)));
27+
await mouse.move(straightTo(centerOf(screen.find("close.png"))));
3328
await mouse.leftClick();
3429
};
3530

index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,40 @@ import { Assert } from "./lib/assert.class";
44
import { Clipboard } from "./lib/clipboard.class";
55
import { Keyboard } from "./lib/keyboard.class";
66
import { Mouse } from "./lib/mouse.class";
7-
import { Movement } from "./lib/movement.class";
7+
import { createMovementApi } from "./lib/movement.function";
88
import { Screen } from "./lib/screen.class";
99
import { LineHelper } from "./lib/util/linehelper.class";
1010

1111
export { jestMatchers } from "./lib/expect/jest.matcher.function";
1212
export { Image } from "./lib/image.class";
1313
export { Key } from "./lib/key.enum";
14-
export { Location } from "./lib/location.class";
14+
export { centerOf, randomPointIn } from "./lib/location.function";
1515
export { LocationParameters } from "./lib/locationparameters.class";
16-
export { Movement } from "./lib/movement.class";
17-
export { MovementType } from "./lib/movementtype.class";
16+
export { linear } from "./lib/movementtype.function";
1817
export { Point } from "./lib/point.class";
1918
export { Region } from "./lib/region.class";
2019

2120
const screenActions = new VisionAdapter();
2221
const nativeActions = new NativeAdapter();
22+
const lineHelper = new LineHelper();
2323

2424
const clipboard = new Clipboard(nativeActions);
2525
const keyboard = new Keyboard(nativeActions);
2626
const mouse = new Mouse(nativeActions);
27-
const movement = new Movement(nativeActions, new LineHelper());
2827
const screen = new Screen(screenActions);
2928
const assert = new Assert(screen);
3029

31-
export { clipboard, keyboard, mouse, movement, screen, assert };
30+
const {straightTo, up, down, left, right} = createMovementApi(nativeActions, lineHelper);
31+
32+
export {
33+
clipboard,
34+
keyboard,
35+
mouse,
36+
screen,
37+
assert,
38+
straightTo,
39+
up,
40+
down,
41+
left,
42+
right,
43+
};

0 commit comments

Comments
 (0)