testdriverai 4.1.19 → 4.1.21

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/agent.js CHANGED
@@ -295,7 +295,7 @@ const check = async () => {
295
295
  log.log("info", chalk.dim("checking..."), "testdriver");
296
296
  log.log("info", "");
297
297
 
298
- let thisScreenshot = await system.captureScreenBase64();
298
+ let thisScreenshot = await system.captureScreenBase64(1, false, true);
299
299
  let images = [lastScreenshot, thisScreenshot];
300
300
  let mousePosition = await system.getMousePosition();
301
301
  let activeWindow = await system.activeWin();
@@ -0,0 +1,18 @@
1
+ # Get cumulative total bytes sent and received for each network interface
2
+ $networkInterfaces = Get-WmiObject -Query "SELECT Name, BytesReceivedPerSec, BytesSentPerSec FROM Win32_PerfRawData_Tcpip_NetworkInterface"
3
+
4
+ # Initialize counters
5
+ $totalBytesSent = 0
6
+ $totalBytesReceived = 0
7
+
8
+ # Sum up the cumulative bytes sent and received for all interfaces
9
+ foreach ($interface in $networkInterfaces) {
10
+ $totalBytesSent += $interface.BytesSentPerSec
11
+ $totalBytesReceived += $interface.BytesReceivedPerSec
12
+ }
13
+
14
+ # Calculate the overall total bytes transferred
15
+ $totalNetworkBytes = $totalBytesSent + $totalBytesReceived
16
+
17
+ # Output results in JSON format for parsing in Node.js
18
+ Write-Output "{`"totalBytesSent`": $totalBytesSent, `"totalBytesReceived`": $totalBytesReceived, `"totalNetworkBytes`": $totalNetworkBytes}"
package/lib/redraw.js CHANGED
@@ -29,40 +29,64 @@ async function resetState() {
29
29
  screenHasRedrawn = false;
30
30
  }
31
31
 
32
+ const parseNetworkStats = (thisRxBytes,thisTxBytes) => {
33
+
34
+ diffRxBytes = lastRxBytes !== null ? thisRxBytes - lastRxBytes : 0;
35
+ diffTxBytes = lastTxBytes !== null ? thisTxBytes - lastTxBytes : 0;
36
+
37
+ lastRxBytes = thisRxBytes;
38
+ lastTxBytes = thisTxBytes;
39
+
40
+ measurements.push({ rx: diffRxBytes, tx: diffTxBytes });
41
+
42
+ if (measurements.length > 60) {
43
+ measurements.shift();
44
+ }
45
+
46
+ let avgRx = measurements.reduce((acc, m) => acc + m.rx, 0) / measurements.length;
47
+ let avgTx = measurements.reduce((acc, m) => acc + m.tx, 0) / measurements.length;
48
+
49
+ let stdDevRx = Math.sqrt(measurements.reduce((acc, m) => acc + Math.pow(m.rx - avgRx, 2), 0) / measurements.length);
50
+ let stdDevTx = Math.sqrt(measurements.reduce((acc, m) => acc + Math.pow(m.tx - avgTx, 2), 0) / measurements.length);
51
+
52
+ let zIndexRx = stdDevRx !== 0 ? (diffRxBytes - avgRx) / stdDevRx : 0;
53
+ let zIndexTx = stdDevTx !== 0 ? (diffTxBytes - avgTx) / stdDevTx : 0;
54
+
55
+ if ((zIndexRx < 0 && zIndexTx < 0) ) {
56
+ networkSettled = true;
57
+ } else {
58
+ networkSettled = false;
59
+ }
60
+ }
61
+
32
62
  async function updateNetwork() {
33
- si.networkStats().then(data => {
34
- let thisRxBytes = data[0].rx_bytes;
35
- let thisTxBytes = data[0].tx_bytes;
36
-
37
- diffRxBytes = lastRxBytes !== null ? thisRxBytes - lastRxBytes : 0;
38
- diffTxBytes = lastTxBytes !== null ? thisTxBytes - lastTxBytes : 0;
39
-
40
- lastRxBytes = thisRxBytes;
41
- lastTxBytes = thisTxBytes;
42
-
43
- measurements.push({ rx: diffRxBytes, tx: diffTxBytes });
44
-
45
- if (measurements.length > 60) {
46
- measurements.shift();
63
+
64
+ const { exec } = require('child_process');
65
+ const scriptPath = path.join(__dirname, "network.ps1");
66
+ if (os.platform() === 'win32') {
67
+ exec(`powershell -File ${scriptPath}`, (error, stdout, stderr) => {
68
+ if (error) {
69
+ console.error(`Error executing PowerShell script: ${error}`);
70
+ return;
47
71
  }
48
-
49
- let avgRx = measurements.reduce((acc, m) => acc + m.rx, 0) / measurements.length;
50
- let avgTx = measurements.reduce((acc, m) => acc + m.tx, 0) / measurements.length;
51
-
52
- let stdDevRx = Math.sqrt(measurements.reduce((acc, m) => acc + Math.pow(m.rx - avgRx, 2), 0) / measurements.length);
53
- let stdDevTx = Math.sqrt(measurements.reduce((acc, m) => acc + Math.pow(m.tx - avgTx, 2), 0) / measurements.length);
54
-
55
- let zIndexRx = stdDevRx !== 0 ? (diffRxBytes - avgRx) / stdDevRx : 0;
56
- let zIndexTx = stdDevTx !== 0 ? (diffTxBytes - avgTx) / stdDevTx : 0;
57
-
58
- // log time since unsettlement
59
- if ((zIndexRx < 0 && zIndexTx < 0) ) {
60
- networkSettled = true;
61
- } else {
62
- networkSettled = false;
72
+ if (stderr) {
73
+ console.error(`PowerShell error: ${stderr}`);
74
+ return;
63
75
  }
64
-
76
+
77
+ try {
78
+ // Parse the JSON output
79
+ const result = JSON.parse(stdout.trim());
80
+ parseNetworkStats(result.totalBytesReceived, result.totalBytesSent);
81
+ } catch (parseError) {
82
+ console.error(`Error parsing JSON: ${parseError}`);
83
+ }
84
+ });
85
+ } else if (os.platform() === 'darwin') {
86
+ si.networkStats().then(data => {
87
+ parseNetworkStats(data[0].rx_bytes, data[0].tx_bytes);
65
88
  });
89
+ }
66
90
  }
67
91
 
68
92
  async function imageDiffPercent(image1Url, image2Url) {
@@ -134,11 +158,6 @@ function wait(timeoutMs) {
134
158
  });
135
159
  }
136
160
 
137
- (async () => {
138
- if (os.platform() === 'win32') {
139
- si.powerShellStart();
140
- }
141
- setInterval(updateNetwork, networkUpdateInterval);
142
- })();
161
+ setInterval(updateNetwork, networkUpdateInterval);
143
162
 
144
163
  module.exports = { start, wait };
package/lib/system.js CHANGED
@@ -32,7 +32,7 @@ const tmpFilename = () => {
32
32
  return path.join(os.tmpdir(), `${new Date().getTime() + Math.random()}.png`);
33
33
  };
34
34
 
35
- const captureAndResize = async (scale = 1, silent = false) => {
35
+ const captureAndResize = async (scale = 1, silent = false, mouse = false) => {
36
36
  try {
37
37
  const primaryDisplay = await getPrimaryDisplay();
38
38
  if (!silent) {
@@ -55,14 +55,17 @@ const captureAndResize = async (scale = 1, silent = false) => {
55
55
  const cursorPath = path.join(__dirname, "resources", "cursor.png");
56
56
 
57
57
  // resize to 1:1 px ratio
58
- await sharp(step1)
59
- .resize(
60
- Math.floor(primaryDisplay.currentResX * scale),
61
- Math.floor(primaryDisplay.currentResY * scale),
62
- )
58
+ const sharpInstance = sharp(step1).resize(
59
+ Math.floor(primaryDisplay.currentResX * scale),
60
+ Math.floor(primaryDisplay.currentResY * scale),
61
+ );
62
+
63
+ if (mouse) {
63
64
  // composite the mouse image ontop
64
- .composite([{ input: cursorPath, left: mousePos.x, top: mousePos.y }])
65
- .toFile(step2);
65
+ sharpInstance.composite([{ input: cursorPath, left: mousePos.x, top: mousePos.y }]);
66
+ }
67
+
68
+ await sharpInstance.toFile(step2);
66
69
 
67
70
  emitter.emit(events.screenCapture.end, {
68
71
  scale,
@@ -83,13 +86,13 @@ const captureAndResize = async (scale = 1, silent = false) => {
83
86
  };
84
87
 
85
88
  // our handy screenshot function
86
- const captureScreenBase64 = async (scale = 1, silent = false) => {
87
- let step2 = await captureAndResize(scale, silent);
89
+ const captureScreenBase64 = async (scale = 1, silent = false, mouse = false) => {
90
+ let step2 = await captureAndResize(scale, silent, mouse);
88
91
  return fs.readFileSync(step2, "base64");
89
92
  };
90
93
 
91
- const captureScreenPNG = async (scale = 1, silent = false) => {
92
- return await captureAndResize(scale, silent);
94
+ const captureScreenPNG = async (scale = 1, silent = false, mouse = false) => {
95
+ return await captureAndResize(scale, silent, mouse);
93
96
  };
94
97
 
95
98
  const platform = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "4.1.19",
3
+ "version": "4.1.21",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {