@midscene/web 0.7.1 → 0.7.2-beta-20241024094141.0
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/dist/browser/playground.js +8438 -0
- package/dist/browser/types/playground.d.ts +313 -0
- package/dist/es/appium.js +680 -604
- package/dist/es/debug.js +95 -73
- package/dist/es/index.js +939 -797
- package/dist/es/midscene-playground.js +678 -609
- package/dist/es/playground.js +593 -1024
- package/dist/es/playwright-report.js +29 -11
- package/dist/es/playwright.js +705 -597
- package/dist/es/puppeteer.js +636 -552
- package/dist/lib/appium.js +688 -609
- package/dist/lib/debug.js +95 -73
- package/dist/lib/index.js +950 -804
- package/dist/lib/midscene-playground.js +687 -615
- package/dist/lib/playground.js +586 -1007
- package/dist/lib/playwright-report.js +30 -9
- package/dist/lib/playwright.js +713 -602
- package/dist/lib/puppeteer.js +644 -557
- package/dist/script/htmlElement.js +11 -10
- package/dist/script/htmlElementDebug.js +11 -10
- package/dist/types/appium.d.ts +2 -3
- package/dist/types/debug.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/{page-ad820b3c.d.ts → page-8117b0ad.d.ts} +8 -7
- package/dist/types/playground.d.ts +6 -21
- package/dist/types/playwright.d.ts +3 -4
- package/dist/types/puppeteer.d.ts +2 -3
- package/dist/types/{tasks-82c1054b.d.ts → tasks-cb6bf758.d.ts} +6 -6
- package/package.json +11 -5
- package/static/index.html +1 -1
package/dist/es/debug.js
CHANGED
|
@@ -5,6 +5,26 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
5
|
return require.apply(this, arguments);
|
|
6
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
7
|
});
|
|
8
|
+
var __async = (__this, __arguments, generator) => {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
var fulfilled = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.next(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var rejected = (value) => {
|
|
18
|
+
try {
|
|
19
|
+
step(generator.throw(value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
25
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
8
28
|
|
|
9
29
|
// src/debug/index.ts
|
|
10
30
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
@@ -23,67 +43,67 @@ import {
|
|
|
23
43
|
resizeImg,
|
|
24
44
|
saveBase64Image
|
|
25
45
|
} from "@midscene/shared/img";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"output_without_text.png"
|
|
40
|
-
);
|
|
41
|
-
const resizeOutputImgPath = path.join(targetDir, "resize-output.png");
|
|
42
|
-
const snapshotJsonPath = path.join(targetDir, "element-snapshot.json");
|
|
43
|
-
const {
|
|
44
|
-
compositeElementInfoImgBase64,
|
|
45
|
-
compositeElementInfoImgWithoutTextBase64
|
|
46
|
-
} = await processImageElementInfo({
|
|
47
|
-
elementsPositionInfo,
|
|
48
|
-
elementsPositionInfoWithoutText,
|
|
49
|
-
inputImgBase64
|
|
50
|
-
});
|
|
51
|
-
const resizeImgBase64 = await resizeImg(inputImgBase64);
|
|
52
|
-
const existingSnapshot = existsSync(snapshotJsonPath) ? JSON.parse(readFileSync(snapshotJsonPath, "utf-8")) : null;
|
|
53
|
-
if (existingSnapshot && JSON.stringify(existingSnapshot) === JSON.stringify(captureElementSnapshot)) {
|
|
54
|
-
console.log("skip save snapshot for ", targetDir);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (!(saveImgType == null ? void 0 : saveImgType.disableSnapshot)) {
|
|
58
|
-
writeFileSyncWithDir(
|
|
59
|
-
snapshotJsonPath,
|
|
60
|
-
JSON.stringify(captureElementSnapshot, null, 2)
|
|
46
|
+
function generateExtractData(page, targetDir, saveImgType) {
|
|
47
|
+
return __async(this, null, function* () {
|
|
48
|
+
const inputImgBase64 = yield page.screenshotBase64();
|
|
49
|
+
const {
|
|
50
|
+
elementsPositionInfo,
|
|
51
|
+
captureElementSnapshot,
|
|
52
|
+
elementsPositionInfoWithoutText
|
|
53
|
+
} = yield getElementInfos(page);
|
|
54
|
+
const inputImagePath = path.join(targetDir, "input.png");
|
|
55
|
+
const outputImagePath = path.join(targetDir, "output.png");
|
|
56
|
+
const outputWithoutTextImgPath = path.join(
|
|
57
|
+
targetDir,
|
|
58
|
+
"output_without_text.png"
|
|
61
59
|
);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
base64Data: compositeElementInfoImgBase64,
|
|
72
|
-
outputPath: outputImagePath
|
|
60
|
+
const resizeOutputImgPath = path.join(targetDir, "resize-output.png");
|
|
61
|
+
const snapshotJsonPath = path.join(targetDir, "element-snapshot.json");
|
|
62
|
+
const {
|
|
63
|
+
compositeElementInfoImgBase64,
|
|
64
|
+
compositeElementInfoImgWithoutTextBase64
|
|
65
|
+
} = yield processImageElementInfo({
|
|
66
|
+
elementsPositionInfo,
|
|
67
|
+
elementsPositionInfoWithoutText,
|
|
68
|
+
inputImgBase64
|
|
73
69
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
70
|
+
const resizeImgBase64 = yield resizeImg(inputImgBase64);
|
|
71
|
+
const existingSnapshot = existsSync(snapshotJsonPath) ? JSON.parse(readFileSync(snapshotJsonPath, "utf-8")) : null;
|
|
72
|
+
if (existingSnapshot && JSON.stringify(existingSnapshot) === JSON.stringify(captureElementSnapshot)) {
|
|
73
|
+
console.log("skip save snapshot for ", targetDir);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableSnapshot)) {
|
|
77
|
+
writeFileSyncWithDir(
|
|
78
|
+
snapshotJsonPath,
|
|
79
|
+
JSON.stringify(captureElementSnapshot, null, 2)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableInputImage)) {
|
|
83
|
+
yield saveBase64Image({
|
|
84
|
+
base64Data: inputImgBase64,
|
|
85
|
+
outputPath: inputImagePath
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableOutputImage)) {
|
|
89
|
+
yield saveBase64Image({
|
|
90
|
+
base64Data: compositeElementInfoImgBase64,
|
|
91
|
+
outputPath: outputImagePath
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableOutputWithoutTextImg)) {
|
|
95
|
+
yield saveBase64Image({
|
|
96
|
+
base64Data: compositeElementInfoImgWithoutTextBase64,
|
|
97
|
+
outputPath: outputWithoutTextImgPath
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableResizeOutputImg)) {
|
|
101
|
+
yield saveBase64Image({
|
|
102
|
+
base64Data: resizeImgBase64,
|
|
103
|
+
outputPath: resizeOutputImgPath
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
87
107
|
}
|
|
88
108
|
function generateTestDataPath(testDataName) {
|
|
89
109
|
const modulePath = __require.resolve("@midscene/core").replace("dist/lib/index.js", "");
|
|
@@ -105,21 +125,23 @@ function writeFileSyncWithDir(filePath, content, options = {}) {
|
|
|
105
125
|
ensureDirectoryExistence(filePath);
|
|
106
126
|
writeFileSync(filePath, content, options);
|
|
107
127
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
128
|
+
function getElementInfos(page) {
|
|
129
|
+
return __async(this, null, function* () {
|
|
130
|
+
const captureElementSnapshot = yield page.getElementInfos();
|
|
131
|
+
const elementsPositionInfoWithoutText = captureElementSnapshot.filter(
|
|
132
|
+
(elementInfo) => {
|
|
133
|
+
if (elementInfo.attributes.nodeType === NodeType.TEXT) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
114
137
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
};
|
|
138
|
+
);
|
|
139
|
+
return {
|
|
140
|
+
elementsPositionInfo: captureElementSnapshot,
|
|
141
|
+
captureElementSnapshot,
|
|
142
|
+
elementsPositionInfoWithoutText
|
|
143
|
+
};
|
|
144
|
+
});
|
|
123
145
|
}
|
|
124
146
|
export {
|
|
125
147
|
generateExtractData,
|