@auto-wiz/dom 1.0.2 → 1.1.1
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/runner.d.ts +2 -3
- package/dist/runner.js +4 -6
- package/dist/steps/stepExecution.d.ts +5 -6
- package/dist/steps/stepExecution.js +29 -43
- package/package.json +2 -2
package/dist/runner.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type FlowRunner, type RunResult, type ExecutionResult, type RunnerOptions, type Flow, type Step } from "@auto-wiz/core";
|
|
2
2
|
export declare class DomFlowRunner implements FlowRunner<void> {
|
|
3
|
-
run(flow: Flow, _context?: any,
|
|
4
|
-
|
|
5
|
-
runStep(step: Step): Promise<ExecutionResult>;
|
|
3
|
+
run(flow: Flow, _context?: any, options?: RunnerOptions): Promise<RunResult>;
|
|
4
|
+
runStep(step: Step, _context?: void, options?: RunnerOptions): Promise<ExecutionResult>;
|
|
6
5
|
}
|
package/dist/runner.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { executeStep } from "./steps/stepExecution";
|
|
2
2
|
export class DomFlowRunner {
|
|
3
|
-
async run(flow, _context = {},
|
|
4
|
-
_options = {} // unused
|
|
5
|
-
) {
|
|
3
|
+
async run(flow, _context = {}, options = {}) {
|
|
6
4
|
const extractedData = {};
|
|
7
5
|
const steps = flow.steps;
|
|
8
6
|
for (let i = 0; i < steps.length; i++) {
|
|
9
7
|
const step = steps[i];
|
|
10
8
|
try {
|
|
11
|
-
const result = await this.runStep(step);
|
|
9
|
+
const result = await this.runStep(step, undefined, options);
|
|
12
10
|
if (!result.success) {
|
|
13
11
|
return {
|
|
14
12
|
success: false,
|
|
@@ -32,10 +30,10 @@ export class DomFlowRunner {
|
|
|
32
30
|
}
|
|
33
31
|
return { success: true, extractedData };
|
|
34
32
|
}
|
|
35
|
-
async runStep(step) {
|
|
33
|
+
async runStep(step, _context, options = {}) {
|
|
36
34
|
try {
|
|
37
35
|
// Direct DOM execution using existing logic
|
|
38
|
-
const result = await executeStep(step);
|
|
36
|
+
const result = await executeStep(step, options);
|
|
39
37
|
return result;
|
|
40
38
|
}
|
|
41
39
|
catch (error) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { Step } from "@auto-wiz/core";
|
|
1
|
+
import type { Step, RunnerOptions } from "@auto-wiz/core";
|
|
2
2
|
/**
|
|
3
3
|
* Step execution 유틸리티
|
|
4
4
|
* 각 Step 타입별 실행 로직
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* - step.locator
|
|
8
|
-
* - 없으면 기존 step.selector 사용 (하위 호환성)
|
|
6
|
+
* locator 시스템 사용:
|
|
7
|
+
* - step.locator의 다중 selector fallback 사용
|
|
9
8
|
*/
|
|
10
9
|
export interface ExecutionResult {
|
|
11
10
|
success: boolean;
|
|
@@ -20,7 +19,7 @@ export declare function executeClickStep(step: Step): Promise<ExecutionResult>;
|
|
|
20
19
|
/**
|
|
21
20
|
* Type step 실행
|
|
22
21
|
*/
|
|
23
|
-
export declare function executeTypeStep(step: Step): Promise<ExecutionResult>;
|
|
22
|
+
export declare function executeTypeStep(step: Step, options?: RunnerOptions): Promise<ExecutionResult>;
|
|
24
23
|
/**
|
|
25
24
|
* Select step 실행
|
|
26
25
|
*/
|
|
@@ -36,4 +35,4 @@ export declare function executeWaitForStep(step: Step): Promise<ExecutionResult>
|
|
|
36
35
|
/**
|
|
37
36
|
* Step 실행 (타입에 따라 자동 분기)
|
|
38
37
|
*/
|
|
39
|
-
export declare function executeStep(step: Step): Promise<ExecutionResult>;
|
|
38
|
+
export declare function executeStep(step: Step, options?: RunnerOptions): Promise<ExecutionResult>;
|
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
import { querySelector } from "../selectors/selectorGenerator";
|
|
2
1
|
import { waitForLocator, isInteractable } from "../selectors/locatorUtils";
|
|
3
2
|
/**
|
|
4
|
-
* Step에서 요소 찾기 (locator
|
|
3
|
+
* Step에서 요소 찾기 (locator 시스템 사용)
|
|
5
4
|
*/
|
|
6
5
|
async function findElement(step) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
const element = await waitForLocator(step.locator, {
|
|
11
|
-
timeout: step.timeoutMs || 5000,
|
|
12
|
-
visible: true,
|
|
13
|
-
interactable: true,
|
|
14
|
-
});
|
|
15
|
-
return { element, usedSelector: step.locator.primary };
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
// Locator로 찾지 못하면 selector로 폴백
|
|
19
|
-
console.warn("Locator failed, falling back to selector", error);
|
|
20
|
-
}
|
|
6
|
+
if (!("locator" in step) || !step.locator) {
|
|
7
|
+
return { element: null, usedSelector: "none" };
|
|
21
8
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
try {
|
|
10
|
+
const element = await waitForLocator(step.locator, {
|
|
11
|
+
timeout: step.timeoutMs || 5000,
|
|
12
|
+
visible: true,
|
|
13
|
+
interactable: true,
|
|
14
|
+
});
|
|
15
|
+
return { element, usedSelector: step.locator.primary };
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.warn("Locator failed:", error);
|
|
19
|
+
return { element: null, usedSelector: step.locator.primary };
|
|
26
20
|
}
|
|
27
|
-
return { element: null, usedSelector: "none" };
|
|
28
21
|
}
|
|
29
22
|
/**
|
|
30
23
|
* Click step 실행
|
|
@@ -59,10 +52,18 @@ export async function executeClickStep(step) {
|
|
|
59
52
|
};
|
|
60
53
|
}
|
|
61
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Resolve placeholders in text (e.g., {{username}} → variables.username)
|
|
57
|
+
*/
|
|
58
|
+
function resolveText(text, variables) {
|
|
59
|
+
if (!variables || !text)
|
|
60
|
+
return text;
|
|
61
|
+
return text.replace(/\{\{(\w+)\}\}/g, (_, key) => variables[key] ?? "");
|
|
62
|
+
}
|
|
62
63
|
/**
|
|
63
64
|
* Type step 실행
|
|
64
65
|
*/
|
|
65
|
-
export async function executeTypeStep(step) {
|
|
66
|
+
export async function executeTypeStep(step, options = {}) {
|
|
66
67
|
if (step.type !== "type") {
|
|
67
68
|
return { success: false, error: "Invalid type step" };
|
|
68
69
|
}
|
|
@@ -88,7 +89,8 @@ export async function executeTypeStep(step) {
|
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
try {
|
|
91
|
-
const
|
|
92
|
+
const rawText = step.originalText || step.text || "";
|
|
93
|
+
const text = resolveText(rawText, options.variables);
|
|
92
94
|
element.value = text;
|
|
93
95
|
element.dispatchEvent(new Event("input", { bubbles: true }));
|
|
94
96
|
element.dispatchEvent(new Event("change", { bubbles: true }));
|
|
@@ -231,7 +233,7 @@ export async function executeWaitForStep(step) {
|
|
|
231
233
|
return { success: false, error: "Invalid waitFor step" };
|
|
232
234
|
}
|
|
233
235
|
// 단순 timeout인 경우
|
|
234
|
-
if (!("
|
|
236
|
+
if (!("locator" in step) && step.timeoutMs) {
|
|
235
237
|
await new Promise((resolve) => setTimeout(resolve, step.timeoutMs));
|
|
236
238
|
return { success: true };
|
|
237
239
|
}
|
|
@@ -245,25 +247,9 @@ export async function executeWaitForStep(step) {
|
|
|
245
247
|
});
|
|
246
248
|
return { success: true, usedSelector: step.locator.primary };
|
|
247
249
|
}
|
|
248
|
-
// selector가 있으면 기존 방식 (하위 호환성)
|
|
249
|
-
if ("selector" in step && step.selector) {
|
|
250
|
-
const startTime = Date.now();
|
|
251
|
-
const pollInterval = 100;
|
|
252
|
-
while (Date.now() - startTime < timeout) {
|
|
253
|
-
const element = querySelector(step.selector);
|
|
254
|
-
if (element) {
|
|
255
|
-
return { success: true, usedSelector: step.selector };
|
|
256
|
-
}
|
|
257
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
258
|
-
}
|
|
259
|
-
return {
|
|
260
|
-
success: false,
|
|
261
|
-
error: `Timeout waiting for element: ${step.selector}`,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
250
|
return {
|
|
265
251
|
success: false,
|
|
266
|
-
error: "WaitFor step requires
|
|
252
|
+
error: "WaitFor step requires locator or timeoutMs",
|
|
267
253
|
};
|
|
268
254
|
}
|
|
269
255
|
catch (error) {
|
|
@@ -276,13 +262,13 @@ export async function executeWaitForStep(step) {
|
|
|
276
262
|
/**
|
|
277
263
|
* Step 실행 (타입에 따라 자동 분기)
|
|
278
264
|
*/
|
|
279
|
-
export async function executeStep(step) {
|
|
265
|
+
export async function executeStep(step, options = {}) {
|
|
280
266
|
try {
|
|
281
267
|
switch (step.type) {
|
|
282
268
|
case "click":
|
|
283
269
|
return await executeClickStep(step);
|
|
284
270
|
case "type":
|
|
285
|
-
return await executeTypeStep(step);
|
|
271
|
+
return await executeTypeStep(step, options);
|
|
286
272
|
case "select":
|
|
287
273
|
return await executeSelectStep(step);
|
|
288
274
|
case "extract":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auto-wiz/dom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "JaeSang",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@auto-wiz/core": "1.
|
|
26
|
+
"@auto-wiz/core": "1.2.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"typescript": "^5.0.0"
|