@auto-wiz/playwright 1.2.0 → 1.3.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 +4 -0
- package/dist/runner.js +17 -15
- package/package.json +3 -3
package/dist/runner.d.ts
CHANGED
|
@@ -3,5 +3,9 @@ import { Page } from "playwright";
|
|
|
3
3
|
export declare class PlaywrightFlowRunner implements FlowRunner<Page> {
|
|
4
4
|
run(flow: Flow, page: Page, options?: RunnerOptions): Promise<RunResult>;
|
|
5
5
|
runStep(step: Step, page: Page, options?: RunnerOptions): Promise<ExecutionResult>;
|
|
6
|
+
/**
|
|
7
|
+
* Resolve placeholders in text (e.g., {{username}} → variables.username)
|
|
8
|
+
*/
|
|
9
|
+
private resolveText;
|
|
6
10
|
private resolveLocator;
|
|
7
11
|
}
|
package/dist/runner.js
CHANGED
|
@@ -76,7 +76,8 @@ class PlaywrightFlowRunner {
|
|
|
76
76
|
}
|
|
77
77
|
case "type": {
|
|
78
78
|
const locator = await this.resolveLocator(page, step, timeout);
|
|
79
|
-
const
|
|
79
|
+
const rawText = step.text || step.originalText || "";
|
|
80
|
+
const text = this.resolveText(rawText, options.variables);
|
|
80
81
|
await locator.fill(text, { timeout });
|
|
81
82
|
if (step.submit) {
|
|
82
83
|
await locator.press("Enter");
|
|
@@ -234,7 +235,7 @@ class PlaywrightFlowRunner {
|
|
|
234
235
|
return { success: true, extractedData: text?.trim() };
|
|
235
236
|
}
|
|
236
237
|
case "waitFor": {
|
|
237
|
-
if (step.
|
|
238
|
+
if (step.locator) {
|
|
238
239
|
// resolveLocator internally waits for visibility, so this is implicitly handled,
|
|
239
240
|
// but we call it to ensure we find the valid element.
|
|
240
241
|
await this.resolveLocator(page, step, step.timeoutMs || timeout);
|
|
@@ -251,27 +252,28 @@ class PlaywrightFlowRunner {
|
|
|
251
252
|
return { success: false, error: error.message };
|
|
252
253
|
}
|
|
253
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Resolve placeholders in text (e.g., {{username}} → variables.username)
|
|
257
|
+
*/
|
|
258
|
+
resolveText(text, variables) {
|
|
259
|
+
if (!variables || !text)
|
|
260
|
+
return text;
|
|
261
|
+
return text.replace(/\{\{(\w+)\}\}/g, (_, key) => variables[key] ?? "");
|
|
262
|
+
}
|
|
254
263
|
async resolveLocator(page, step, timeout) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if ("locator" in step && step.locator) {
|
|
258
|
-
const { primary, fallbacks = [] } = step.locator;
|
|
259
|
-
candidates.push(primary, ...fallbacks);
|
|
260
|
-
}
|
|
261
|
-
else if ("selector" in step && step.selector) {
|
|
262
|
-
candidates.push(step.selector);
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
throw new Error(`Step ${step.type} requires a selector or locator`);
|
|
264
|
+
if (!("locator" in step) || !step.locator) {
|
|
265
|
+
throw new Error(`Step ${step.type} requires a locator`);
|
|
266
266
|
}
|
|
267
|
+
const { primary, fallbacks = [] } = step.locator;
|
|
268
|
+
const candidates = [primary, ...fallbacks];
|
|
267
269
|
if (candidates.length === 0) {
|
|
268
270
|
throw new Error(`Step ${step.type} has no valid selectors`);
|
|
269
271
|
}
|
|
270
|
-
//
|
|
272
|
+
// If only one candidate, just return it (Playwright's default behavior)
|
|
271
273
|
if (candidates.length === 1) {
|
|
272
274
|
return page.locator(candidates[0]).first();
|
|
273
275
|
}
|
|
274
|
-
//
|
|
276
|
+
// Parallel Race: Check all candidates for visibility
|
|
275
277
|
// We create a promise for each candidate that resolves if the element becomes visible
|
|
276
278
|
// and returns the corresponding Locator.
|
|
277
279
|
const promises = candidates.map(async (selector) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auto-wiz/playwright",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "JaeSang",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@auto-wiz/core": "^1.
|
|
26
|
+
"@auto-wiz/core": "^1.2.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"playwright": "^1.40.0"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"typescript": "^5.0.0",
|
|
33
33
|
"@types/node": "^20.0.0",
|
|
34
|
-
"@auto-wiz/core": "1.1
|
|
34
|
+
"@auto-wiz/core": "1.2.1"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsc"
|