testdriverai 4.1.18 → 4.1.20

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.
@@ -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;
75
+ }
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}`);
63
83
  }
64
-
65
84
  });
85
+ } else if (os.platform() === 'darwin') {
86
+ si.networkStats().then(data => {
87
+ parseNetworkStats(data[0].rx_bytes, data[0].tx_bytes);
88
+ });
89
+ }
66
90
  }
67
91
 
68
92
  async function imageDiffPercent(image1Url, image2Url) {
@@ -134,9 +158,6 @@ function wait(timeoutMs) {
134
158
  });
135
159
  }
136
160
 
137
- (async () => {
138
- await si.powerShellStart();
139
- setInterval(updateNetwork, networkUpdateInterval);
140
- })();
161
+ setInterval(updateNetwork, networkUpdateInterval);
141
162
 
142
163
  module.exports = { start, wait };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "4.1.18",
3
+ "version": "4.1.20",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {