testdriverai 4.0.65 → 4.0.66
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/redraw.js +30 -31
- package/package.json +1 -1
package/lib/redraw.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
const { captureScreenPNG } = require("./system");
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const Jimp = require("jimp");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
async function compareImages(image1Url, image2Url) {
|
|
6
|
+
const image1 = await Jimp.read(image1Url);
|
|
7
|
+
const image2 = await Jimp.read(image2Url);
|
|
8
8
|
|
|
9
|
-
//
|
|
10
|
-
|
|
9
|
+
// Pixel difference
|
|
10
|
+
const diff = Jimp.diff(image1, image2);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
if (diff.percent < 0.15) {
|
|
13
|
+
return false;
|
|
14
|
+
} else {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
18
|
|
|
19
19
|
let startImage = null;
|
|
20
20
|
|
|
@@ -25,25 +25,24 @@ async function start() {
|
|
|
25
25
|
|
|
26
26
|
function wait(timeoutMs) {
|
|
27
27
|
return new Promise((resolve) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// checkCondition();
|
|
28
|
+
const startTime = Date.now();
|
|
29
|
+
|
|
30
|
+
async function checkCondition() {
|
|
31
|
+
let nowImage = await captureScreenPNG();
|
|
32
|
+
let result = await compareImages(startImage, nowImage);
|
|
33
|
+
|
|
34
|
+
if (result) {
|
|
35
|
+
resolve("Condition met");
|
|
36
|
+
} else if (Date.now() - startTime >= timeoutMs) {
|
|
37
|
+
resolve("Timeout reached");
|
|
38
|
+
} else {
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
checkCondition();
|
|
41
|
+
}, 200);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
checkCondition();
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
48
|
|