playwright-mimic 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/README.md +446 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/mimic.d.ts +26 -0
- package/dist/mimic.d.ts.map +1 -0
- package/dist/mimic.js +71 -0
- package/dist/mimic.js.map +1 -0
- package/dist/mimicry/actionType.d.ts +6 -0
- package/dist/mimicry/actionType.d.ts.map +1 -0
- package/dist/mimicry/actionType.js +32 -0
- package/dist/mimicry/actionType.js.map +1 -0
- package/dist/mimicry/click.d.ts +20 -0
- package/dist/mimicry/click.d.ts.map +1 -0
- package/dist/mimicry/click.js +152 -0
- package/dist/mimicry/click.js.map +1 -0
- package/dist/mimicry/forms.d.ts +31 -0
- package/dist/mimicry/forms.d.ts.map +1 -0
- package/dist/mimicry/forms.js +154 -0
- package/dist/mimicry/forms.js.map +1 -0
- package/dist/mimicry/navigation.d.ts +6 -0
- package/dist/mimicry/navigation.d.ts.map +1 -0
- package/dist/mimicry/navigation.js +52 -0
- package/dist/mimicry/navigation.js.map +1 -0
- package/dist/mimicry/schema/action.d.ts +312 -0
- package/dist/mimicry/schema/action.d.ts.map +1 -0
- package/dist/mimicry/schema/action.js +194 -0
- package/dist/mimicry/schema/action.js.map +1 -0
- package/dist/mimicry/selector.d.ts +118 -0
- package/dist/mimicry/selector.d.ts.map +1 -0
- package/dist/mimicry/selector.js +682 -0
- package/dist/mimicry/selector.js.map +1 -0
- package/dist/mimicry.d.ts +24 -0
- package/dist/mimicry.d.ts.map +1 -0
- package/dist/mimicry.js +71 -0
- package/dist/mimicry.js.map +1 -0
- package/dist/utils/token-counter.d.ts +63 -0
- package/dist/utils/token-counter.d.ts.map +1 -0
- package/dist/utils/token-counter.js +171 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { generateText, Output } from 'ai';
|
|
2
|
+
import { zClickActionResult } from './schema/action.js';
|
|
3
|
+
import { countTokens } from '../utils/token-counter.js';
|
|
4
|
+
/**
|
|
5
|
+
* Get click action by matching Gherkin step against captured target elements
|
|
6
|
+
*
|
|
7
|
+
* This function uses AI to analyze a Gherkin step and match it against
|
|
8
|
+
* all available target elements on the page. It returns the top 5 most
|
|
9
|
+
* likely candidates along with the appropriate click type.
|
|
10
|
+
*
|
|
11
|
+
* @param page - Playwright Page object (currently unused but kept for consistency)
|
|
12
|
+
* @param brain - LanguageModel instance for AI analysis
|
|
13
|
+
* @param gherkinStep - The Gherkin step to match (e.g., "I click on the Submit button")
|
|
14
|
+
* @param targetElements - Array of captured target elements from the page
|
|
15
|
+
* @returns Promise resolving to ClickActionResult with top candidates and click type
|
|
16
|
+
*/
|
|
17
|
+
export const getClickAction = async (_page, brain, gherkinStep, targetElements) => {
|
|
18
|
+
// Format target elements with their indices for the prompt
|
|
19
|
+
// Include all relevant identifying information
|
|
20
|
+
const elementsWithIndices = targetElements.map((element, index) => ({
|
|
21
|
+
index,
|
|
22
|
+
tag: element.tag,
|
|
23
|
+
text: element.text,
|
|
24
|
+
id: element.id,
|
|
25
|
+
role: element.role,
|
|
26
|
+
label: element.label,
|
|
27
|
+
ariaLabel: element.ariaLabel,
|
|
28
|
+
typeAttr: element.typeAttr,
|
|
29
|
+
nameAttr: element.nameAttr,
|
|
30
|
+
href: element.href,
|
|
31
|
+
dataset: element.dataset,
|
|
32
|
+
nthOfType: element.nthOfType,
|
|
33
|
+
}));
|
|
34
|
+
// Group elements by tag type
|
|
35
|
+
const elementsByTag = new Map();
|
|
36
|
+
for (const el of elementsWithIndices) {
|
|
37
|
+
const tagKey = el.tag === 'a' ? 'links' : el.tag === 'button' ? 'buttons' : el.tag === 'input' ? 'inputs' : el.tag;
|
|
38
|
+
if (!elementsByTag.has(tagKey)) {
|
|
39
|
+
elementsByTag.set(tagKey, []);
|
|
40
|
+
}
|
|
41
|
+
elementsByTag.get(tagKey).push(el);
|
|
42
|
+
}
|
|
43
|
+
// Format element fields in selector priority order, skipping null/empty values
|
|
44
|
+
const formatElement = (roleSection) => (el) => {
|
|
45
|
+
const parts = [];
|
|
46
|
+
// Priority order: testId → text → role → ariaLabel → label → name → type → href → dataAttributes → tag → id → nthOfType
|
|
47
|
+
if (el.dataset.testid) {
|
|
48
|
+
parts.push(` testId: "${el.dataset.testid}"`);
|
|
49
|
+
}
|
|
50
|
+
if (el.text && el.text.trim()) {
|
|
51
|
+
parts.push(` text: "${el.text.trim()}"`);
|
|
52
|
+
}
|
|
53
|
+
if (el.role && roleSection !== el.role) {
|
|
54
|
+
parts.push(` role: ${el.role}`);
|
|
55
|
+
}
|
|
56
|
+
if (el.ariaLabel) {
|
|
57
|
+
parts.push(` ariaLabel: "${el.ariaLabel}"`);
|
|
58
|
+
}
|
|
59
|
+
if (el.label) {
|
|
60
|
+
parts.push(` label: "${el.label}"`);
|
|
61
|
+
}
|
|
62
|
+
if (el.nameAttr) {
|
|
63
|
+
parts.push(` name: "${el.nameAttr}"`);
|
|
64
|
+
}
|
|
65
|
+
if (el.typeAttr) {
|
|
66
|
+
parts.push(` type: ${el.typeAttr}`);
|
|
67
|
+
}
|
|
68
|
+
if (el.href) {
|
|
69
|
+
parts.push(` href: "${el.href}"`);
|
|
70
|
+
}
|
|
71
|
+
if (Object.keys(el.dataset).length > 0) {
|
|
72
|
+
const dataKeys = Object.keys(el.dataset).filter(k => k !== 'testid');
|
|
73
|
+
if (dataKeys.length > 0) {
|
|
74
|
+
parts.push(` dataAttributes: ${JSON.stringify(dataKeys)}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
parts.push(` tag: ${el.tag}`);
|
|
78
|
+
// if (el.id) {
|
|
79
|
+
// parts.push(` id: "${el.id}"`);
|
|
80
|
+
// }
|
|
81
|
+
parts.push(` index: ${el.index}`);
|
|
82
|
+
if (el.nthOfType > 1) {
|
|
83
|
+
parts.push(` nthOfType: ${el.nthOfType}`);
|
|
84
|
+
}
|
|
85
|
+
return ` - ${parts.join('\n ')}`;
|
|
86
|
+
};
|
|
87
|
+
// Create formatted description grouped by tag
|
|
88
|
+
const elementsDescription = Array.from(elementsByTag.entries())
|
|
89
|
+
.map(([tagKey, elements]) => {
|
|
90
|
+
const formattedElements = elements.map(formatElement(tagKey)).join('\n');
|
|
91
|
+
return `${tagKey}:\n${formattedElements}`;
|
|
92
|
+
})
|
|
93
|
+
.join('\n\n');
|
|
94
|
+
const prompt = `You are an expert Playwright test engineer specializing in mapping Gherkin steps to concrete DOM interactions.
|
|
95
|
+
|
|
96
|
+
Your task is to analyze:
|
|
97
|
+
1. A single Gherkin step that implies a click action.
|
|
98
|
+
2. A list of candidate DOM elements extracted from the page.
|
|
99
|
+
|
|
100
|
+
You must return the **top 5 most likely elements** that the Gherkin step is referring to.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### IMPORTANT RULES
|
|
105
|
+
|
|
106
|
+
- Rank elements from **most likely (rank 1)** to **least likely (rank 5)**.
|
|
107
|
+
- Prefer **semantic matches** first:
|
|
108
|
+
- Visible text
|
|
109
|
+
- Accessible name (label, aria-label, role)
|
|
110
|
+
- Button / link intent
|
|
111
|
+
- Use "index" **only as a secondary disambiguation signal**, never as the primary reason.
|
|
112
|
+
- Do NOT invent elements or field values.
|
|
113
|
+
- Do NOT include more than 5 results.
|
|
114
|
+
- If fewer than 5 reasonable matches exist, return fewer.
|
|
115
|
+
- Do NOT assume navigation or side effects — this task is only about **what element is clicked**.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
**Gherkin Step:**
|
|
119
|
+
${gherkinStep}
|
|
120
|
+
|
|
121
|
+
**Available Target Elements (${targetElements.length} total):**
|
|
122
|
+
${elementsDescription}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
## Reason and return up to the top 5 most likely elements that the Gherkin step is referring to.
|
|
126
|
+
`;
|
|
127
|
+
const res = await generateText({
|
|
128
|
+
model: brain,
|
|
129
|
+
prompt,
|
|
130
|
+
maxRetries: 3,
|
|
131
|
+
output: Output.object({ schema: zClickActionResult, name: 'clickActionResult' }),
|
|
132
|
+
});
|
|
133
|
+
await countTokens(res);
|
|
134
|
+
return res.output;
|
|
135
|
+
};
|
|
136
|
+
export const executeClickAction = async (element, clickActionResult) => {
|
|
137
|
+
switch (clickActionResult.clickType) {
|
|
138
|
+
case 'left':
|
|
139
|
+
return await element?.click();
|
|
140
|
+
case 'right':
|
|
141
|
+
return await element?.click({ button: 'right' });
|
|
142
|
+
case 'double':
|
|
143
|
+
return await element?.dblclick();
|
|
144
|
+
case 'middle':
|
|
145
|
+
return await element?.click({ button: 'middle' });
|
|
146
|
+
case 'hover':
|
|
147
|
+
return await element?.hover();
|
|
148
|
+
default:
|
|
149
|
+
throw new Error(`Unknown click type: ${clickActionResult.clickType}`);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=click.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"click.js","sourceRoot":"","sources":["../../src/mimicry/click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAG7D,OAAO,EACL,kBAAkB,EAEnB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,KAAW,EACX,KAAoB,EACpB,WAAmB,EACnB,cAA4B,EACA,EAAE;IAC9B,2DAA2D;IAC3D,+CAA+C;IAC/C,MAAM,mBAAmB,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAClE,KAAK;QACL,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,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EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;KACjF,CAAC,CAAC;IAEH,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,OAAuB,EACvB,iBAAoC,EACrB,EAAE;IACjB,QAAQ,iBAAiB,CAAC,SAAS,EAAE,CAAC;QACpC,KAAK,MAAM;YACT,OAAO,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC;QAChC,KAAK,OAAO;YACV,OAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QACnD,KAAK,QAAQ;YACX,OAAO,MAAM,OAAO,EAAE,QAAQ,EAAE,CAAC;QACnC,KAAK,QAAQ;YACX,OAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QACpD,KAAK,OAAO;YACV,OAAO,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC;QAChC;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,iBAAiB,CAAC,SAAS,EAAE,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Locator, Page } from '@playwright/test';
|
|
2
|
+
import { type LanguageModel } from 'ai';
|
|
3
|
+
import z from 'zod';
|
|
4
|
+
import { TargetInfo } from './selector';
|
|
5
|
+
declare const zFormActionResult: z.ZodObject<{
|
|
6
|
+
type: z.ZodEnum<{
|
|
7
|
+
type: "type";
|
|
8
|
+
fill: "fill";
|
|
9
|
+
select: "select";
|
|
10
|
+
uncheck: "uncheck";
|
|
11
|
+
check: "check";
|
|
12
|
+
setInputFiles: "setInputFiles";
|
|
13
|
+
clear: "clear";
|
|
14
|
+
keypress: "keypress";
|
|
15
|
+
}>;
|
|
16
|
+
params: z.ZodObject<{
|
|
17
|
+
value: z.ZodString;
|
|
18
|
+
modifiers: z.ZodArray<z.ZodEnum<{
|
|
19
|
+
Alt: "Alt";
|
|
20
|
+
Control: "Control";
|
|
21
|
+
Meta: "Meta";
|
|
22
|
+
Shift: "Shift";
|
|
23
|
+
none: "none";
|
|
24
|
+
}>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export type FormActionResult = z.infer<typeof zFormActionResult>;
|
|
28
|
+
export declare const getFormAction: (_page: Page, brain: LanguageModel, gherkinStep: string, targetElements: TargetInfo[]) => Promise<FormActionResult>;
|
|
29
|
+
export declare const executeFormAction: (page: Page, formActionResult: FormActionResult, targetElement: Locator | null) => Promise<void | string[]>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=forms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forms.d.ts","sourceRoot":"","sources":["../../src/mimicry/forms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,IAAI,CAAA;AAC7D,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;iBAMrB,CAAA;AAGF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEjE,eAAO,MAAM,aAAa,GACxB,OAAO,IAAI,EACX,OAAO,aAAa,EACpB,aAAa,MAAM,EACnB,gBAAgB,UAAU,EAAE,KAC3B,OAAO,CAAC,gBAAgB,CA4H1B,CAAA;AAGD,eAAO,MAAM,iBAAiB,GAC5B,MAAM,IAAI,EACV,kBAAkB,gBAAgB,EAClC,eAAe,OAAO,GAAG,IAAI,KAC5B,OAAO,CAAC,IAAI,GAAG,MAAM,EAAE,CAwBzB,CAAA"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { generateText, Output } from 'ai';
|
|
2
|
+
import z from 'zod';
|
|
3
|
+
import { countTokens } from '../utils/token-counter';
|
|
4
|
+
const zFormActionResult = z.object({
|
|
5
|
+
type: z.enum(['keypress', 'type', 'fill', 'select', 'uncheck', 'check', 'setInputFiles', 'clear']),
|
|
6
|
+
params: z.object({
|
|
7
|
+
value: z.string().describe("Value to set for the form update."),
|
|
8
|
+
modifiers: z.array(z.enum(['Alt', 'Control', 'Meta', 'Shift', 'none'])).describe("Optional modifier keys to use for the form update."),
|
|
9
|
+
}),
|
|
10
|
+
});
|
|
11
|
+
export const getFormAction = async (_page, brain, gherkinStep, targetElements) => {
|
|
12
|
+
// Format target elements with their indices for the prompt
|
|
13
|
+
// Include all relevant identifying information
|
|
14
|
+
const elementsWithIndices = targetElements.map((element, index) => ({
|
|
15
|
+
index,
|
|
16
|
+
tag: element.tag,
|
|
17
|
+
text: element.text,
|
|
18
|
+
id: element.id,
|
|
19
|
+
role: element.role,
|
|
20
|
+
label: element.label,
|
|
21
|
+
ariaLabel: element.ariaLabel,
|
|
22
|
+
typeAttr: element.typeAttr,
|
|
23
|
+
nameAttr: element.nameAttr,
|
|
24
|
+
href: element.href,
|
|
25
|
+
dataset: element.dataset,
|
|
26
|
+
nthOfType: element.nthOfType,
|
|
27
|
+
}));
|
|
28
|
+
// Group elements by tag type
|
|
29
|
+
const elementsByTag = new Map();
|
|
30
|
+
for (const el of elementsWithIndices) {
|
|
31
|
+
const tagKey = el.tag === 'a' ? 'links' : el.tag === 'button' ? 'buttons' : el.tag === 'input' ? 'inputs' : el.tag;
|
|
32
|
+
if (!elementsByTag.has(tagKey)) {
|
|
33
|
+
elementsByTag.set(tagKey, []);
|
|
34
|
+
}
|
|
35
|
+
elementsByTag.get(tagKey).push(el);
|
|
36
|
+
}
|
|
37
|
+
// Format element fields in selector priority order, skipping null/empty values
|
|
38
|
+
const formatElement = (roleSection) => (el) => {
|
|
39
|
+
const parts = [];
|
|
40
|
+
// Priority order: testId → text → role → ariaLabel → label → name → type → href → dataAttributes → tag → id → nthOfType
|
|
41
|
+
if (el.dataset.testid) {
|
|
42
|
+
parts.push(` testId: "${el.dataset.testid}"`);
|
|
43
|
+
}
|
|
44
|
+
if (el.text && el.text.trim()) {
|
|
45
|
+
parts.push(` text: "${el.text.trim()}"`);
|
|
46
|
+
}
|
|
47
|
+
if (el.role && roleSection !== el.role) {
|
|
48
|
+
parts.push(` role: ${el.role}`);
|
|
49
|
+
}
|
|
50
|
+
if (el.ariaLabel) {
|
|
51
|
+
parts.push(` ariaLabel: "${el.ariaLabel}"`);
|
|
52
|
+
}
|
|
53
|
+
if (el.label) {
|
|
54
|
+
parts.push(` label: "${el.label}"`);
|
|
55
|
+
}
|
|
56
|
+
if (el.nameAttr) {
|
|
57
|
+
parts.push(` name: "${el.nameAttr}"`);
|
|
58
|
+
}
|
|
59
|
+
if (el.typeAttr) {
|
|
60
|
+
parts.push(` type: ${el.typeAttr}`);
|
|
61
|
+
}
|
|
62
|
+
if (el.href) {
|
|
63
|
+
parts.push(` href: "${el.href}"`);
|
|
64
|
+
}
|
|
65
|
+
if (Object.keys(el.dataset).length > 0) {
|
|
66
|
+
const dataKeys = Object.keys(el.dataset).filter(k => k !== 'testid');
|
|
67
|
+
if (dataKeys.length > 0) {
|
|
68
|
+
parts.push(` dataAttributes: ${JSON.stringify(dataKeys)}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
parts.push(` tag: ${el.tag}`);
|
|
72
|
+
// if (el.id) {
|
|
73
|
+
// parts.push(` id: "${el.id}"`);
|
|
74
|
+
// }
|
|
75
|
+
parts.push(` index: ${el.index}`);
|
|
76
|
+
if (el.nthOfType > 1) {
|
|
77
|
+
parts.push(` nthOfType: ${el.nthOfType}`);
|
|
78
|
+
}
|
|
79
|
+
return ` - ${parts.join('\n ')}`;
|
|
80
|
+
};
|
|
81
|
+
// Create formatted description grouped by tag
|
|
82
|
+
const elementsDescription = Array.from(elementsByTag.entries())
|
|
83
|
+
.map(([tagKey, elements]) => {
|
|
84
|
+
const formattedElements = elements.map(formatElement(tagKey)).join('\n');
|
|
85
|
+
return `${tagKey}:\n${formattedElements}`;
|
|
86
|
+
})
|
|
87
|
+
.join('\n\n');
|
|
88
|
+
const res = await generateText({
|
|
89
|
+
model: brain,
|
|
90
|
+
prompt: `You are an expert Playwright test engineer specializing in mapping Gherkin steps to concrete DOM interactions.
|
|
91
|
+
|
|
92
|
+
Your task is to analyze:
|
|
93
|
+
1. A single Gherkin step that implies a click action.
|
|
94
|
+
2. A list of candidate DOM elements extracted from the page.
|
|
95
|
+
|
|
96
|
+
You must return the **top 5 most likely elements** that the Gherkin step is referring to.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### IMPORTANT RULES
|
|
101
|
+
|
|
102
|
+
- Rank elements from **most likely (rank 1)** to **least likely (rank 5)**.
|
|
103
|
+
- Prefer **semantic matches** first:
|
|
104
|
+
- Visible text
|
|
105
|
+
- Accessible name (label, aria-label, role)
|
|
106
|
+
- Button / link intent
|
|
107
|
+
- Use "index" **only as a secondary disambiguation signal**, never as the primary reason.
|
|
108
|
+
- Do NOT invent elements or field values.
|
|
109
|
+
- Do NOT include more than 5 results.
|
|
110
|
+
- If fewer than 5 reasonable matches exist, return fewer.
|
|
111
|
+
- Do NOT assume navigation or side effects — this task is only about **what element is clicked**.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
**Gherkin Step:**
|
|
115
|
+
${gherkinStep}
|
|
116
|
+
|
|
117
|
+
**Available Target Elements (${targetElements.length} total):**
|
|
118
|
+
${elementsDescription}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Reason and return up to the top 5 most likely elements that the Gherkin step is referring to.
|
|
122
|
+
`,
|
|
123
|
+
output: Output.object({ schema: zFormActionResult, name: 'formActionResult' }),
|
|
124
|
+
maxRetries: 3,
|
|
125
|
+
});
|
|
126
|
+
await countTokens(res);
|
|
127
|
+
return res.output;
|
|
128
|
+
};
|
|
129
|
+
export const executeFormAction = async (page, formActionResult, targetElement) => {
|
|
130
|
+
if (targetElement === null) {
|
|
131
|
+
throw new Error('No target element found');
|
|
132
|
+
}
|
|
133
|
+
switch (formActionResult.type) {
|
|
134
|
+
case 'keypress':
|
|
135
|
+
return await page.keyboard.press(formActionResult.params.value);
|
|
136
|
+
case 'type':
|
|
137
|
+
return await page.keyboard.type(formActionResult.params.value);
|
|
138
|
+
case 'fill':
|
|
139
|
+
return await targetElement.fill(formActionResult.params.value);
|
|
140
|
+
case 'select':
|
|
141
|
+
return await targetElement.selectOption(formActionResult.params.value);
|
|
142
|
+
case 'uncheck':
|
|
143
|
+
return await targetElement.uncheck();
|
|
144
|
+
case 'check':
|
|
145
|
+
return await targetElement.check();
|
|
146
|
+
case 'setInputFiles':
|
|
147
|
+
return await targetElement.setInputFiles(formActionResult.params.value);
|
|
148
|
+
case 'clear':
|
|
149
|
+
return await targetElement.clear();
|
|
150
|
+
default:
|
|
151
|
+
throw new Error(`Unknown form action type: ${formActionResult.type}`);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=forms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forms.js","sourceRoot":"","sources":["../../src/mimicry/forms.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAC7D,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAA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MAAM,CAAC,KAAK,CAAC,CAAC;QAClE,KAAK,MAAM;YACT,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACjE,KAAK,MAAM;YACT,OAAO,MAAM,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACjE,KAAK,QAAQ;YACX,OAAO,MAAM,aAAa,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzE,KAAK,SAAS;YACZ,OAAO,MAAM,aAAa,CAAC,OAAO,EAAE,CAAC;QACvC,KAAK,OAAO;YACV,OAAO,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC;QACrC,KAAK,eAAe;YAClB,OAAO,MAAM,aAAa,CAAC,aAAa,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1E,KAAK,OAAO;YACV,OAAO,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC;QACrC;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type LanguageModel } from 'ai';
|
|
2
|
+
import { Page } from '@playwright/test';
|
|
3
|
+
import { type NavigationAction } from './schema/action.js';
|
|
4
|
+
export declare const getNavigationAction: (_page: Page, brain: LanguageModel, action: string) => Promise<NavigationAction>;
|
|
5
|
+
export declare const executeNavigationAction: (page: Page, navigationAction: NavigationAction) => Promise<void>;
|
|
6
|
+
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/mimicry/navigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,IAAI,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEvC,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,oBAAoB,CAAA;AAG3B,eAAO,MAAM,mBAAmB,GAC9B,OAAO,IAAI,EACX,OAAO,aAAa,EACpB,QAAQ,MAAM,KACb,OAAO,CAAC,gBAAgB,CAqB1B,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,MAAM,IAAI,EACV,kBAAkB,gBAAgB,KACjC,OAAO,CAAC,IAAI,CA0Bd,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { generateText, Output } from 'ai';
|
|
2
|
+
import { zNavigationAction, } from './schema/action.js';
|
|
3
|
+
import { countTokens } from '../utils/token-counter.js';
|
|
4
|
+
export const getNavigationAction = async (_page, brain, action) => {
|
|
5
|
+
const res = await generateText({
|
|
6
|
+
model: brain,
|
|
7
|
+
maxRetries: 3,
|
|
8
|
+
prompt: `You are an expert in converting Gherkin test steps into structured browser automation action objects using Playwright.
|
|
9
|
+
|
|
10
|
+
Your task is to process a single Gherkin step and determine whether it represents a **navigation** action. this can be any of the following:
|
|
11
|
+
- navigate to a page (this requires a url, if no url is provided, go for an option below)
|
|
12
|
+
- closePage: close the current page
|
|
13
|
+
- goBack: go back to the previous page, or navigate back in the browser history
|
|
14
|
+
- goForward: go forward to the next page, or navigate forward in the browser history
|
|
15
|
+
- refresh: refresh the current page, or reload the page
|
|
16
|
+
|
|
17
|
+
Input Gherkin step: ${action}
|
|
18
|
+
|
|
19
|
+
`,
|
|
20
|
+
output: Output.object({ schema: zNavigationAction, name: 'navigation' }),
|
|
21
|
+
});
|
|
22
|
+
await countTokens(res);
|
|
23
|
+
return res.output;
|
|
24
|
+
};
|
|
25
|
+
export const executeNavigationAction = async (page, navigationAction) => {
|
|
26
|
+
switch (navigationAction.type) {
|
|
27
|
+
case 'openPage':
|
|
28
|
+
case 'navigate':
|
|
29
|
+
// console.log('Navigating to', navigationAction.params.url);
|
|
30
|
+
await page.goto(navigationAction.params.url, { waitUntil: 'networkidle' });
|
|
31
|
+
break;
|
|
32
|
+
case 'closePage':
|
|
33
|
+
// console.log('Closing page');
|
|
34
|
+
await page.close();
|
|
35
|
+
break;
|
|
36
|
+
case 'goBack':
|
|
37
|
+
// console.log('Going back');
|
|
38
|
+
await page.goBack();
|
|
39
|
+
break;
|
|
40
|
+
case 'goForward':
|
|
41
|
+
// console.log('Going forward');
|
|
42
|
+
await page.goForward();
|
|
43
|
+
break;
|
|
44
|
+
case 'refresh':
|
|
45
|
+
// console.log('Refreshing page');
|
|
46
|
+
await page.reload();
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Unknown navigation action type: ${navigationAction.type}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../src/mimicry/navigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAG7D,OAAO,EACL,iBAAiB,GAElB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,KAAW,EACX,KAAoB,EACpB,MAAc,EACa,EAAE;IAC7B,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC;QAC7B,KAAK,EAAE,KAAK;QACZ,UAAU,EAAE,CAAC;QACb,MAAM,EAAE;;;;;;;;;sBASU,MAAM;;KAEvB;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;KACzE,CAAC,CAAC;IACH,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB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