testdriverai 4.0.28 → 4.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands.js +38 -42
- package/package.json +1 -1
package/lib/commands.js
CHANGED
|
@@ -33,8 +33,8 @@ const commandOrControl = process.platform === 'darwin' ? 'command' : 'control';
|
|
|
33
33
|
const findImageOnScreen = async (relativePath, haystack, restrictToWindow) => {
|
|
34
34
|
let displayMultiple = await getDisplayMultiple();
|
|
35
35
|
|
|
36
|
-
// move the file from filePath to
|
|
37
|
-
let rootpath = path.join(cwd(),
|
|
36
|
+
// move the file from filePath to `testdriver/screenshots`
|
|
37
|
+
let rootpath = path.join(cwd(), `testdriver`, `screenshots`, platform());
|
|
38
38
|
// add .png to relative path if not already there
|
|
39
39
|
if (!relativePath.endsWith('.png')) {
|
|
40
40
|
relativePath = relativePath + '.png';
|
|
@@ -46,7 +46,6 @@ const findImageOnScreen = async (relativePath, haystack, restrictToWindow) => {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
let needle = path.join(rootpath, relativePath);
|
|
49
|
-
let foundWriteLocation = path.join(cwd(), '.testdriver', '.matches', `${new Date().getTime()}-${relativePath}`);
|
|
50
49
|
|
|
51
50
|
const bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
52
51
|
|
|
@@ -114,15 +113,6 @@ const findImageOnScreen = async (relativePath, haystack, restrictToWindow) => {
|
|
|
114
113
|
|
|
115
114
|
bar1.stop();
|
|
116
115
|
|
|
117
|
-
if (foundWriteLocation) {
|
|
118
|
-
// Crop the haystack at the coordinates found in result
|
|
119
|
-
const imageHaystack = await Jimp.read(haystack);
|
|
120
|
-
const croppedImage = imageHaystack.crop(result.x, result.y, result.width, result.height);
|
|
121
|
-
|
|
122
|
-
await croppedImage.writeAsync(foundWriteLocation);
|
|
123
|
-
|
|
124
|
-
result.foundWriteLocation = foundWriteLocation;
|
|
125
|
-
}
|
|
126
116
|
return result;
|
|
127
117
|
|
|
128
118
|
}
|
|
@@ -200,6 +190,37 @@ const scroll = async(direction = 'down', amount = 300) => {
|
|
|
200
190
|
}
|
|
201
191
|
}
|
|
202
192
|
|
|
193
|
+
// perform a mouse click
|
|
194
|
+
const click = async(x, y, button = 'left', click = 'single') => {
|
|
195
|
+
|
|
196
|
+
await redraw.start();
|
|
197
|
+
|
|
198
|
+
log('debug', chalk.dim(`${click} ${button} clicking at ${x}, ${y}...`), true)
|
|
199
|
+
|
|
200
|
+
x = parseInt(x);
|
|
201
|
+
y = parseInt(y);
|
|
202
|
+
|
|
203
|
+
let double = click == 'double' ? true : false;
|
|
204
|
+
robot.moveMouseSmooth(x, y, .1);
|
|
205
|
+
await delay(1000); // wait for the mouse to move
|
|
206
|
+
robot.mouseClick(button, double);
|
|
207
|
+
await redraw.wait(2000);
|
|
208
|
+
return;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const hover = async(x, y) => {
|
|
212
|
+
|
|
213
|
+
await redraw.start();
|
|
214
|
+
|
|
215
|
+
x = parseInt(x);
|
|
216
|
+
y = parseInt(y);
|
|
217
|
+
|
|
218
|
+
await robot.moveMouseSmooth(x, y, .1);
|
|
219
|
+
await redraw.wait(2000);
|
|
220
|
+
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
203
224
|
let commands = {
|
|
204
225
|
// method, levenshein, dice, or combined
|
|
205
226
|
// leven = this is turbo, all around good for text similarity
|
|
@@ -258,35 +279,6 @@ let commands = {
|
|
|
258
279
|
}
|
|
259
280
|
|
|
260
281
|
},
|
|
261
|
-
// perform a mouse click
|
|
262
|
-
click: async(x, y, button = 'left', click = 'single') => {
|
|
263
|
-
|
|
264
|
-
await redraw.start();
|
|
265
|
-
|
|
266
|
-
log('debug', chalk.dim(`${click} ${button} clicking at ${x}, ${y}...`), true)
|
|
267
|
-
|
|
268
|
-
x = parseInt(x);
|
|
269
|
-
y = parseInt(y);
|
|
270
|
-
|
|
271
|
-
let double = click == 'double' ? true : false;
|
|
272
|
-
robot.moveMouseSmooth(x, y, .1);
|
|
273
|
-
await delay(1000); // wait for the mouse to move
|
|
274
|
-
robot.mouseClick(button, double);
|
|
275
|
-
await redraw.wait(2000);
|
|
276
|
-
return;
|
|
277
|
-
},
|
|
278
|
-
hover: async(x, y) => {
|
|
279
|
-
|
|
280
|
-
await redraw.start();
|
|
281
|
-
|
|
282
|
-
x = parseInt(x);
|
|
283
|
-
y = parseInt(y);
|
|
284
|
-
|
|
285
|
-
await robot.moveMouseSmooth(x, y, .1);
|
|
286
|
-
await redraw.wait(2000);
|
|
287
|
-
|
|
288
|
-
return;
|
|
289
|
-
},
|
|
290
282
|
"match-image": async(relativePath, action = 'click', button = 'left', clickType = 'single') => {
|
|
291
283
|
|
|
292
284
|
let image = await captureScreenPNG()
|
|
@@ -299,7 +291,11 @@ let commands = {
|
|
|
299
291
|
throw new AiError(`Image not found: ${relativePath}`)
|
|
300
292
|
} else {
|
|
301
293
|
|
|
302
|
-
|
|
294
|
+
if (action === 'click') {
|
|
295
|
+
await click(result.centerX * displayMultiple, result.centerY * displayMultiple, button, clickType);
|
|
296
|
+
} else if (action === 'hover') {
|
|
297
|
+
await hover(result.centerX * displayMultiple, result.centerY * displayMultiple);
|
|
298
|
+
}
|
|
303
299
|
}
|
|
304
300
|
|
|
305
301
|
},
|