@rettangoli/vt 0.0.7 → 0.0.9
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/package.json +1 -1
- package/src/createSteps.js +83 -14
package/package.json
CHANGED
package/src/createSteps.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
async function click(page, args) {
|
|
2
|
-
|
|
1
|
+
async function click(page, args, context, selectedElement) {
|
|
2
|
+
if (selectedElement) {
|
|
3
|
+
await selectedElement.click();
|
|
4
|
+
} else if (args.length >= 2) {
|
|
5
|
+
await page.mouse.click(Number(args[0]), Number(args[1]), { button: "left" });
|
|
6
|
+
} else {
|
|
7
|
+
console.warn('`click` command needs a `select` block or coordinates.');
|
|
8
|
+
}
|
|
3
9
|
}
|
|
4
10
|
|
|
5
11
|
async function customEvent(page, args) {
|
|
@@ -30,28 +36,68 @@ async function mouseUp(page) {
|
|
|
30
36
|
await page.mouse.up();
|
|
31
37
|
}
|
|
32
38
|
|
|
39
|
+
async function rMouseDown(page){
|
|
40
|
+
await page.mouse.down({ button: 'right' });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function rMouseUp(page){
|
|
44
|
+
await page.mouse.up({ button: 'right' });
|
|
45
|
+
}
|
|
46
|
+
|
|
33
47
|
async function move(page, args) {
|
|
34
48
|
await page.mouse.move(Number(args[0]), Number(args[1]));
|
|
35
49
|
}
|
|
36
50
|
|
|
37
|
-
async function rclick(page, args) {
|
|
38
|
-
|
|
51
|
+
async function rclick(page, args, context, selectedElement) {
|
|
52
|
+
if (selectedElement) {
|
|
53
|
+
await selectedElement.click({ button: 'right' });
|
|
54
|
+
} else if (args.length >= 2) {
|
|
55
|
+
await page.mouse.click(Number(args[0]), Number(args[1]), { button: "right" });
|
|
56
|
+
} else {
|
|
57
|
+
console.warn('`rclick` command needs a `select` block or coordinates.');
|
|
58
|
+
}
|
|
39
59
|
}
|
|
40
60
|
|
|
41
61
|
async function wait(page, args) {
|
|
42
62
|
await page.waitForTimeout(Number(args[0]));
|
|
43
63
|
}
|
|
44
64
|
|
|
65
|
+
async function write(page, args, context, selectedElement) {
|
|
66
|
+
if (selectedElement) {
|
|
67
|
+
const textToWrite = args.join(' ');
|
|
68
|
+
await selectedElement.fill(textToWrite);
|
|
69
|
+
} else {
|
|
70
|
+
console.warn('`write` command called without a `select` block.');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function select(page, args) {
|
|
75
|
+
const testId = args[0];
|
|
76
|
+
const hostElementLocator = page.getByTestId(testId);
|
|
77
|
+
|
|
78
|
+
const interactiveElementLocator = hostElementLocator.locator(
|
|
79
|
+
'input, textarea, button, select, a'
|
|
80
|
+
).first();
|
|
81
|
+
|
|
82
|
+
const count = await interactiveElementLocator.count();
|
|
83
|
+
|
|
84
|
+
if (count > 0) {
|
|
85
|
+
return interactiveElementLocator;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return hostElementLocator;
|
|
89
|
+
}
|
|
90
|
+
|
|
45
91
|
export function createSteps(page, context) {
|
|
46
92
|
let screenshotIndex = 0;
|
|
47
93
|
|
|
48
|
-
async function screenshot(
|
|
94
|
+
async function screenshot() {
|
|
49
95
|
screenshotIndex++;
|
|
50
96
|
const screenshotPath = await context.takeAndSaveScreenshot(page, `${context.baseName}-${screenshotIndex}`);
|
|
51
97
|
console.log(`Screenshot saved: ${screenshotPath}`);
|
|
52
98
|
}
|
|
53
99
|
|
|
54
|
-
const
|
|
100
|
+
const actionHandlers = {
|
|
55
101
|
click,
|
|
56
102
|
customEvent,
|
|
57
103
|
goto,
|
|
@@ -60,19 +106,42 @@ export function createSteps(page, context) {
|
|
|
60
106
|
mouseUp,
|
|
61
107
|
move,
|
|
62
108
|
rclick,
|
|
109
|
+
rMouseDown,
|
|
110
|
+
rMouseUp,
|
|
63
111
|
screenshot,
|
|
112
|
+
select,
|
|
64
113
|
wait,
|
|
114
|
+
write,
|
|
65
115
|
};
|
|
66
116
|
|
|
117
|
+
async function executeSingleStep(stepString, selectedElement) {
|
|
118
|
+
const [command, ...args] = stepString.split(" ");
|
|
119
|
+
const actionFn = actionHandlers[command];
|
|
120
|
+
if (actionFn) {
|
|
121
|
+
await actionFn(page, args, context, selectedElement);
|
|
122
|
+
} else {
|
|
123
|
+
console.warn(`Unknown step command: "${command}"`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
67
127
|
return {
|
|
68
|
-
async executeStep(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
128
|
+
async executeStep(step) {
|
|
129
|
+
if (typeof step === 'string') {
|
|
130
|
+
await executeSingleStep(step, null);
|
|
131
|
+
} else if (typeof step === 'object' && step !== null) {
|
|
132
|
+
const blockCommandString = Object.keys(step)[0];
|
|
133
|
+
const nestedStepStrings = step[blockCommandString];
|
|
134
|
+
const [command, ...args] = blockCommandString.split(" ");
|
|
135
|
+
|
|
136
|
+
const blockFn = actionHandlers[command];
|
|
137
|
+
if (blockFn) {
|
|
138
|
+
const selectedElement = await blockFn(page, args, context, null);
|
|
139
|
+
for (const nestedStep of nestedStepStrings) {
|
|
140
|
+
await executeSingleStep(nestedStep, selectedElement);
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
console.warn(`Unsupported block command: "${command}".`);
|
|
144
|
+
}
|
|
76
145
|
}
|
|
77
146
|
}
|
|
78
147
|
};
|