testdriverai 4.2.12 → 4.2.14

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/commander.js CHANGED
@@ -8,6 +8,19 @@ const notify = require("./notify");
8
8
  const analytics = require("./analytics");
9
9
  const marky = require("marky");
10
10
  const sdk = require("./sdk");
11
+ const outputs = require("./outputs");
12
+
13
+ // replace all occurances of ${OUTPUT.ls} with outputs.get("ls") in every possible property of the `object`
14
+ // this is a recursive function that will go through all the properties of the object
15
+ const replaceOutputs = (obj) => {
16
+ for (let key in obj) {
17
+ if (typeof obj[key] === "object") {
18
+ replaceOutputs(obj[key]);
19
+ } else if (typeof obj[key] === "string") {
20
+ obj[key] = obj[key].replace(/\${OUTPUT\.(.*?)}/g, (_, match) => outputs.get(match));
21
+ }
22
+ }
23
+ };
11
24
 
12
25
  // object is a json representation of the individual yml command
13
26
  // the process turns markdown -> yml -> json -> js function execution
@@ -37,6 +50,11 @@ commands:
37
50
  keys: [command, space]
38
51
  \`\`\``;
39
52
  } else {
53
+
54
+
55
+
56
+ replaceOutputs(object);
57
+
40
58
  let copy = JSON.parse(JSON.stringify(object));
41
59
 
42
60
  marky.mark(object.command);
@@ -178,6 +196,13 @@ commands:
178
196
  notify(generator.jsonToManual(object, false));
179
197
  response = await commands.assert(object.expect, object.async);
180
198
  break;
199
+ case "exec":
200
+ speak(`exec ${object.cli}`);
201
+ logger.info(generator.jsonToManual(object));
202
+ notify(generator.jsonToManual(object, false));
203
+ response = await commands.exec(object.cli, object.stderr, object.silent);
204
+ outputs.set(object.output, response);
205
+ break;
181
206
  default:
182
207
  throw new Error(`Command not found: ${object.command}`);
183
208
  }
package/lib/commands.js CHANGED
@@ -10,7 +10,7 @@ const {
10
10
  const keymap = require("./keymap");
11
11
  const { focusApplication } = require("./focus-application");
12
12
  const fs = require("fs").promises; // Using the promises version for async operations
13
- const robot = require("robotjs");
13
+ const robot = require("testdriverai-robotjs");
14
14
  const { findTemplateImage } = require("./subimage/index");
15
15
  const { cwd } = require("node:process");
16
16
  const path = require("path");
@@ -24,6 +24,8 @@ const {
24
24
  createMarkdownStreamLogger,
25
25
  } = require("./logger");
26
26
  const { emitter, events } = require("./events.js");
27
+ const util = require('util');
28
+ const exec = util.promisify(require('child_process').exec);
27
29
 
28
30
  const niceSeconds = (ms) => {
29
31
  return Math.round(ms / 1000);
@@ -363,7 +365,10 @@ let commands = {
363
365
  type: async (string, delay = 500) => {
364
366
  await redraw.start();
365
367
  string = string.toString();
366
- if (delay > 0)
368
+ // there is a bug in robotjs that causes repeated characters to only be typed once
369
+ // so we need to check for repeated characters and type them slowly if so
370
+ const hasRepeatedChars = /(.)\1/.test(string);
371
+ if (delay > 0 && hasRepeatedChars)
367
372
  await robot.typeStringDelayed(string, delay);
368
373
  else
369
374
  await robot.typeString(string);
@@ -659,6 +664,26 @@ let commands = {
659
664
  assert: async (assertion, async = false) => {
660
665
  return await assert(assertion, true, async);
661
666
  },
667
+ exec: async (cli_command, use_stderr = false, silent = false) => {
668
+
669
+ let args = {};
670
+ if (silent) {
671
+ args = { stdio: [] };
672
+ }
673
+
674
+ const { stdout, stderr } = await exec(cli_command, args);
675
+
676
+ if (!silent) {
677
+ logger.info(chalk.dim(stdout), true);
678
+ }
679
+
680
+ if (use_stderr) {
681
+ return stderr;
682
+ } else {
683
+ return stdout;
684
+ }
685
+
686
+ }
662
687
  };
663
688
 
664
689
  module.exports = { commands, assert };
@@ -3,7 +3,7 @@ const path = require("path");
3
3
  const { execSync } = require("child_process");
4
4
  const { platform } = require("./system");
5
5
  const scriptPath = path.join(__dirname, "focusWindow.ps1");
6
- const robot = require("robotjs");
6
+ const robot = require("testdriverai-robotjs");
7
7
  const { logger } = require("./logger");
8
8
 
9
9
  // apple script that focuses on a window
package/lib/outputs.js ADDED
@@ -0,0 +1,12 @@
1
+ let outputs = {};
2
+
3
+ module.exports = {
4
+ get: (key) => {
5
+ return outputs[key] || null;
6
+ },
7
+ set: (key, value) => {
8
+ if (key && value) {
9
+ outputs[key] = value;
10
+ }
11
+ },
12
+ };
package/lib/system.js CHANGED
@@ -4,7 +4,7 @@ const os = require("os");
4
4
  const path = require("path");
5
5
  const screenshot = require("screenshot-desktop");
6
6
  const si = require("systeminformation");
7
- const robot = require("robotjs");
7
+ const robot = require("testdriverai-robotjs");
8
8
  const sharp = require("sharp");
9
9
  const { emitter, events } = require("./events.js");
10
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "4.2.12",
3
+ "version": "4.2.14",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -38,7 +38,7 @@
38
38
  "odiff-bin": "^3.1.2",
39
39
  "prompts": "^2.4.2",
40
40
  "remark-parse": "^11.0.0",
41
- "robotjs": "^0.6.0",
41
+ "testdriverai-robotjs": "^0.6.0",
42
42
  "sanitize-filename": "^1.6.3",
43
43
  "say": "^0.16.0",
44
44
  "screenshot-desktop": "^1.15.0",