lazyscout 0.1.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/LICENSE +21 -0
- package/README.md +119 -0
- package/dist/index.js +1360 -0
- package/dist/web/assets/index-Bvjimfib.css +1 -0
- package/dist/web/assets/index-CX5TV5gQ.js +12 -0
- package/dist/web/index.html +13 -0
- package/package.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1360 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
|
|
6
|
+
// src/commands/scan.ts
|
|
7
|
+
import { writeFile } from "node:fs/promises";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
|
|
10
|
+
// ../../packages/core/dist/url/policy.js
|
|
11
|
+
var LOCAL_QA_POLICY = {
|
|
12
|
+
allowedProtocols: ["http:", "https:"],
|
|
13
|
+
allowLoopback: true,
|
|
14
|
+
allowPrivateNetwork: true,
|
|
15
|
+
allowCloudMetadata: false
|
|
16
|
+
};
|
|
17
|
+
var PUBLIC_SAAS_POLICY = {
|
|
18
|
+
allowedProtocols: ["http:", "https:"],
|
|
19
|
+
allowLoopback: false,
|
|
20
|
+
allowPrivateNetwork: false,
|
|
21
|
+
allowCloudMetadata: false
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// ../../packages/core/dist/url/checkTargetUrl.js
|
|
25
|
+
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "0.0.0.0", "::1", "[::1]"]);
|
|
26
|
+
var CLOUD_METADATA_HOSTS = /* @__PURE__ */ new Set(["169.254.169.254", "metadata.google.internal", "metadata"]);
|
|
27
|
+
function isPrivateHostname(hostname) {
|
|
28
|
+
const host = hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
29
|
+
if (host.endsWith(".local") || host.endsWith(".internal") || host.endsWith(".localhost"))
|
|
30
|
+
return true;
|
|
31
|
+
if (host.startsWith("fc") || host.startsWith("fd"))
|
|
32
|
+
return true;
|
|
33
|
+
if (host.startsWith("fe80:"))
|
|
34
|
+
return true;
|
|
35
|
+
const ipv4 = host.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
36
|
+
if (!ipv4)
|
|
37
|
+
return false;
|
|
38
|
+
const [a, b] = [Number(ipv4[1]), Number(ipv4[2])];
|
|
39
|
+
if (a === 10)
|
|
40
|
+
return true;
|
|
41
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
42
|
+
return true;
|
|
43
|
+
if (a === 192 && b === 168)
|
|
44
|
+
return true;
|
|
45
|
+
if (a === 169 && b === 254)
|
|
46
|
+
return true;
|
|
47
|
+
if (a === 127)
|
|
48
|
+
return true;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
function isLoopbackHostname(hostname) {
|
|
52
|
+
return LOOPBACK_HOSTS.has(hostname.toLowerCase());
|
|
53
|
+
}
|
|
54
|
+
function isCloudMetadataHostname(hostname) {
|
|
55
|
+
return CLOUD_METADATA_HOSTS.has(hostname.toLowerCase());
|
|
56
|
+
}
|
|
57
|
+
function checkTargetUrl(rawUrl, policy = LOCAL_QA_POLICY) {
|
|
58
|
+
const trimmed = rawUrl.trim();
|
|
59
|
+
if (!trimmed) {
|
|
60
|
+
return { ok: false, code: "invalid-url", message: "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E43\u0E2A\u0E48 URL \u0E17\u0E35\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23\u0E27\u0E34\u0E40\u0E04\u0E23\u0E32\u0E30\u0E2B\u0E4C" };
|
|
61
|
+
}
|
|
62
|
+
const withProtocol = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`;
|
|
63
|
+
let url;
|
|
64
|
+
try {
|
|
65
|
+
url = new URL(withProtocol);
|
|
66
|
+
} catch {
|
|
67
|
+
return { ok: false, code: "invalid-url", message: `\u0E23\u0E39\u0E1B\u0E41\u0E1A\u0E1A URL \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07: ${rawUrl}` };
|
|
68
|
+
}
|
|
69
|
+
if (!policy.allowedProtocols.includes(url.protocol)) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
code: "blocked-url",
|
|
73
|
+
message: `\u0E23\u0E2D\u0E07\u0E23\u0E31\u0E1A\u0E40\u0E09\u0E1E\u0E32\u0E30 ${policy.allowedProtocols.join(", ")} \u0E40\u0E17\u0E48\u0E32\u0E19\u0E31\u0E49\u0E19 (\u0E44\u0E14\u0E49\u0E23\u0E31\u0E1A ${url.protocol})`
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (!url.hostname) {
|
|
77
|
+
return { ok: false, code: "invalid-url", message: "URL \u0E44\u0E21\u0E48\u0E21\u0E35\u0E0A\u0E37\u0E48\u0E2D\u0E42\u0E2E\u0E2A\u0E15\u0E4C" };
|
|
78
|
+
}
|
|
79
|
+
if (!policy.allowCloudMetadata && isCloudMetadataHostname(url.hostname)) {
|
|
80
|
+
return { ok: false, code: "blocked-url", message: "\u0E44\u0E21\u0E48\u0E2D\u0E19\u0E38\u0E0D\u0E32\u0E15\u0E43\u0E2B\u0E49\u0E40\u0E02\u0E49\u0E32\u0E16\u0E36\u0E07 cloud metadata endpoint" };
|
|
81
|
+
}
|
|
82
|
+
if (!policy.allowLoopback && isLoopbackHostname(url.hostname)) {
|
|
83
|
+
return { ok: false, code: "blocked-url", message: "\u0E44\u0E21\u0E48\u0E2D\u0E19\u0E38\u0E0D\u0E32\u0E15\u0E43\u0E2B\u0E49\u0E40\u0E02\u0E49\u0E32\u0E16\u0E36\u0E07 localhost" };
|
|
84
|
+
}
|
|
85
|
+
if (!policy.allowPrivateNetwork && isPrivateHostname(url.hostname)) {
|
|
86
|
+
return { ok: false, code: "blocked-url", message: "\u0E44\u0E21\u0E48\u0E2D\u0E19\u0E38\u0E0D\u0E32\u0E15\u0E43\u0E2B\u0E49\u0E40\u0E02\u0E49\u0E32\u0E16\u0E36\u0E07\u0E40\u0E04\u0E23\u0E37\u0E2D\u0E02\u0E48\u0E32\u0E22\u0E20\u0E32\u0E22\u0E43\u0E19 (private IP)" };
|
|
87
|
+
}
|
|
88
|
+
return { ok: true, url };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ../../packages/core/dist/url/normalizeUrl.js
|
|
92
|
+
var NON_PAGE_EXTENSIONS = [
|
|
93
|
+
".pdf",
|
|
94
|
+
".zip",
|
|
95
|
+
".rar",
|
|
96
|
+
".png",
|
|
97
|
+
".jpg",
|
|
98
|
+
".jpeg",
|
|
99
|
+
".gif",
|
|
100
|
+
".svg",
|
|
101
|
+
".webp",
|
|
102
|
+
".ico",
|
|
103
|
+
".mp4",
|
|
104
|
+
".mp3",
|
|
105
|
+
".avi",
|
|
106
|
+
".doc",
|
|
107
|
+
".docx",
|
|
108
|
+
".xls",
|
|
109
|
+
".xlsx",
|
|
110
|
+
".ppt",
|
|
111
|
+
".pptx",
|
|
112
|
+
".csv",
|
|
113
|
+
".exe",
|
|
114
|
+
".dmg"
|
|
115
|
+
];
|
|
116
|
+
function normalizeUrl(rawUrl) {
|
|
117
|
+
const url = new URL(rawUrl);
|
|
118
|
+
url.hash = "";
|
|
119
|
+
url.hostname = url.hostname.toLowerCase();
|
|
120
|
+
url.searchParams.sort();
|
|
121
|
+
if (url.pathname.length > 1 && url.pathname.endsWith("/")) {
|
|
122
|
+
url.pathname = url.pathname.replace(/\/+$/, "");
|
|
123
|
+
}
|
|
124
|
+
return url.toString();
|
|
125
|
+
}
|
|
126
|
+
function isSameOrigin(candidate, origin) {
|
|
127
|
+
try {
|
|
128
|
+
return new URL(candidate).origin === origin;
|
|
129
|
+
} catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function isCrawlableUrl(rawUrl) {
|
|
134
|
+
try {
|
|
135
|
+
const url = new URL(rawUrl);
|
|
136
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
137
|
+
return false;
|
|
138
|
+
const path = url.pathname.toLowerCase();
|
|
139
|
+
return !NON_PAGE_EXTENSIONS.some((ext) => path.endsWith(ext));
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function moduleNameFromUrl(rawUrl) {
|
|
145
|
+
try {
|
|
146
|
+
const { pathname } = new URL(rawUrl);
|
|
147
|
+
const segments = pathname.split("/").filter(Boolean).slice(0, 2);
|
|
148
|
+
if (segments.length === 0)
|
|
149
|
+
return "HOME";
|
|
150
|
+
const name = segments.join("-").replace(/\.[a-z0-9]+$/i, "").replace(/[^a-zA-Z0-9ก-๙-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").toUpperCase();
|
|
151
|
+
return name || "HOME";
|
|
152
|
+
} catch {
|
|
153
|
+
return "PAGE";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ../../packages/core/dist/testcase/describeStep.js
|
|
158
|
+
function describeTarget(target) {
|
|
159
|
+
const name = target.name || target.label || target.text || target.placeholder;
|
|
160
|
+
if (name && target.role)
|
|
161
|
+
return `${target.role} "${name}"`;
|
|
162
|
+
if (name)
|
|
163
|
+
return `"${name}"`;
|
|
164
|
+
if (target.cssSelector)
|
|
165
|
+
return `element (${target.cssSelector})`;
|
|
166
|
+
return "element";
|
|
167
|
+
}
|
|
168
|
+
function describeStep(step) {
|
|
169
|
+
if (step.description)
|
|
170
|
+
return step.description;
|
|
171
|
+
switch (step.type) {
|
|
172
|
+
case "navigate":
|
|
173
|
+
return `Navigate to ${step.url}`;
|
|
174
|
+
case "click":
|
|
175
|
+
return `Click ${describeTarget(step.target)}`;
|
|
176
|
+
case "fill":
|
|
177
|
+
return `Enter "${step.value}" in ${describeTarget(step.target)}`;
|
|
178
|
+
case "select":
|
|
179
|
+
return `Select "${step.option}" from ${describeTarget(step.target)}`;
|
|
180
|
+
case "assertVisible":
|
|
181
|
+
return `Verify that ${describeTarget(step.target)} is visible`;
|
|
182
|
+
case "assertText":
|
|
183
|
+
return step.target ? `Verify that ${describeTarget(step.target)} shows "${step.text}"` : `Verify that the page shows "${step.text}"`;
|
|
184
|
+
case "assertUrl":
|
|
185
|
+
return `Verify that the URL contains "${step.urlContains}"`;
|
|
186
|
+
case "manual":
|
|
187
|
+
return step.description;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function describeSteps(steps) {
|
|
191
|
+
return steps.map((step, index) => `${index + 1}. ${describeStep(step)}`).join("\n");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ../../packages/core/dist/testcase/createTestCase.js
|
|
195
|
+
function makeTestCaseId(module, sequence) {
|
|
196
|
+
return `TC-${module}-${String(sequence).padStart(3, "0")}`;
|
|
197
|
+
}
|
|
198
|
+
function makeTestDataId(module, sequence) {
|
|
199
|
+
return `TD-${module}-${String(sequence).padStart(3, "0")}`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ../../packages/explorer/dist/browser/domCollector.js
|
|
203
|
+
function collectPageData() {
|
|
204
|
+
const MAX_PER_GROUP = 80;
|
|
205
|
+
function cleanText(value) {
|
|
206
|
+
return (value || "").replace(/\s+/g, " ").trim().slice(0, 200);
|
|
207
|
+
}
|
|
208
|
+
function attr(el, name) {
|
|
209
|
+
const value = el.getAttribute(name);
|
|
210
|
+
return value && value.trim() ? value.trim() : void 0;
|
|
211
|
+
}
|
|
212
|
+
function accessibleName(el) {
|
|
213
|
+
const ariaLabel = cleanText(el.getAttribute("aria-label"));
|
|
214
|
+
if (ariaLabel)
|
|
215
|
+
return ariaLabel;
|
|
216
|
+
const labelledBy = el.getAttribute("aria-labelledby");
|
|
217
|
+
if (labelledBy) {
|
|
218
|
+
const text = labelledBy.split(/\s+/).map((id) => cleanText(document.getElementById(id)?.textContent)).filter(Boolean).join(" ");
|
|
219
|
+
if (text)
|
|
220
|
+
return text;
|
|
221
|
+
}
|
|
222
|
+
const isFormField = el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement;
|
|
223
|
+
if (isFormField) {
|
|
224
|
+
if (el.id) {
|
|
225
|
+
const label = document.querySelector(`label[for="${CSS.escape(el.id)}"]`);
|
|
226
|
+
const labelText = cleanText(label?.textContent);
|
|
227
|
+
if (labelText)
|
|
228
|
+
return labelText;
|
|
229
|
+
}
|
|
230
|
+
const wrappingLabel = el.closest("label");
|
|
231
|
+
if (wrappingLabel) {
|
|
232
|
+
const labelText = cleanText(wrappingLabel.textContent);
|
|
233
|
+
if (labelText)
|
|
234
|
+
return labelText;
|
|
235
|
+
}
|
|
236
|
+
const placeholder = cleanText(el.getAttribute("placeholder"));
|
|
237
|
+
if (placeholder)
|
|
238
|
+
return placeholder;
|
|
239
|
+
const title = cleanText(el.getAttribute("title"));
|
|
240
|
+
if (title)
|
|
241
|
+
return title;
|
|
242
|
+
if (el instanceof HTMLInputElement && el.value && el.type !== "text")
|
|
243
|
+
return cleanText(el.value);
|
|
244
|
+
return cleanText(el.getAttribute("name"));
|
|
245
|
+
}
|
|
246
|
+
const ownText = cleanText(el.textContent);
|
|
247
|
+
if (ownText)
|
|
248
|
+
return ownText;
|
|
249
|
+
const image = el.querySelector("img[alt]");
|
|
250
|
+
const alt = cleanText(image?.getAttribute("alt"));
|
|
251
|
+
if (alt)
|
|
252
|
+
return alt;
|
|
253
|
+
return cleanText(el.getAttribute("title")) || cleanText(el.getAttribute("value"));
|
|
254
|
+
}
|
|
255
|
+
function cssSelector(el) {
|
|
256
|
+
if (el.id)
|
|
257
|
+
return `#${CSS.escape(el.id)}`;
|
|
258
|
+
const parts = [];
|
|
259
|
+
let current = el;
|
|
260
|
+
let depth = 0;
|
|
261
|
+
while (current && current.nodeType === 1 && depth < 4) {
|
|
262
|
+
let part = current.tagName.toLowerCase();
|
|
263
|
+
const parent = current.parentElement;
|
|
264
|
+
if (parent) {
|
|
265
|
+
const sameTag = Array.from(parent.children).filter((child) => child.tagName === current.tagName);
|
|
266
|
+
if (sameTag.length > 1)
|
|
267
|
+
part += `:nth-of-type(${sameTag.indexOf(current) + 1})`;
|
|
268
|
+
}
|
|
269
|
+
parts.unshift(part);
|
|
270
|
+
if (current.id) {
|
|
271
|
+
parts[0] = `#${CSS.escape(current.id)}`;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
current = parent;
|
|
275
|
+
depth++;
|
|
276
|
+
}
|
|
277
|
+
return parts.join(" > ");
|
|
278
|
+
}
|
|
279
|
+
function inputRole(input) {
|
|
280
|
+
switch (input.type) {
|
|
281
|
+
case "checkbox":
|
|
282
|
+
return "checkbox";
|
|
283
|
+
case "radio":
|
|
284
|
+
return "radio";
|
|
285
|
+
case "search":
|
|
286
|
+
return "searchbox";
|
|
287
|
+
case "submit":
|
|
288
|
+
case "button":
|
|
289
|
+
case "reset":
|
|
290
|
+
case "image":
|
|
291
|
+
return "button";
|
|
292
|
+
case "range":
|
|
293
|
+
return "slider";
|
|
294
|
+
case "number":
|
|
295
|
+
return "spinbutton";
|
|
296
|
+
default:
|
|
297
|
+
return "textbox";
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function toRawElement(el, kind, defaultRole) {
|
|
301
|
+
const explicitRole = attr(el, "role");
|
|
302
|
+
let role = explicitRole || defaultRole;
|
|
303
|
+
let inputType;
|
|
304
|
+
let options;
|
|
305
|
+
if (el instanceof HTMLInputElement) {
|
|
306
|
+
inputType = el.type;
|
|
307
|
+
if (!explicitRole)
|
|
308
|
+
role = inputRole(el);
|
|
309
|
+
}
|
|
310
|
+
if (el instanceof HTMLSelectElement) {
|
|
311
|
+
options = Array.from(el.options).map((option) => cleanText(option.textContent)).slice(0, 30);
|
|
312
|
+
}
|
|
313
|
+
const disabled = el.disabled === true || el.getAttribute("aria-disabled") === "true";
|
|
314
|
+
const required = el.required === true || el.getAttribute("aria-required") === "true";
|
|
315
|
+
return {
|
|
316
|
+
kind,
|
|
317
|
+
role,
|
|
318
|
+
accessibleName: accessibleName(el),
|
|
319
|
+
text: cleanText(el.textContent) || void 0,
|
|
320
|
+
tagName: el.tagName.toLowerCase(),
|
|
321
|
+
inputType,
|
|
322
|
+
placeholder: attr(el, "placeholder"),
|
|
323
|
+
name: attr(el, "name"),
|
|
324
|
+
id: el.id || void 0,
|
|
325
|
+
href: el instanceof HTMLAnchorElement ? el.href : void 0,
|
|
326
|
+
options,
|
|
327
|
+
required,
|
|
328
|
+
disabled,
|
|
329
|
+
cssSelector: cssSelector(el)
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function isCollectable(el) {
|
|
333
|
+
if (el.closest('[aria-hidden="true"]'))
|
|
334
|
+
return false;
|
|
335
|
+
if (el instanceof HTMLInputElement && el.type === "hidden")
|
|
336
|
+
return false;
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
function collect(selector, kind, defaultRole) {
|
|
340
|
+
return Array.from(document.querySelectorAll(selector)).filter(isCollectable).slice(0, MAX_PER_GROUP).map((el) => toRawElement(el, kind, defaultRole));
|
|
341
|
+
}
|
|
342
|
+
const BUTTON_SELECTOR = 'button, input[type="submit"], input[type="button"], input[type="reset"], [role="button"]';
|
|
343
|
+
const INPUT_SELECTOR = 'input:not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="image"])';
|
|
344
|
+
const forms = Array.from(document.querySelectorAll("form")).slice(0, 20).map((form) => {
|
|
345
|
+
const fields = Array.from(form.querySelectorAll(INPUT_SELECTOR + ", textarea, select")).filter(isCollectable).slice(0, 40).map((el) => {
|
|
346
|
+
const kind = el.tagName === "TEXTAREA" ? "textarea" : el.tagName === "SELECT" ? "select" : "input";
|
|
347
|
+
const defaultRole = el.tagName === "SELECT" ? "combobox" : "textbox";
|
|
348
|
+
return toRawElement(el, kind, defaultRole);
|
|
349
|
+
});
|
|
350
|
+
const submitButtons = Array.from(form.querySelectorAll(BUTTON_SELECTOR)).filter(isCollectable).slice(0, 10).map((el) => toRawElement(el, "button", "button"));
|
|
351
|
+
return {
|
|
352
|
+
id: form.id || void 0,
|
|
353
|
+
name: attr(form, "name"),
|
|
354
|
+
action: form.getAttribute("action") || void 0,
|
|
355
|
+
method: (form.getAttribute("method") || "get").toLowerCase(),
|
|
356
|
+
// ใช้ aria-label / name / id เท่านั้น เพราะ textContent ของ form คือทั้งฟอร์ม
|
|
357
|
+
accessibleName: attr(form, "aria-label") || attr(form, "name") || form.id || void 0,
|
|
358
|
+
fields,
|
|
359
|
+
submitButtons
|
|
360
|
+
};
|
|
361
|
+
});
|
|
362
|
+
return {
|
|
363
|
+
title: document.title,
|
|
364
|
+
headings: Array.from(document.querySelectorAll("h1, h2, h3")).map((el) => cleanText(el.textContent)).filter(Boolean).slice(0, 30),
|
|
365
|
+
links: collect("a[href]", "link", "link"),
|
|
366
|
+
buttons: collect(BUTTON_SELECTOR, "button", "button"),
|
|
367
|
+
inputs: collect(INPUT_SELECTOR, "input", "textbox"),
|
|
368
|
+
textareas: collect("textarea", "textarea", "textbox"),
|
|
369
|
+
selects: collect("select", "select", "combobox"),
|
|
370
|
+
forms
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// ../../packages/explorer/dist/safety.js
|
|
375
|
+
var DESTRUCTIVE_KEYWORDS = [
|
|
376
|
+
// English
|
|
377
|
+
"delete",
|
|
378
|
+
"remove",
|
|
379
|
+
"destroy",
|
|
380
|
+
"erase",
|
|
381
|
+
"drop",
|
|
382
|
+
"reset",
|
|
383
|
+
"purchase",
|
|
384
|
+
"buy",
|
|
385
|
+
"checkout",
|
|
386
|
+
"pay",
|
|
387
|
+
"payment",
|
|
388
|
+
"transfer",
|
|
389
|
+
"withdraw",
|
|
390
|
+
"refund",
|
|
391
|
+
"send",
|
|
392
|
+
"submit order",
|
|
393
|
+
"place order",
|
|
394
|
+
"confirm payment",
|
|
395
|
+
"confirm order",
|
|
396
|
+
"logout",
|
|
397
|
+
"log out",
|
|
398
|
+
"sign out",
|
|
399
|
+
"signout",
|
|
400
|
+
"deactivate",
|
|
401
|
+
"disable account",
|
|
402
|
+
"delete account",
|
|
403
|
+
"close account",
|
|
404
|
+
"unsubscribe",
|
|
405
|
+
"cancel subscription",
|
|
406
|
+
"archive",
|
|
407
|
+
"publish",
|
|
408
|
+
"approve",
|
|
409
|
+
"reject",
|
|
410
|
+
// ไทย
|
|
411
|
+
"\u0E25\u0E1A",
|
|
412
|
+
"\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01",
|
|
413
|
+
"\u0E0A\u0E33\u0E23\u0E30\u0E40\u0E07\u0E34\u0E19",
|
|
414
|
+
"\u0E08\u0E48\u0E32\u0E22",
|
|
415
|
+
"\u0E42\u0E2D\u0E19",
|
|
416
|
+
"\u0E0B\u0E37\u0E49\u0E2D",
|
|
417
|
+
"\u0E2A\u0E31\u0E48\u0E07\u0E0B\u0E37\u0E49\u0E2D",
|
|
418
|
+
"\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E01\u0E32\u0E23\u0E0A\u0E33\u0E23\u0E30",
|
|
419
|
+
"\u0E2D\u0E2D\u0E01\u0E08\u0E32\u0E01\u0E23\u0E30\u0E1A\u0E1A",
|
|
420
|
+
"\u0E2A\u0E48\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25",
|
|
421
|
+
"\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01"
|
|
422
|
+
];
|
|
423
|
+
function isDestructiveLabel(...labels) {
|
|
424
|
+
const haystack = labels.filter(Boolean).join(" ").toLowerCase();
|
|
425
|
+
if (!haystack.trim())
|
|
426
|
+
return false;
|
|
427
|
+
return DESTRUCTIVE_KEYWORDS.some((keyword) => haystack.includes(keyword));
|
|
428
|
+
}
|
|
429
|
+
function canFollowLink(href, accessibleName) {
|
|
430
|
+
if (!href)
|
|
431
|
+
return false;
|
|
432
|
+
if (isDestructiveLabel(accessibleName, href))
|
|
433
|
+
return false;
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// ../../packages/explorer/dist/mapToPageModel.js
|
|
438
|
+
function toUIElement(raw) {
|
|
439
|
+
return {
|
|
440
|
+
...raw,
|
|
441
|
+
destructive: isDestructiveLabel(raw.accessibleName, raw.text, raw.name, raw.id)
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function toFormInfo(raw) {
|
|
445
|
+
return {
|
|
446
|
+
id: raw.id,
|
|
447
|
+
name: raw.name,
|
|
448
|
+
action: raw.action,
|
|
449
|
+
method: raw.method,
|
|
450
|
+
accessibleName: raw.accessibleName,
|
|
451
|
+
fields: raw.fields.map(toUIElement),
|
|
452
|
+
submitButtons: raw.submitButtons.map(toUIElement)
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
function mapToPageModel(raw, meta) {
|
|
456
|
+
return {
|
|
457
|
+
url: meta.url,
|
|
458
|
+
finalUrl: meta.finalUrl,
|
|
459
|
+
title: raw.title,
|
|
460
|
+
depth: meta.depth,
|
|
461
|
+
statusCode: meta.statusCode,
|
|
462
|
+
headings: raw.headings,
|
|
463
|
+
links: raw.links.map(toUIElement),
|
|
464
|
+
buttons: raw.buttons.map(toUIElement),
|
|
465
|
+
inputs: raw.inputs.map(toUIElement),
|
|
466
|
+
textareas: raw.textareas.map(toUIElement),
|
|
467
|
+
selects: raw.selects.map(toUIElement),
|
|
468
|
+
forms: raw.forms.map(toFormInfo)
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// ../../packages/explorer/dist/errors.js
|
|
473
|
+
function toExploreIssue(url, error) {
|
|
474
|
+
const raw = error instanceof Error ? error.message : String(error);
|
|
475
|
+
const text = raw.toLowerCase();
|
|
476
|
+
let code = "navigation-failed";
|
|
477
|
+
let message = "\u0E40\u0E1B\u0E34\u0E14\u0E2B\u0E19\u0E49\u0E32\u0E19\u0E35\u0E49\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08";
|
|
478
|
+
if (text.includes("err_connection_refused") || text.includes("econnrefused")) {
|
|
479
|
+
code = "connection-refused";
|
|
480
|
+
message = "\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49 (connection refused) \u2014 \u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E27\u0E48\u0E32\u0E40\u0E27\u0E47\u0E1A\u0E44\u0E0B\u0E15\u0E4C\u0E40\u0E1B\u0E34\u0E14\u0E2D\u0E22\u0E39\u0E48\u0E41\u0E25\u0E30\u0E1E\u0E2D\u0E23\u0E4C\u0E15\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07";
|
|
481
|
+
} else if (text.includes("err_name_not_resolved") || text.includes("enotfound")) {
|
|
482
|
+
code = "dns-error";
|
|
483
|
+
message = "\u0E2B\u0E32\u0E0A\u0E37\u0E48\u0E2D\u0E42\u0E14\u0E40\u0E21\u0E19\u0E19\u0E35\u0E49\u0E44\u0E21\u0E48\u0E1E\u0E1A (DNS) \u2014 \u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E15\u0E31\u0E27\u0E2A\u0E30\u0E01\u0E14\u0E02\u0E2D\u0E07 URL";
|
|
484
|
+
} else if (text.includes("err_cert") || text.includes("ssl") || text.includes("err_bad_ssl")) {
|
|
485
|
+
code = "ssl-error";
|
|
486
|
+
message = "\u0E43\u0E1A\u0E23\u0E31\u0E1A\u0E23\u0E2D\u0E07 SSL \u0E02\u0E2D\u0E07\u0E40\u0E27\u0E47\u0E1A\u0E44\u0E0B\u0E15\u0E4C\u0E21\u0E35\u0E1B\u0E31\u0E0D\u0E2B\u0E32";
|
|
487
|
+
} else if (text.includes("timeout") || text.includes("timed out")) {
|
|
488
|
+
code = "timeout";
|
|
489
|
+
message = "\u0E40\u0E1B\u0E34\u0E14\u0E2B\u0E19\u0E49\u0E32\u0E44\u0E21\u0E48\u0E17\u0E31\u0E19\u0E40\u0E27\u0E25\u0E32\u0E17\u0E35\u0E48\u0E01\u0E33\u0E2B\u0E19\u0E14 (timeout)";
|
|
490
|
+
} else if (text.includes("crash")) {
|
|
491
|
+
code = "page-crash";
|
|
492
|
+
message = "\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E27\u0E47\u0E1A\u0E17\u0E33\u0E43\u0E2B\u0E49 browser \u0E2B\u0E22\u0E38\u0E14\u0E17\u0E33\u0E07\u0E32\u0E19 (page crash)";
|
|
493
|
+
} else if (text.includes("err_connection_timed_out")) {
|
|
494
|
+
code = "timeout";
|
|
495
|
+
message = "\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08\u0E20\u0E32\u0E22\u0E43\u0E19\u0E40\u0E27\u0E25\u0E32\u0E17\u0E35\u0E48\u0E01\u0E33\u0E2B\u0E19\u0E14";
|
|
496
|
+
} else if (text.includes("err_aborted")) {
|
|
497
|
+
code = "navigation-failed";
|
|
498
|
+
message = "\u0E01\u0E32\u0E23\u0E40\u0E1B\u0E34\u0E14\u0E2B\u0E19\u0E49\u0E32\u0E16\u0E39\u0E01\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E01\u0E25\u0E32\u0E07\u0E17\u0E32\u0E07";
|
|
499
|
+
} else if (text.includes("executable doesn") || text.includes("browsertype.launch")) {
|
|
500
|
+
code = "browser-error";
|
|
501
|
+
message = '\u0E40\u0E1B\u0E34\u0E14 browser \u0E44\u0E21\u0E48\u0E44\u0E14\u0E49 \u2014 \u0E43\u0E2B\u0E49\u0E23\u0E31\u0E19 "npx playwright install chromium" \u0E01\u0E48\u0E2D\u0E19';
|
|
502
|
+
}
|
|
503
|
+
return { url, code, message };
|
|
504
|
+
}
|
|
505
|
+
var ExplorerError = class extends Error {
|
|
506
|
+
code;
|
|
507
|
+
hint;
|
|
508
|
+
constructor(code, message, hint) {
|
|
509
|
+
super(message);
|
|
510
|
+
this.name = "ExplorerError";
|
|
511
|
+
this.code = code;
|
|
512
|
+
this.hint = hint;
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
// ../../packages/explorer/dist/launchBrowser.js
|
|
517
|
+
import { chromium } from "playwright-core";
|
|
518
|
+
var CANDIDATES = [
|
|
519
|
+
{ channel: void 0, label: "Chromium \u0E02\u0E2D\u0E07 Playwright" },
|
|
520
|
+
{ channel: "chrome", label: "Google Chrome" },
|
|
521
|
+
{ channel: "msedge", label: "Microsoft Edge" }
|
|
522
|
+
];
|
|
523
|
+
async function launchBrowser() {
|
|
524
|
+
const failures = [];
|
|
525
|
+
for (const candidate of CANDIDATES) {
|
|
526
|
+
try {
|
|
527
|
+
const browser = await chromium.launch({
|
|
528
|
+
headless: true,
|
|
529
|
+
...candidate.channel ? { channel: candidate.channel } : {}
|
|
530
|
+
});
|
|
531
|
+
return { browser, label: candidate.label };
|
|
532
|
+
} catch (error) {
|
|
533
|
+
failures.push(candidate.label);
|
|
534
|
+
void error;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
throw new ExplorerError("browser-error", `\u0E40\u0E1B\u0E34\u0E14\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49 (\u0E25\u0E2D\u0E07\u0E41\u0E25\u0E49\u0E27: ${failures.join(", ")})`, '\u0E15\u0E34\u0E14\u0E15\u0E31\u0E49\u0E07 Google Chrome \u0E2B\u0E23\u0E37\u0E2D Microsoft Edge \u0E2B\u0E23\u0E37\u0E2D\u0E23\u0E31\u0E19 "npx playwright install chromium" \u0E41\u0E25\u0E49\u0E27\u0E25\u0E2D\u0E07\u0E43\u0E2B\u0E21\u0E48');
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// ../../packages/explorer/dist/exploreWebsite.js
|
|
541
|
+
var DEFAULT_EXPLORE_OPTIONS = {
|
|
542
|
+
maxPages: 20,
|
|
543
|
+
maxDepth: 3,
|
|
544
|
+
pageTimeoutMs: 2e4,
|
|
545
|
+
totalTimeoutMs: 12e4
|
|
546
|
+
};
|
|
547
|
+
async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY) {
|
|
548
|
+
const config2 = { ...DEFAULT_EXPLORE_OPTIONS, ...options };
|
|
549
|
+
const startedAt = Date.now();
|
|
550
|
+
const check = checkTargetUrl(startUrl, policy);
|
|
551
|
+
if (!check.ok)
|
|
552
|
+
throw new ExplorerError(check.code, check.message);
|
|
553
|
+
const origin = check.url.origin;
|
|
554
|
+
const entryUrl = normalizeUrl(check.url.toString());
|
|
555
|
+
const pages = [];
|
|
556
|
+
const issues = [];
|
|
557
|
+
const visited = /* @__PURE__ */ new Set();
|
|
558
|
+
const queue = [{ url: entryUrl, depth: 0 }];
|
|
559
|
+
let urlsSkipped = 0;
|
|
560
|
+
let limitReached = "none";
|
|
561
|
+
const { browser, label: browserLabel } = await launchBrowser();
|
|
562
|
+
try {
|
|
563
|
+
const context = await browser.newContext({ viewport: { width: 1366, height: 900 } });
|
|
564
|
+
context.setDefaultTimeout(config2.pageTimeoutMs);
|
|
565
|
+
const page = await context.newPage();
|
|
566
|
+
while (queue.length > 0) {
|
|
567
|
+
if (pages.length >= config2.maxPages) {
|
|
568
|
+
limitReached = "max-pages";
|
|
569
|
+
urlsSkipped += queue.length;
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
if (Date.now() - startedAt > config2.totalTimeoutMs) {
|
|
573
|
+
limitReached = "total-timeout";
|
|
574
|
+
urlsSkipped += queue.length;
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
const item = queue.shift();
|
|
578
|
+
if (visited.has(item.url))
|
|
579
|
+
continue;
|
|
580
|
+
visited.add(item.url);
|
|
581
|
+
const result = await visitPage(page, item, config2);
|
|
582
|
+
if (result.kind === "issue") {
|
|
583
|
+
issues.push(result.issue);
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
const finalKey = normalizeUrl(result.page.finalUrl);
|
|
587
|
+
if (finalKey !== item.url && visited.has(finalKey)) {
|
|
588
|
+
urlsSkipped++;
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
visited.add(finalKey);
|
|
592
|
+
pages.push(result.page);
|
|
593
|
+
if (item.depth >= config2.maxDepth) {
|
|
594
|
+
if (result.page.links.length > 0)
|
|
595
|
+
limitReached = limitReached === "none" ? "max-depth" : limitReached;
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
for (const link of result.page.links) {
|
|
599
|
+
if (!canFollowLink(link.href, link.accessibleName))
|
|
600
|
+
continue;
|
|
601
|
+
if (!isSameOrigin(link.href, origin) || !isCrawlableUrl(link.href)) {
|
|
602
|
+
urlsSkipped++;
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
const next = normalizeUrl(link.href);
|
|
606
|
+
if (visited.has(next) || queue.some((queued) => queued.url === next))
|
|
607
|
+
continue;
|
|
608
|
+
queue.push({ url: next, depth: item.depth + 1 });
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
} finally {
|
|
612
|
+
await browser.close().catch(() => void 0);
|
|
613
|
+
}
|
|
614
|
+
return {
|
|
615
|
+
startUrl: entryUrl,
|
|
616
|
+
origin,
|
|
617
|
+
pages,
|
|
618
|
+
issues,
|
|
619
|
+
stats: {
|
|
620
|
+
browser: browserLabel,
|
|
621
|
+
pagesVisited: pages.length,
|
|
622
|
+
urlsSkipped,
|
|
623
|
+
durationMs: Date.now() - startedAt,
|
|
624
|
+
limitReached
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
async function visitPage(page, item, config2) {
|
|
629
|
+
try {
|
|
630
|
+
const response = await page.goto(item.url, {
|
|
631
|
+
waitUntil: "domcontentloaded",
|
|
632
|
+
timeout: config2.pageTimeoutMs
|
|
633
|
+
});
|
|
634
|
+
const status = response?.status();
|
|
635
|
+
if (status !== void 0 && status >= 400) {
|
|
636
|
+
return {
|
|
637
|
+
kind: "issue",
|
|
638
|
+
issue: { url: item.url, code: "http-error", message: `\u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C\u0E15\u0E2D\u0E1A\u0E01\u0E25\u0E31\u0E1A HTTP ${status}` }
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
await page.waitForLoadState("networkidle", { timeout: 3e3 }).catch(() => void 0);
|
|
642
|
+
const finalUrl = page.url();
|
|
643
|
+
const raw = await page.evaluate(collectPageData);
|
|
644
|
+
return {
|
|
645
|
+
kind: "page",
|
|
646
|
+
page: mapToPageModel(raw, {
|
|
647
|
+
url: item.url,
|
|
648
|
+
finalUrl,
|
|
649
|
+
depth: item.depth,
|
|
650
|
+
statusCode: status
|
|
651
|
+
})
|
|
652
|
+
};
|
|
653
|
+
} catch (error) {
|
|
654
|
+
return { kind: "issue", issue: toExploreIssue(item.url, error) };
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// ../../packages/generators/dist/moduleNames.js
|
|
659
|
+
function assignModules(pages) {
|
|
660
|
+
const result = /* @__PURE__ */ new Map();
|
|
661
|
+
const used = /* @__PURE__ */ new Map();
|
|
662
|
+
for (const page of pages) {
|
|
663
|
+
const base = moduleNameFromUrl(page.finalUrl);
|
|
664
|
+
const count = used.get(base) ?? 0;
|
|
665
|
+
used.set(base, count + 1);
|
|
666
|
+
result.set(page.url, count === 0 ? base : `${base}-${count + 1}`);
|
|
667
|
+
}
|
|
668
|
+
return result;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// ../../packages/generators/dist/testcases/targets.js
|
|
672
|
+
function toTargetRef(element) {
|
|
673
|
+
if (element.accessibleName) {
|
|
674
|
+
return { role: element.role, name: element.accessibleName };
|
|
675
|
+
}
|
|
676
|
+
if (element.placeholder) {
|
|
677
|
+
return { role: element.role, placeholder: element.placeholder };
|
|
678
|
+
}
|
|
679
|
+
return { role: element.role, cssSelector: element.cssSelector };
|
|
680
|
+
}
|
|
681
|
+
function labelOf(element) {
|
|
682
|
+
return element.accessibleName || element.placeholder || element.name || element.id || element.tagName;
|
|
683
|
+
}
|
|
684
|
+
function sampleValueFor(element) {
|
|
685
|
+
const hint = `${element.inputType || ""} ${element.name || ""} ${element.accessibleName || ""}`.toLowerCase();
|
|
686
|
+
if (element.inputType === "email" || hint.includes("email") || hint.includes("\u0E2D\u0E35\u0E40\u0E21\u0E25")) {
|
|
687
|
+
return "qa.tester@example.com";
|
|
688
|
+
}
|
|
689
|
+
if (element.inputType === "password" || hint.includes("password") || hint.includes("\u0E23\u0E2B\u0E31\u0E2A\u0E1C\u0E48\u0E32\u0E19")) {
|
|
690
|
+
return "Passw0rd!23";
|
|
691
|
+
}
|
|
692
|
+
if (element.inputType === "tel" || hint.includes("phone") || hint.includes("\u0E42\u0E17\u0E23"))
|
|
693
|
+
return "0812345678";
|
|
694
|
+
if (element.inputType === "number")
|
|
695
|
+
return "1";
|
|
696
|
+
if (element.inputType === "date")
|
|
697
|
+
return "2026-01-01";
|
|
698
|
+
if (element.inputType === "url")
|
|
699
|
+
return "https://example.com";
|
|
700
|
+
if (element.kind === "textarea")
|
|
701
|
+
return "Sample text for testing";
|
|
702
|
+
return "test data";
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// ../../packages/generators/dist/testcases/rules.js
|
|
706
|
+
var UNKNOWN_BEHAVIOUR = "Verify that the result is displayed according to application requirements (needs review by tester).";
|
|
707
|
+
function build(ctx, draft) {
|
|
708
|
+
return {
|
|
709
|
+
module: ctx.module,
|
|
710
|
+
sourceUrl: ctx.page.finalUrl,
|
|
711
|
+
...draft
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
function pageLabel(page, module) {
|
|
715
|
+
return page.title?.trim() || page.headings[0] || module;
|
|
716
|
+
}
|
|
717
|
+
function precondition(page) {
|
|
718
|
+
try {
|
|
719
|
+
return [`The application is available at ${new URL(page.finalUrl).origin}`];
|
|
720
|
+
} catch {
|
|
721
|
+
return ["The application is available"];
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function navigateStep(page) {
|
|
725
|
+
return { type: "navigate", url: page.finalUrl };
|
|
726
|
+
}
|
|
727
|
+
function isUsable(element) {
|
|
728
|
+
return !element.disabled && Boolean(element.accessibleName || element.placeholder);
|
|
729
|
+
}
|
|
730
|
+
function isToggleField(element) {
|
|
731
|
+
return element.inputType === "checkbox" || element.inputType === "radio";
|
|
732
|
+
}
|
|
733
|
+
function fillFieldStep(field) {
|
|
734
|
+
if (isToggleField(field)) {
|
|
735
|
+
return { type: "click", target: toTargetRef(field), description: `Select "${labelOf(field)}"` };
|
|
736
|
+
}
|
|
737
|
+
if (field.kind === "select") {
|
|
738
|
+
const option = field.options?.[1] ?? field.options?.[0] ?? "";
|
|
739
|
+
return { type: "select", target: toTargetRef(field), option };
|
|
740
|
+
}
|
|
741
|
+
return { type: "fill", target: toTargetRef(field), value: sampleValueFor(field) };
|
|
742
|
+
}
|
|
743
|
+
function pageStructureRule(ctx) {
|
|
744
|
+
const { page } = ctx;
|
|
745
|
+
const controls = [
|
|
746
|
+
...page.inputs.filter(isUsable),
|
|
747
|
+
...page.textareas.filter(isUsable),
|
|
748
|
+
...page.selects.filter(isUsable),
|
|
749
|
+
...page.buttons.filter(isUsable),
|
|
750
|
+
...page.links.filter(isUsable).slice(0, 3)
|
|
751
|
+
].slice(0, 8);
|
|
752
|
+
if (controls.length === 0)
|
|
753
|
+
return [];
|
|
754
|
+
const steps = [navigateStep(page)];
|
|
755
|
+
if (page.headings[0]) {
|
|
756
|
+
steps.push({ type: "assertText", text: page.headings[0] });
|
|
757
|
+
}
|
|
758
|
+
for (const control of controls) {
|
|
759
|
+
steps.push({ type: "assertVisible", target: toTargetRef(control) });
|
|
760
|
+
}
|
|
761
|
+
return [
|
|
762
|
+
build(ctx, {
|
|
763
|
+
title: `${pageLabel(page, ctx.module)} page displays required controls`,
|
|
764
|
+
preconditions: precondition(page),
|
|
765
|
+
steps,
|
|
766
|
+
expectedResult: `All ${controls.length} controls detected on the page are visible.`,
|
|
767
|
+
type: "positive",
|
|
768
|
+
priority: "medium",
|
|
769
|
+
automationStatus: "ready",
|
|
770
|
+
notes: "Generated from elements detected on the page."
|
|
771
|
+
})
|
|
772
|
+
];
|
|
773
|
+
}
|
|
774
|
+
function requiredFieldRule(ctx, form) {
|
|
775
|
+
const submit = form.submitButtons.find((button) => !button.disabled);
|
|
776
|
+
const fields = form.fields.filter(isUsable);
|
|
777
|
+
const testableFields = fields.filter((field) => !isToggleField(field)).slice(0, 5);
|
|
778
|
+
if (!submit || testableFields.length === 0)
|
|
779
|
+
return [];
|
|
780
|
+
return testableFields.map((field) => {
|
|
781
|
+
const steps = [navigateStep(ctx.page)];
|
|
782
|
+
for (const other of fields) {
|
|
783
|
+
if (other === field)
|
|
784
|
+
continue;
|
|
785
|
+
steps.push(fillFieldStep(other));
|
|
786
|
+
}
|
|
787
|
+
steps.push({
|
|
788
|
+
type: "manual",
|
|
789
|
+
description: `Leave "${labelOf(field)}" empty`
|
|
790
|
+
});
|
|
791
|
+
steps.push({ type: "click", target: toTargetRef(submit) });
|
|
792
|
+
return build(ctx, {
|
|
793
|
+
title: `${labelOf(field)} is required`,
|
|
794
|
+
preconditions: precondition(ctx.page),
|
|
795
|
+
steps,
|
|
796
|
+
expectedResult: field.required ? "Verify that a validation message is displayed for the empty required field, and the form is not submitted." : UNKNOWN_BEHAVIOUR,
|
|
797
|
+
type: "validation",
|
|
798
|
+
priority: field.required ? "high" : "medium",
|
|
799
|
+
automationStatus: "needs-review",
|
|
800
|
+
notes: field.required ? 'Evidence: the field has the HTML "required" attribute.' : 'No "required" attribute found \u2014 confirm with the specification whether this field is mandatory.'
|
|
801
|
+
});
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
function formSubmitRule(ctx, form) {
|
|
805
|
+
const submit = form.submitButtons.find((button) => !button.disabled && !button.destructive);
|
|
806
|
+
const fields = form.fields.filter(isUsable);
|
|
807
|
+
if (!submit || fields.length === 0)
|
|
808
|
+
return [];
|
|
809
|
+
const steps = [navigateStep(ctx.page)];
|
|
810
|
+
for (const field of fields.slice(0, 8)) {
|
|
811
|
+
steps.push(fillFieldStep(field));
|
|
812
|
+
}
|
|
813
|
+
steps.push({ type: "click", target: toTargetRef(submit) });
|
|
814
|
+
const formName = form.accessibleName || labelOf(submit);
|
|
815
|
+
return [
|
|
816
|
+
build(ctx, {
|
|
817
|
+
title: `Submit ${formName} with valid data`,
|
|
818
|
+
preconditions: [...precondition(ctx.page), "Valid test data is prepared"],
|
|
819
|
+
steps,
|
|
820
|
+
expectedResult: UNKNOWN_BEHAVIOUR,
|
|
821
|
+
type: "positive",
|
|
822
|
+
priority: "high",
|
|
823
|
+
automationStatus: "needs-data",
|
|
824
|
+
notes: "Sample values are placeholders \u2014 replace them with real test data before running."
|
|
825
|
+
})
|
|
826
|
+
];
|
|
827
|
+
}
|
|
828
|
+
function navigationRule(ctx) {
|
|
829
|
+
const { page } = ctx;
|
|
830
|
+
const seen = /* @__PURE__ */ new Set();
|
|
831
|
+
const cases = [];
|
|
832
|
+
for (const link of page.links) {
|
|
833
|
+
if (cases.length >= 6)
|
|
834
|
+
break;
|
|
835
|
+
if (!link.href || link.disabled || !link.accessibleName)
|
|
836
|
+
continue;
|
|
837
|
+
if (link.destructive)
|
|
838
|
+
continue;
|
|
839
|
+
let target;
|
|
840
|
+
try {
|
|
841
|
+
target = new URL(link.href);
|
|
842
|
+
} catch {
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
if (target.origin !== new URL(page.finalUrl).origin)
|
|
846
|
+
continue;
|
|
847
|
+
if (target.pathname === new URL(page.finalUrl).pathname)
|
|
848
|
+
continue;
|
|
849
|
+
if (seen.has(target.pathname))
|
|
850
|
+
continue;
|
|
851
|
+
seen.add(target.pathname);
|
|
852
|
+
const visitedTitle = ctx.visitedTitles.get(normalizeUrl(target.toString()));
|
|
853
|
+
cases.push(build(ctx, {
|
|
854
|
+
title: `Navigate to ${link.accessibleName}`,
|
|
855
|
+
preconditions: precondition(page),
|
|
856
|
+
steps: [
|
|
857
|
+
navigateStep(page),
|
|
858
|
+
{ type: "click", target: toTargetRef(link) },
|
|
859
|
+
{ type: "assertUrl", urlContains: target.pathname }
|
|
860
|
+
],
|
|
861
|
+
expectedResult: visitedTitle ? `The browser navigates to ${target.pathname} and the page "${visitedTitle}" is displayed.` : `The browser navigates to ${target.pathname}.`,
|
|
862
|
+
type: "positive",
|
|
863
|
+
priority: "low",
|
|
864
|
+
automationStatus: visitedTitle ? "ready" : "needs-review",
|
|
865
|
+
notes: visitedTitle ? void 0 : "Explorer did not open this page \u2014 expected result needs review."
|
|
866
|
+
}));
|
|
867
|
+
}
|
|
868
|
+
return cases;
|
|
869
|
+
}
|
|
870
|
+
function destructiveActionRule(ctx) {
|
|
871
|
+
const { page } = ctx;
|
|
872
|
+
const dangerous = [...page.buttons, ...page.links].filter((element) => element.destructive && element.accessibleName).slice(0, 5);
|
|
873
|
+
const seen = /* @__PURE__ */ new Set();
|
|
874
|
+
const cases = [];
|
|
875
|
+
for (const element of dangerous) {
|
|
876
|
+
if (seen.has(element.accessibleName))
|
|
877
|
+
continue;
|
|
878
|
+
seen.add(element.accessibleName);
|
|
879
|
+
cases.push(build(ctx, {
|
|
880
|
+
title: `Verify "${element.accessibleName}" action (manual)`,
|
|
881
|
+
preconditions: [...precondition(page), "Disposable test data is prepared"],
|
|
882
|
+
steps: [
|
|
883
|
+
navigateStep(page),
|
|
884
|
+
{
|
|
885
|
+
type: "manual",
|
|
886
|
+
description: `Manually trigger ${element.role} "${element.accessibleName}" in a safe test environment`
|
|
887
|
+
}
|
|
888
|
+
],
|
|
889
|
+
expectedResult: UNKNOWN_BEHAVIOUR,
|
|
890
|
+
type: "positive",
|
|
891
|
+
priority: "high",
|
|
892
|
+
automationStatus: "manual",
|
|
893
|
+
notes: "Detected as a potentially destructive action \u2014 Explorer did not click it."
|
|
894
|
+
}));
|
|
895
|
+
}
|
|
896
|
+
return cases;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// ../../packages/generators/dist/testcases/generateTestCases.js
|
|
900
|
+
var DEFAULT_GENERATE_OPTIONS = {
|
|
901
|
+
maxTestCasesPerPage: 15
|
|
902
|
+
};
|
|
903
|
+
function generateTestCases(pages, options = {}) {
|
|
904
|
+
const config2 = { ...DEFAULT_GENERATE_OPTIONS, ...options };
|
|
905
|
+
const visitedTitles = /* @__PURE__ */ new Map();
|
|
906
|
+
for (const page of pages) {
|
|
907
|
+
visitedTitles.set(safeNormalize(page.finalUrl), page.title);
|
|
908
|
+
visitedTitles.set(safeNormalize(page.url), page.title);
|
|
909
|
+
}
|
|
910
|
+
const moduleByUrl = assignModules(pages);
|
|
911
|
+
const counters = /* @__PURE__ */ new Map();
|
|
912
|
+
const testCases = [];
|
|
913
|
+
for (const page of pages) {
|
|
914
|
+
const module = moduleByUrl.get(page.url) ?? "PAGE";
|
|
915
|
+
const context = { page, module, visitedTitles };
|
|
916
|
+
const fromPage = [
|
|
917
|
+
...pageStructureRule(context),
|
|
918
|
+
...page.forms.flatMap((form) => requiredFieldRule(context, form)),
|
|
919
|
+
...page.forms.flatMap((form) => formSubmitRule(context, form)),
|
|
920
|
+
...navigationRule(context),
|
|
921
|
+
...destructiveActionRule(context)
|
|
922
|
+
].slice(0, config2.maxTestCasesPerPage);
|
|
923
|
+
for (const generated of fromPage) {
|
|
924
|
+
const sequence = (counters.get(module) ?? 0) + 1;
|
|
925
|
+
counters.set(module, sequence);
|
|
926
|
+
testCases.push({ id: makeTestCaseId(module, sequence), ...generated });
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
return testCases;
|
|
930
|
+
}
|
|
931
|
+
function safeNormalize(url) {
|
|
932
|
+
try {
|
|
933
|
+
return normalizeUrl(url);
|
|
934
|
+
} catch {
|
|
935
|
+
return url;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// ../../packages/generators/dist/testdata/generateTestData.js
|
|
940
|
+
function inputTypeOf(field) {
|
|
941
|
+
if (field.kind === "select")
|
|
942
|
+
return "select";
|
|
943
|
+
if (field.kind === "textarea")
|
|
944
|
+
return "textarea";
|
|
945
|
+
return field.inputType || "text";
|
|
946
|
+
}
|
|
947
|
+
function invalidValueFor(field) {
|
|
948
|
+
const type = inputTypeOf(field);
|
|
949
|
+
switch (type) {
|
|
950
|
+
case "email":
|
|
951
|
+
return { value: "invalid-email", note: "Tests email format validation." };
|
|
952
|
+
case "password":
|
|
953
|
+
return { value: "123", note: "Tests minimum length/complexity \u2014 confirm the real rule with the specification." };
|
|
954
|
+
case "number":
|
|
955
|
+
case "range":
|
|
956
|
+
return { value: "abc", note: "Tests that non-numeric input is rejected." };
|
|
957
|
+
case "tel":
|
|
958
|
+
return { value: "12", note: "Tests phone number length \u2014 confirm the real format with the specification." };
|
|
959
|
+
case "date":
|
|
960
|
+
return { value: "2026-13-45", note: "Tests that an out-of-range date is rejected." };
|
|
961
|
+
case "url":
|
|
962
|
+
return { value: "not-a-url", note: "Tests URL format validation." };
|
|
963
|
+
case "select":
|
|
964
|
+
return { value: "(no option selected)", note: "Tests the case where no option is selected." };
|
|
965
|
+
case "checkbox":
|
|
966
|
+
case "radio":
|
|
967
|
+
return { value: "(not selected)", note: "Tests the case where the option is not selected." };
|
|
968
|
+
default:
|
|
969
|
+
return {
|
|
970
|
+
value: "(empty)",
|
|
971
|
+
note: field.required ? "Tests the required-field rule." : "Field is not marked required \u2014 confirm with the specification whether validation applies."
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
function validValueFor(field) {
|
|
976
|
+
if (field.kind === "select")
|
|
977
|
+
return field.options?.find(Boolean) ?? "(first option)";
|
|
978
|
+
if (field.inputType === "checkbox" || field.inputType === "radio")
|
|
979
|
+
return "(selected)";
|
|
980
|
+
return sampleValueFor(field);
|
|
981
|
+
}
|
|
982
|
+
function generateTestData(pages) {
|
|
983
|
+
const moduleByUrl = assignModules(pages);
|
|
984
|
+
const rows = [];
|
|
985
|
+
for (const page of pages) {
|
|
986
|
+
const module = moduleByUrl.get(page.url) ?? "PAGE";
|
|
987
|
+
const seenFields = /* @__PURE__ */ new Set();
|
|
988
|
+
let sequence = 0;
|
|
989
|
+
const fields = [...page.inputs, ...page.textareas, ...page.selects];
|
|
990
|
+
for (const field of fields) {
|
|
991
|
+
const name = labelOf(field);
|
|
992
|
+
if (!name || seenFields.has(name))
|
|
993
|
+
continue;
|
|
994
|
+
seenFields.add(name);
|
|
995
|
+
const invalid = invalidValueFor(field);
|
|
996
|
+
sequence++;
|
|
997
|
+
rows.push({
|
|
998
|
+
id: makeTestDataId(module, sequence),
|
|
999
|
+
module,
|
|
1000
|
+
sourceUrl: page.finalUrl,
|
|
1001
|
+
field: name,
|
|
1002
|
+
inputType: inputTypeOf(field),
|
|
1003
|
+
required: field.required,
|
|
1004
|
+
validValue: validValueFor(field),
|
|
1005
|
+
invalidValue: invalid.value,
|
|
1006
|
+
note: invalid.note
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return rows;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// ../../packages/generators/dist/csv/exportTestCasesToCsv.js
|
|
1014
|
+
var UTF8_BOM = "\uFEFF";
|
|
1015
|
+
var CSV_COLUMNS = [
|
|
1016
|
+
"TC_ID",
|
|
1017
|
+
"Module",
|
|
1018
|
+
"Title",
|
|
1019
|
+
"Preconditions",
|
|
1020
|
+
"Test_Steps",
|
|
1021
|
+
"Expected_Result",
|
|
1022
|
+
"Type",
|
|
1023
|
+
"Priority",
|
|
1024
|
+
"Automation_Status",
|
|
1025
|
+
"Source_URL"
|
|
1026
|
+
];
|
|
1027
|
+
var TEST_DATA_CSV_COLUMNS = [
|
|
1028
|
+
"TD_ID",
|
|
1029
|
+
"Module",
|
|
1030
|
+
"Field",
|
|
1031
|
+
"Input_Type",
|
|
1032
|
+
"Required",
|
|
1033
|
+
"Valid_Value",
|
|
1034
|
+
"Invalid_Value",
|
|
1035
|
+
"Note",
|
|
1036
|
+
"Source_URL"
|
|
1037
|
+
];
|
|
1038
|
+
function escapeCsvValue(value) {
|
|
1039
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
1040
|
+
}
|
|
1041
|
+
function toRow(values) {
|
|
1042
|
+
return values.map(escapeCsvValue).join(",");
|
|
1043
|
+
}
|
|
1044
|
+
function testCaseRow(testCase) {
|
|
1045
|
+
return toRow([
|
|
1046
|
+
testCase.id,
|
|
1047
|
+
testCase.module,
|
|
1048
|
+
testCase.title,
|
|
1049
|
+
testCase.preconditions.join("\n"),
|
|
1050
|
+
describeSteps(testCase.steps),
|
|
1051
|
+
testCase.expectedResult,
|
|
1052
|
+
testCase.type,
|
|
1053
|
+
testCase.priority,
|
|
1054
|
+
testCase.automationStatus,
|
|
1055
|
+
testCase.sourceUrl
|
|
1056
|
+
]);
|
|
1057
|
+
}
|
|
1058
|
+
function testDataRow(row) {
|
|
1059
|
+
return toRow([
|
|
1060
|
+
row.id,
|
|
1061
|
+
row.module,
|
|
1062
|
+
row.field,
|
|
1063
|
+
row.inputType,
|
|
1064
|
+
row.required ? "yes" : "no",
|
|
1065
|
+
row.validValue,
|
|
1066
|
+
row.invalidValue,
|
|
1067
|
+
row.note ?? "",
|
|
1068
|
+
row.sourceUrl
|
|
1069
|
+
]);
|
|
1070
|
+
}
|
|
1071
|
+
function exportTestCasesToCsv(testCases, testData = []) {
|
|
1072
|
+
const lines = [toRow([...CSV_COLUMNS]), ...testCases.map(testCaseRow)];
|
|
1073
|
+
if (testData.length > 0) {
|
|
1074
|
+
lines.push("", toRow(["TEST DATA"]), toRow([...TEST_DATA_CSV_COLUMNS]), ...testData.map(testDataRow));
|
|
1075
|
+
}
|
|
1076
|
+
return UTF8_BOM + lines.join("\r\n") + "\r\n";
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// src/commands/scan.ts
|
|
1080
|
+
async function runScan(options) {
|
|
1081
|
+
console.log(`\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2A\u0E33\u0E23\u0E27\u0E08 ${options.url} ...`);
|
|
1082
|
+
const result = await exploreWebsite(options.url, {
|
|
1083
|
+
...options.maxPages !== void 0 ? { maxPages: options.maxPages } : {},
|
|
1084
|
+
...options.maxDepth !== void 0 ? { maxDepth: options.maxDepth } : {}
|
|
1085
|
+
});
|
|
1086
|
+
const testCases = generateTestCases(result.pages);
|
|
1087
|
+
const testData = generateTestData(result.pages);
|
|
1088
|
+
for (const page of result.pages) {
|
|
1089
|
+
console.log(` \u2713 [depth ${page.depth}] ${page.title || "(no title)"} \u2014 ${page.finalUrl}`);
|
|
1090
|
+
}
|
|
1091
|
+
for (const issue of result.issues) {
|
|
1092
|
+
console.log(` ! ${issue.url} \u2014 ${issue.message}`);
|
|
1093
|
+
}
|
|
1094
|
+
console.log(
|
|
1095
|
+
`
|
|
1096
|
+
\u0E2A\u0E23\u0E38\u0E1B: ${result.pages.length} \u0E2B\u0E19\u0E49\u0E32 \xB7 ${testCases.length} test case \xB7 ${testData.length} test data \xB7 ${(result.stats.durationMs / 1e3).toFixed(1)} \u0E27\u0E34\u0E19\u0E32\u0E17\u0E35 \xB7 \u0E43\u0E0A\u0E49 ${result.stats.browser}`
|
|
1097
|
+
);
|
|
1098
|
+
if (result.pages.length === 0) {
|
|
1099
|
+
console.error("\u0E40\u0E1B\u0E34\u0E14\u0E40\u0E27\u0E47\u0E1A\u0E44\u0E0B\u0E15\u0E4C\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08 \u0E08\u0E36\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E43\u0E2B\u0E49\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01");
|
|
1100
|
+
process.exitCode = 1;
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
const csvPath = resolve(options.csvPath ?? "lazyscout-testcases.csv");
|
|
1104
|
+
await writeFile(csvPath, exportTestCasesToCsv(testCases, testData), "utf8");
|
|
1105
|
+
console.log(`\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 CSV: ${csvPath}`);
|
|
1106
|
+
if (options.jsonPath) {
|
|
1107
|
+
const jsonPath = resolve(options.jsonPath);
|
|
1108
|
+
await writeFile(jsonPath, JSON.stringify({ ...result, testCases, testData }, null, 2), "utf8");
|
|
1109
|
+
console.log(`\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 JSON: ${jsonPath}`);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
// src/commands/serve.ts
|
|
1114
|
+
import { dirname, join } from "node:path";
|
|
1115
|
+
import { fileURLToPath } from "node:url";
|
|
1116
|
+
|
|
1117
|
+
// ../server/dist/app.js
|
|
1118
|
+
import Fastify from "fastify";
|
|
1119
|
+
import fastifyStatic from "@fastify/static";
|
|
1120
|
+
|
|
1121
|
+
// ../server/dist/config.js
|
|
1122
|
+
var config = {
|
|
1123
|
+
host: process.env.HOST ?? "127.0.0.1",
|
|
1124
|
+
port: Number(process.env.PORT ?? 4e3),
|
|
1125
|
+
urlPolicy: process.env.LAZYSCOUT_MODE === "public" ? PUBLIC_SAAS_POLICY : LOCAL_QA_POLICY,
|
|
1126
|
+
limits: {
|
|
1127
|
+
maxPages: 20,
|
|
1128
|
+
maxDepth: 3
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
function clamp(value, min, max, fallback) {
|
|
1132
|
+
if (value === void 0 || Number.isNaN(value))
|
|
1133
|
+
return fallback;
|
|
1134
|
+
return Math.min(Math.max(Math.trunc(value), min), max);
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
// ../server/dist/toApiError.js
|
|
1138
|
+
function toApiError(error) {
|
|
1139
|
+
if (error instanceof ExplorerError) {
|
|
1140
|
+
const status = error.code === "invalid-url" || error.code === "blocked-url" ? 400 : 502;
|
|
1141
|
+
return {
|
|
1142
|
+
status,
|
|
1143
|
+
body: { error: { code: error.code, message: error.message, hint: error.hint } }
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
return {
|
|
1147
|
+
status: 500,
|
|
1148
|
+
body: {
|
|
1149
|
+
error: {
|
|
1150
|
+
code: "internal-error",
|
|
1151
|
+
message: "\u0E40\u0E01\u0E34\u0E14\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14\u0E20\u0E32\u0E22\u0E43\u0E19\u0E23\u0E30\u0E1A\u0E1A\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E27\u0E34\u0E40\u0E04\u0E23\u0E32\u0E30\u0E2B\u0E4C\u0E40\u0E27\u0E47\u0E1A\u0E44\u0E0B\u0E15\u0E4C",
|
|
1152
|
+
hint: "\u0E25\u0E2D\u0E07\u0E43\u0E2B\u0E21\u0E48\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07 \u0E2B\u0E23\u0E37\u0E2D\u0E14\u0E39 log \u0E02\u0E2D\u0E07\u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E2B\u0E32\u0E2A\u0E32\u0E40\u0E2B\u0E15\u0E38"
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// ../server/dist/routes/analyze.js
|
|
1159
|
+
function registerAnalyzeRoute(app) {
|
|
1160
|
+
app.post("/api/analyze", async (request, reply) => {
|
|
1161
|
+
const body = request.body ?? {};
|
|
1162
|
+
if (typeof body.url !== "string" || !body.url.trim()) {
|
|
1163
|
+
return reply.status(400).send({
|
|
1164
|
+
error: { code: "invalid-url", message: "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38 URL \u0E17\u0E35\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23\u0E27\u0E34\u0E40\u0E04\u0E23\u0E32\u0E30\u0E2B\u0E4C" }
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
const check = checkTargetUrl(body.url, config.urlPolicy);
|
|
1168
|
+
if (!check.ok) {
|
|
1169
|
+
return reply.status(400).send({ error: { code: check.code, message: check.message } });
|
|
1170
|
+
}
|
|
1171
|
+
try {
|
|
1172
|
+
const result = await exploreWebsite(check.url.toString(), {
|
|
1173
|
+
maxPages: clamp(body.maxPages, 1, config.limits.maxPages, config.limits.maxPages),
|
|
1174
|
+
maxDepth: clamp(body.maxDepth, 0, config.limits.maxDepth, config.limits.maxDepth)
|
|
1175
|
+
}, config.urlPolicy);
|
|
1176
|
+
if (result.pages.length === 0) {
|
|
1177
|
+
const firstIssue = result.issues[0];
|
|
1178
|
+
throw new ExplorerError(firstIssue?.code ?? "navigation-failed", firstIssue?.message ?? "\u0E40\u0E1B\u0E34\u0E14\u0E40\u0E27\u0E47\u0E1A\u0E44\u0E0B\u0E15\u0E4C\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08", "\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E27\u0E48\u0E32 URL \u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07\u0E41\u0E25\u0E30\u0E40\u0E27\u0E47\u0E1A\u0E44\u0E0B\u0E15\u0E4C\u0E01\u0E33\u0E25\u0E31\u0E07\u0E17\u0E33\u0E07\u0E32\u0E19\u0E2D\u0E22\u0E39\u0E48");
|
|
1179
|
+
}
|
|
1180
|
+
const response = {
|
|
1181
|
+
startUrl: result.startUrl,
|
|
1182
|
+
origin: result.origin,
|
|
1183
|
+
pages: result.pages,
|
|
1184
|
+
testCases: generateTestCases(result.pages),
|
|
1185
|
+
testData: generateTestData(result.pages),
|
|
1186
|
+
issues: result.issues,
|
|
1187
|
+
stats: result.stats
|
|
1188
|
+
};
|
|
1189
|
+
return reply.send(response);
|
|
1190
|
+
} catch (error) {
|
|
1191
|
+
request.log.error({ err: error }, "analyze failed");
|
|
1192
|
+
const { status, body: errorBody } = toApiError(error);
|
|
1193
|
+
return reply.status(status).send(errorBody);
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// ../server/dist/routes/exportCsv.js
|
|
1199
|
+
function registerExportCsvRoute(app) {
|
|
1200
|
+
app.post("/api/export/csv", async (request, reply) => {
|
|
1201
|
+
const body = request.body ?? {};
|
|
1202
|
+
if (!Array.isArray(body.testCases) || body.testCases.length === 0) {
|
|
1203
|
+
return reply.status(400).send({
|
|
1204
|
+
error: { code: "empty-export", message: "\u0E44\u0E21\u0E48\u0E21\u0E35 test case \u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A export" }
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
const csv = exportTestCasesToCsv(body.testCases, Array.isArray(body.testData) ? body.testData : []);
|
|
1208
|
+
const filename = `lazyscout-testcases-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.csv`;
|
|
1209
|
+
return reply.header("Content-Type", "text/csv; charset=utf-8").header("Content-Disposition", `attachment; filename="${filename}"`).send(csv);
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
// ../server/dist/app.js
|
|
1214
|
+
function buildApp(options = {}) {
|
|
1215
|
+
const app = Fastify({
|
|
1216
|
+
logger: { level: options.logLevel ?? process.env.LOG_LEVEL ?? "info" },
|
|
1217
|
+
// การ crawl ใช้เวลานาน จึงต้องยืด timeout ของ request ให้พอ
|
|
1218
|
+
connectionTimeout: 0,
|
|
1219
|
+
bodyLimit: 10 * 1024 * 1024
|
|
1220
|
+
});
|
|
1221
|
+
app.get("/api/health", async () => ({ status: "ok" }));
|
|
1222
|
+
registerAnalyzeRoute(app);
|
|
1223
|
+
registerExportCsvRoute(app);
|
|
1224
|
+
if (options.staticDir) {
|
|
1225
|
+
app.register(fastifyStatic, { root: options.staticDir });
|
|
1226
|
+
app.setNotFoundHandler(async (request, reply) => {
|
|
1227
|
+
if (request.url.startsWith("/api/")) {
|
|
1228
|
+
return reply.status(404).send({ error: { code: "not-found", message: "\u0E44\u0E21\u0E48\u0E1E\u0E1A endpoint \u0E19\u0E35\u0E49" } });
|
|
1229
|
+
}
|
|
1230
|
+
return reply.sendFile("index.html");
|
|
1231
|
+
});
|
|
1232
|
+
} else {
|
|
1233
|
+
app.setNotFoundHandler(async (_request, reply) => reply.status(404).send({ error: { code: "not-found", message: "\u0E44\u0E21\u0E48\u0E1E\u0E1A endpoint \u0E19\u0E35\u0E49" } }));
|
|
1234
|
+
}
|
|
1235
|
+
return app;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// src/openInBrowser.ts
|
|
1239
|
+
import { spawn } from "node:child_process";
|
|
1240
|
+
async function openInBrowser(url) {
|
|
1241
|
+
const [command, args] = process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : process.platform === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
|
|
1242
|
+
try {
|
|
1243
|
+
const child = spawn(command, args, { stdio: "ignore", detached: true });
|
|
1244
|
+
child.on("error", () => void 0);
|
|
1245
|
+
child.unref();
|
|
1246
|
+
} catch {
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// src/commands/serve.ts
|
|
1251
|
+
var DEFAULT_PORT = 4321;
|
|
1252
|
+
var WEB_DIR = join(dirname(fileURLToPath(import.meta.url)), "web");
|
|
1253
|
+
async function runServe(options) {
|
|
1254
|
+
const app = buildApp({ staticDir: WEB_DIR, logLevel: "warn" });
|
|
1255
|
+
const port = await listenOnFreePort(app, options.port ?? DEFAULT_PORT);
|
|
1256
|
+
const url = `http://localhost:${port}`;
|
|
1257
|
+
console.log(`
|
|
1258
|
+
LazyScout \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E41\u0E25\u0E49\u0E27\u0E17\u0E35\u0E48 ${url}`);
|
|
1259
|
+
console.log(" \u0E01\u0E14 Ctrl+C \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E1B\u0E34\u0E14\n");
|
|
1260
|
+
if (options.open) await openInBrowser(url);
|
|
1261
|
+
}
|
|
1262
|
+
async function listenOnFreePort(app, startPort) {
|
|
1263
|
+
for (let port = startPort; port < startPort + 20; port++) {
|
|
1264
|
+
try {
|
|
1265
|
+
await app.listen({ host: "127.0.0.1", port });
|
|
1266
|
+
return port;
|
|
1267
|
+
} catch (error) {
|
|
1268
|
+
const code = error.code;
|
|
1269
|
+
if (code !== "EADDRINUSE") throw error;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
throw new Error(`\u0E2B\u0E32\u0E1E\u0E2D\u0E23\u0E4C\u0E15\u0E27\u0E48\u0E32\u0E07\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E43\u0E19\u0E0A\u0E48\u0E27\u0E07 ${startPort}-${startPort + 19}`);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
// src/version.ts
|
|
1276
|
+
var VERSION = true ? "0.1.0" : "0.0.0-dev";
|
|
1277
|
+
|
|
1278
|
+
// src/index.ts
|
|
1279
|
+
var HELP = `
|
|
1280
|
+
LazyScout ${VERSION} \u2014 \u0E27\u0E34\u0E40\u0E04\u0E23\u0E32\u0E30\u0E2B\u0E4C\u0E40\u0E27\u0E47\u0E1A\u0E44\u0E0B\u0E15\u0E4C\u0E41\u0E25\u0E49\u0E27\u0E2A\u0E23\u0E49\u0E32\u0E07 Draft Test Case \u0E43\u0E2B\u0E49 Software Tester
|
|
1281
|
+
|
|
1282
|
+
\u0E01\u0E32\u0E23\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19
|
|
1283
|
+
npx lazyscout \u0E40\u0E1B\u0E34\u0E14\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E27\u0E47\u0E1A\u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19 (\u0E41\u0E19\u0E30\u0E19\u0E33)
|
|
1284
|
+
npx lazyscout scan <url> \u0E2A\u0E41\u0E01\u0E19\u0E41\u0E25\u0E49\u0E27\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01\u0E1C\u0E25\u0E40\u0E1B\u0E47\u0E19\u0E44\u0E1F\u0E25\u0E4C \u0E44\u0E21\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E34\u0E14\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C
|
|
1285
|
+
|
|
1286
|
+
\u0E15\u0E31\u0E27\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E02\u0E2D\u0E07 scan
|
|
1287
|
+
--csv <\u0E44\u0E1F\u0E25\u0E4C> \u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 test case + test data \u0E40\u0E1B\u0E47\u0E19 CSV (\u0E04\u0E48\u0E32\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19: lazyscout-testcases.csv)
|
|
1288
|
+
--json <\u0E44\u0E1F\u0E25\u0E4C> \u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01\u0E1C\u0E25\u0E14\u0E34\u0E1A\u0E17\u0E31\u0E49\u0E07\u0E2B\u0E21\u0E14\u0E40\u0E1B\u0E47\u0E19 JSON
|
|
1289
|
+
--max-pages <n> \u0E08\u0E33\u0E19\u0E27\u0E19\u0E2B\u0E19\u0E49\u0E32\u0E2A\u0E39\u0E07\u0E2A\u0E38\u0E14 (\u0E04\u0E48\u0E32\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19 20)
|
|
1290
|
+
--max-depth <n> \u0E04\u0E27\u0E32\u0E21\u0E25\u0E36\u0E01\u0E2A\u0E39\u0E07\u0E2A\u0E38\u0E14 (\u0E04\u0E48\u0E32\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19 3)
|
|
1291
|
+
|
|
1292
|
+
\u0E15\u0E31\u0E27\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E02\u0E2D\u0E07\u0E01\u0E32\u0E23\u0E40\u0E1B\u0E34\u0E14\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E27\u0E47\u0E1A
|
|
1293
|
+
--port <n> \u0E1E\u0E2D\u0E23\u0E4C\u0E15\u0E17\u0E35\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23 (\u0E04\u0E48\u0E32\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19 4321)
|
|
1294
|
+
--no-open \u0E44\u0E21\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E34\u0E14\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C\u0E43\u0E2B\u0E49\u0E2D\u0E31\u0E15\u0E42\u0E19\u0E21\u0E31\u0E15\u0E34
|
|
1295
|
+
|
|
1296
|
+
\u0E15\u0E31\u0E27\u0E2D\u0E22\u0E48\u0E32\u0E07
|
|
1297
|
+
npx lazyscout
|
|
1298
|
+
npx lazyscout scan http://localhost:5173
|
|
1299
|
+
npx lazyscout scan https://example.com --max-pages 10 --csv report.csv
|
|
1300
|
+
|
|
1301
|
+
Explorer \u0E2A\u0E33\u0E23\u0E27\u0E08\u0E40\u0E09\u0E1E\u0E32\u0E30 origin \u0E40\u0E14\u0E35\u0E22\u0E27\u0E01\u0E31\u0E19 \u0E40\u0E14\u0E34\u0E19\u0E14\u0E49\u0E27\u0E22\u0E25\u0E34\u0E07\u0E01\u0E4C\u0E40\u0E17\u0E48\u0E32\u0E19\u0E31\u0E49\u0E19 \u0E44\u0E21\u0E48\u0E04\u0E25\u0E34\u0E01\u0E1B\u0E38\u0E48\u0E21\u0E41\u0E25\u0E30\u0E44\u0E21\u0E48 submit form
|
|
1302
|
+
`;
|
|
1303
|
+
async function main() {
|
|
1304
|
+
const { values, positionals } = parseArgs({
|
|
1305
|
+
allowPositionals: true,
|
|
1306
|
+
options: {
|
|
1307
|
+
help: { type: "boolean", short: "h", default: false },
|
|
1308
|
+
version: { type: "boolean", short: "v", default: false },
|
|
1309
|
+
csv: { type: "string" },
|
|
1310
|
+
json: { type: "string" },
|
|
1311
|
+
"max-pages": { type: "string" },
|
|
1312
|
+
"max-depth": { type: "string" },
|
|
1313
|
+
port: { type: "string" },
|
|
1314
|
+
// parseArgs ของ Node ไม่แปลง --no-open ให้เอง ต้องประกาศเป็น option แยก
|
|
1315
|
+
"no-open": { type: "boolean", default: false }
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
if (values.version) {
|
|
1319
|
+
console.log(VERSION);
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
const command = positionals[0];
|
|
1323
|
+
if (values.help || command === "help") {
|
|
1324
|
+
console.log(HELP);
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
switch (command) {
|
|
1328
|
+
case void 0:
|
|
1329
|
+
case "serve":
|
|
1330
|
+
await runServe({ port: values.port ? Number(values.port) : void 0, open: !values["no-open"] });
|
|
1331
|
+
return;
|
|
1332
|
+
case "scan": {
|
|
1333
|
+
const url = positionals[1];
|
|
1334
|
+
if (!url) {
|
|
1335
|
+
console.error("\u0E15\u0E49\u0E2D\u0E07\u0E23\u0E30\u0E1A\u0E38 URL \u0E40\u0E0A\u0E48\u0E19: npx lazyscout scan http://localhost:5173");
|
|
1336
|
+
process.exitCode = 1;
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
await runScan({
|
|
1340
|
+
url,
|
|
1341
|
+
csvPath: values.csv,
|
|
1342
|
+
jsonPath: values.json,
|
|
1343
|
+
maxPages: values["max-pages"] ? Number(values["max-pages"]) : void 0,
|
|
1344
|
+
maxDepth: values["max-depth"] ? Number(values["max-depth"]) : void 0
|
|
1345
|
+
});
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
default:
|
|
1349
|
+
console.error(`\u0E44\u0E21\u0E48\u0E23\u0E39\u0E49\u0E08\u0E31\u0E01\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07 "${command}" \u2014 \u0E14\u0E39\u0E27\u0E34\u0E18\u0E35\u0E43\u0E0A\u0E49\u0E14\u0E49\u0E27\u0E22: npx lazyscout --help`);
|
|
1350
|
+
process.exitCode = 1;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
main().catch((error) => {
|
|
1354
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1355
|
+
const hint = error && typeof error === "object" && "hint" in error ? String(error.hint) : void 0;
|
|
1356
|
+
console.error(`
|
|
1357
|
+
\u2716 ${message}`);
|
|
1358
|
+
if (hint) console.error(` ${hint}`);
|
|
1359
|
+
process.exitCode = 1;
|
|
1360
|
+
});
|