@auto-wiz/playwright 1.0.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/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/runner.d.ts +7 -0
- package/dist/runner.js +102 -0
- package/package.json +36 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./runner";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./runner"), exports);
|
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type FlowRunner, type RunResult, type ExecutionResult, type RunnerOptions, type Flow, type Step } from "@auto-wiz/core";
|
|
2
|
+
import { Page } from "playwright";
|
|
3
|
+
export declare class PlaywrightFlowRunner implements FlowRunner<Page> {
|
|
4
|
+
run(flow: Flow, page: Page, options?: RunnerOptions): Promise<RunResult>;
|
|
5
|
+
runStep(step: Step, page: Page, options?: RunnerOptions): Promise<ExecutionResult>;
|
|
6
|
+
private getLocator;
|
|
7
|
+
}
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlaywrightFlowRunner = void 0;
|
|
4
|
+
class PlaywrightFlowRunner {
|
|
5
|
+
async run(flow, page, options = {}) {
|
|
6
|
+
const extractedData = {};
|
|
7
|
+
for (const [index, step] of flow.steps.entries()) {
|
|
8
|
+
try {
|
|
9
|
+
const result = await this.runStep(step, page, options);
|
|
10
|
+
if (!result.success) {
|
|
11
|
+
// Playwright usually throws, but if we catch it:
|
|
12
|
+
if (options.stopOnError !== false) {
|
|
13
|
+
return {
|
|
14
|
+
success: false,
|
|
15
|
+
error: result.error,
|
|
16
|
+
failedStepIndex: index,
|
|
17
|
+
extractedData,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (result.extractedData) {
|
|
22
|
+
extractedData[`step_${index}`] = result.extractedData;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: error.message,
|
|
29
|
+
failedStepIndex: index,
|
|
30
|
+
extractedData,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { success: true, extractedData };
|
|
35
|
+
}
|
|
36
|
+
async runStep(step, page, options = {}) {
|
|
37
|
+
const timeout = options.timeout || 5000;
|
|
38
|
+
try {
|
|
39
|
+
switch (step.type) {
|
|
40
|
+
case "navigate":
|
|
41
|
+
if (step.url) {
|
|
42
|
+
await page.goto(step.url, { timeout });
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case "click": {
|
|
46
|
+
const locator = this.getLocator(page, step);
|
|
47
|
+
await locator.click({ timeout });
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "type": {
|
|
51
|
+
const locator = this.getLocator(page, step);
|
|
52
|
+
const text = step.text || step.originalText || "";
|
|
53
|
+
await locator.fill(text, { timeout });
|
|
54
|
+
if (step.submit) {
|
|
55
|
+
await locator.press("Enter");
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "select": {
|
|
60
|
+
const locator = this.getLocator(page, step);
|
|
61
|
+
if (step.value) {
|
|
62
|
+
await locator.selectOption(step.value, { timeout });
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "extract": {
|
|
67
|
+
const locator = this.getLocator(page, step);
|
|
68
|
+
const text = await locator.textContent({ timeout });
|
|
69
|
+
return { success: true, extractedData: text?.trim() };
|
|
70
|
+
}
|
|
71
|
+
case "waitFor": {
|
|
72
|
+
if (step.selector || step.locator) {
|
|
73
|
+
const locator = this.getLocator(page, step);
|
|
74
|
+
await locator.waitFor({
|
|
75
|
+
state: "visible",
|
|
76
|
+
timeout: step.timeoutMs || timeout,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else if (step.timeoutMs) {
|
|
80
|
+
await page.waitForTimeout(step.timeoutMs);
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { success: true };
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return { success: false, error: error.message };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
getLocator(page, step) {
|
|
92
|
+
if ("locator" in step && step.locator) {
|
|
93
|
+
const { primary } = step.locator;
|
|
94
|
+
return page.locator(primary).first();
|
|
95
|
+
}
|
|
96
|
+
if ("selector" in step && step.selector) {
|
|
97
|
+
return page.locator(step.selector).first();
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`Step ${step.type} requires a selector or locator`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.PlaywrightFlowRunner = PlaywrightFlowRunner;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@auto-wiz/playwright",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "JaeSang",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/JaeSang1998/automation-wizard.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"playwright": "^1.40.0",
|
|
27
|
+
"@auto-wiz/core": "1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "^5.0.0",
|
|
31
|
+
"@types/node": "^20.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc"
|
|
35
|
+
}
|
|
36
|
+
}
|