testdriverai 4.1.27 → 4.1.29

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
@@ -12,7 +12,6 @@ const sdk = require("./sdk");
12
12
  // object is a json representation of the individual yml command
13
13
  // the process turns markdown -> yml -> json -> js function execution
14
14
  const run = async (object, depth) => {
15
-
16
15
  log("debug", { object, depth });
17
16
 
18
17
  // success returns null
@@ -63,7 +62,11 @@ commands:
63
62
  speak(`scrolling ${object.direction}`);
64
63
  log("info", generator.jsonToManual(object));
65
64
  notify(generator.jsonToManual(object, false));
66
- response = await commands.scroll(object.direction, object.amount);
65
+ response = await commands.scroll(
66
+ object.direction,
67
+ object.amount,
68
+ object.method,
69
+ );
67
70
  break;
68
71
  case "wait":
69
72
  speak(`waiting ${object.timeout} seconds`);
@@ -143,6 +146,7 @@ commands:
143
146
  object.text,
144
147
  object.direction,
145
148
  object.distance,
149
+ object.textMatchMethod,
146
150
  object.method,
147
151
  );
148
152
  break;
@@ -154,6 +158,7 @@ commands:
154
158
  object.description,
155
159
  object.direction,
156
160
  object.distance,
161
+ object.method,
157
162
  );
158
163
  break;
159
164
  case "focus-application":
@@ -179,10 +184,10 @@ commands:
179
184
  }
180
185
 
181
186
  let timing = marky.stop(object.command);
182
-
187
+
183
188
  await Promise.all([
184
- sdk.req('ran', { command: object.command, data: object }),
185
- analytics.track("command", { data: object, depth, timing })
189
+ sdk.req("ran", { command: object.command, data: object }),
190
+ analytics.track("command", { data: object, depth, timing }),
186
191
  ]);
187
192
 
188
193
  return response;
package/lib/commands.js CHANGED
@@ -160,18 +160,33 @@ const assert = async (assertion, shouldThrow = false, async = false) => {
160
160
  return handleAssertResponse(response.data);
161
161
  }
162
162
  };
163
- const scroll = async (direction = "down", amount = 300) => {
163
+ const scroll = async (direction = "down", amount = 300, method = "keyboard") => {
164
164
  await redraw.start();
165
165
 
166
166
  amount = parseInt(amount);
167
167
 
168
+ if (method === "mouse") {
169
+ // after experimenting, 200 is a good default for mouse, mostly as mouse will be called only when the user asks for it
170
+ // and that happens when keyboard scrolling cannot do things when there's a pop up that needs to be scrolled over and
171
+ // pop ups are usually smaller and needs a smaller amount of scrolling
172
+ amount = 200;
173
+ }
174
+
168
175
  switch (direction) {
169
176
  case "up":
170
- await robot.keyTap("pageup");
177
+ if (method === "mouse") {
178
+ await robot.scrollMouse(0, amount );
179
+ } else {
180
+ await robot.keyTap("pageup");
181
+ }
171
182
  await redraw.wait(2500);
172
183
  break;
173
184
  case "down":
174
- await robot.keyTap("pagedown");
185
+ if (method === "mouse") {
186
+ await robot.scrollMouse(0, amount * -1);
187
+ } else {
188
+ await robot.keyTap("pagedown");
189
+ }
175
190
  await redraw.wait(2500);
176
191
  break;
177
192
  case "left":
@@ -421,7 +436,7 @@ let commands = {
421
436
  wait: async (timeout = 3000) => {
422
437
  return await delay(timeout);
423
438
  },
424
- "wait-for-image": async (description, timeout = 5000) => {
439
+ "wait-for-image": async (description, timeout = 10000) => {
425
440
  log("info", "");
426
441
  log(
427
442
  "info",
@@ -436,11 +451,8 @@ let commands = {
436
451
  let passed = false;
437
452
 
438
453
  while (durationPassed < timeout && !passed) {
439
- const response = await sdk.req("assert", {
440
- needle: description,
441
- image: await captureScreenBase64(),
442
- });
443
- passed = response.data;
454
+
455
+ passed = await assert(`An image matching the description "${description}" appears on screen.`, false, false);
444
456
 
445
457
  durationPassed = new Date().getTime() - startTime;
446
458
  if (!passed) {
@@ -521,29 +533,38 @@ let commands = {
521
533
  text,
522
534
  direction = "down",
523
535
  maxDistance = 1200,
524
- method = "turbo",
536
+ textMatchMethod = "turbo",
537
+ method = "keyboard"
525
538
  ) => {
526
539
  await redraw.start();
527
540
 
528
541
  log("info", chalk.dim(`scrolling for text: "${text}"...`), true);
529
542
 
530
- try {
531
- // use robot to press CMD+F
532
- await robot.keyTap("f", commandOrControl);
533
- // type the text
534
- await robot.typeString(text);
535
- await redraw.wait(5000);
536
- await robot.keyTap("escape");
537
- } catch (e) {
538
- console.log(e);
539
- throw new AiError(
540
- "Could not find element using browser text search",
541
- true,
542
- );
543
+ if (method === "keyboard") {
544
+ try {
545
+ // use robot to press CMD+F
546
+ await robot.keyTap("f", commandOrControl);
547
+ // keyTap will release the normal keys, but will not release modifier keys
548
+ // so we need to release the modifier keys manually
549
+ robot.keyToggle(commandOrControl, "up");
550
+ // type the text
551
+ await robot.typeString(text);
552
+ await redraw.wait(5000);
553
+ await robot.keyTap("escape");
554
+ } catch (e) {
555
+ console.log(e);
556
+ throw new AiError(
557
+ "Could not find element using browser text search",
558
+ true,
559
+ );
560
+ }
543
561
  }
544
562
 
545
563
  let scrollDistance = 0;
546
564
  let incrementDistance = 300;
565
+ if (method === "mouse") {
566
+ incrementDistance = 200;
567
+ }
547
568
  let passed = false;
548
569
 
549
570
  while (scrollDistance <= maxDistance && !passed) {
@@ -551,7 +572,7 @@ let commands = {
551
572
  "assert/text",
552
573
  {
553
574
  needle: text,
554
- method: method,
575
+ method: textMatchMethod,
555
576
  image: await captureScreenBase64(),
556
577
  },
557
578
  (chunk) => {
@@ -570,7 +591,7 @@ let commands = {
570
591
  ),
571
592
  true,
572
593
  );
573
- await scroll(direction);
594
+ await scroll(direction, incrementDistance, method);
574
595
  scrollDistance = scrollDistance + incrementDistance;
575
596
  }
576
597
  }
@@ -589,6 +610,7 @@ let commands = {
589
610
  description,
590
611
  direction = "down",
591
612
  maxDistance = 10000,
613
+ method = "keyboard",
592
614
  ) => {
593
615
  log(
594
616
  "info",
@@ -600,20 +622,17 @@ let commands = {
600
622
  let incrementDistance = 500;
601
623
  let passed = false;
602
624
 
603
- while (scrollDistance < maxDistance && !passed) {
604
- const response = await sdk.req("assert", {
605
- needle: `An image matching the description "${description}" appears on screen.`,
606
- image: await captureScreenBase64(),
607
- });
625
+ while (scrollDistance <= maxDistance && !passed) {
626
+
627
+ passed = await assert(`An image matching the description "${description}" appears on screen.`, false, false);
608
628
 
609
- passed = response.data;
610
629
  if (!passed) {
611
630
  log(
612
631
  "info",
613
632
  chalk.dim(`scrolling ${direction} ${incrementDistance} pixels...`),
614
633
  true,
615
634
  );
616
- await scroll(direction);
635
+ await scroll(direction, incrementDistance, method);
617
636
  scrollDistance = scrollDistance + incrementDistance;
618
637
  }
619
638
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "4.1.27",
3
+ "version": "4.1.29",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {