@monkeytestai/monkeytester 0.6.0 → 0.6.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/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/dist/cli.js +1 -1
- package/dist/explorer/index.d.ts.map +1 -1
- package/dist/explorer/index.js +102 -17
- package/dist/explorer/index.js.map +1 -1
- package/dist/planner/index.d.ts.map +1 -1
- package/dist/planner/index.js +30 -1
- package/dist/planner/index.js.map +1 -1
- package/dist/planner/inventory.d.ts +23 -0
- package/dist/planner/inventory.d.ts.map +1 -0
- package/dist/planner/inventory.js +203 -0
- package/dist/planner/inventory.js.map +1 -0
- package/dist/runner/actions.d.ts +8 -0
- package/dist/runner/actions.d.ts.map +1 -1
- package/dist/runner/actions.js +211 -31
- package/dist/runner/actions.js.map +1 -1
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +13 -0
- package/dist/runner/index.js.map +1 -1
- package/dist/runner/locate.d.ts +41 -0
- package/dist/runner/locate.d.ts.map +1 -0
- package/dist/runner/locate.js +507 -0
- package/dist/runner/locate.js.map +1 -0
- package/dist/runner/replay.d.ts.map +1 -1
- package/dist/runner/replay.js +4 -1
- package/dist/runner/replay.js.map +1 -1
- package/dist/triager/index.d.ts +10 -1
- package/dist/triager/index.d.ts.map +1 -1
- package/dist/triager/index.js +65 -2
- package/dist/triager/index.js.map +1 -1
- package/dist/types.d.ts +65 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drop or repair planner flows that name a control the crawl did not see.
|
|
3
|
+
*
|
|
4
|
+
* A model will invent a checkbox flow and a text-input flow for a page whose
|
|
5
|
+
* only control is an unlabeled number input. Those flows used to run, time
|
|
6
|
+
* out in `locator.fill`, and come back inconclusive. They are not tests.
|
|
7
|
+
* Flows the engine built from scraped forms and controls are left alone;
|
|
8
|
+
* callers pass only the model list.
|
|
9
|
+
*/
|
|
10
|
+
import { sameCrawlPage } from '../explorer/queue.js';
|
|
11
|
+
const GENERIC = new Set(['input', 'inputs', 'field', 'fields', 'box', 'the', 'a', 'an', 'control', 'element', 'form']);
|
|
12
|
+
export function reconcileModelFlows(flows, siteMap) {
|
|
13
|
+
const kept = [];
|
|
14
|
+
const dropped = [];
|
|
15
|
+
const repairs = [];
|
|
16
|
+
for (const flow of flows) {
|
|
17
|
+
const page = siteMap.pages.find(item => sameCrawlPage(item.url, flow.startUrl));
|
|
18
|
+
const fields = page ? fieldsOf(page) : [];
|
|
19
|
+
if (!page || fields.length === 0) {
|
|
20
|
+
kept.push(flow);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const purpose = requestedKind(`${flow.name}\n${flow.description}`);
|
|
24
|
+
if (purpose && !kindExists(fields, purpose)) {
|
|
25
|
+
dropped.push({
|
|
26
|
+
id: flow.id,
|
|
27
|
+
name: flow.name,
|
|
28
|
+
reason: missingReason(purpose),
|
|
29
|
+
});
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const steps = [];
|
|
33
|
+
let repaired = false;
|
|
34
|
+
let stepDrop = '';
|
|
35
|
+
for (const step of flow.steps) {
|
|
36
|
+
const judged = judgeStep(step, fields, page);
|
|
37
|
+
if (judged.drop) {
|
|
38
|
+
stepDrop = judged.drop;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (judged.step.action !== step.action)
|
|
42
|
+
repaired = true;
|
|
43
|
+
steps.push(judged.step);
|
|
44
|
+
}
|
|
45
|
+
if (steps.length === 0) {
|
|
46
|
+
dropped.push({
|
|
47
|
+
id: flow.id,
|
|
48
|
+
name: flow.name,
|
|
49
|
+
reason: stepDrop || 'no matching control',
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const next = repaired ? { ...flow, steps } : flow;
|
|
54
|
+
if (repaired)
|
|
55
|
+
repairs.push(flow.name);
|
|
56
|
+
kept.push(next);
|
|
57
|
+
}
|
|
58
|
+
const sentences = [
|
|
59
|
+
dropped.length
|
|
60
|
+
? `Dropped ${dropped.length} flow${dropped.length === 1 ? '' : 's'} that named controls the page does not have: ${dropped.map(item => `"${item.name}" (${item.reason})`).join(', ')}.`
|
|
61
|
+
: '',
|
|
62
|
+
repairs.length
|
|
63
|
+
? `Repaired ${repairs.map(name => `"${name}"`).join(', ')} to target a control the crawl actually saw.`
|
|
64
|
+
: '',
|
|
65
|
+
].filter(Boolean);
|
|
66
|
+
return {
|
|
67
|
+
flows: kept,
|
|
68
|
+
dropped,
|
|
69
|
+
...(sentences.length ? { note: sentences.join(' ') } : {}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function fieldsOf(page) {
|
|
73
|
+
if (page.inputs && page.inputs.length > 0)
|
|
74
|
+
return page.inputs;
|
|
75
|
+
const fromForms = [];
|
|
76
|
+
for (const form of page.forms ?? []) {
|
|
77
|
+
if (form.inputs && form.inputs.length > 0)
|
|
78
|
+
fromForms.push(...form.inputs);
|
|
79
|
+
else
|
|
80
|
+
fromForms.push(...form.fields.filter(Boolean).map(token => ({ name: token })));
|
|
81
|
+
}
|
|
82
|
+
return fromForms;
|
|
83
|
+
}
|
|
84
|
+
function judgeStep(step, fields, page) {
|
|
85
|
+
const action = step.action;
|
|
86
|
+
const kind = requestedKind(action);
|
|
87
|
+
if (kind && !kindExists(fields, kind)) {
|
|
88
|
+
return { step, drop: missingReason(kind) };
|
|
89
|
+
}
|
|
90
|
+
const quoted = action.match(/\bfill(?:\s+in)?\s+the\s+["“]([^"”]+)["”]/i)?.[1]?.trim();
|
|
91
|
+
if (quoted && !matchesAny(fields, quoted) && !(kind && kindExists(fields, kind) && fields.filter(field => fieldMatchesKind(field, kind)).length === 1)) {
|
|
92
|
+
const fuzzy = uniqueFuzzy(fields, quoted);
|
|
93
|
+
if (!fuzzy)
|
|
94
|
+
return { step, drop: `no control matching "${quoted}"` };
|
|
95
|
+
}
|
|
96
|
+
const click = action.match(/\bclick(?:ing)?\s+(?:the\s+)?["“]([^"”]+)["”]/i)?.[1]?.trim();
|
|
97
|
+
if (click && page.controls && page.controls.length > 0) {
|
|
98
|
+
const known = page.controls.some(control => control.label.trim().toLowerCase() === click.toLowerCase());
|
|
99
|
+
if (!known && !matchesAny(fields, click)) {
|
|
100
|
+
return { step, drop: `no control matching "${click}"` };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const repaired = repairFill(step, fields);
|
|
104
|
+
return { step: repaired ?? step };
|
|
105
|
+
}
|
|
106
|
+
function repairFill(step, fields) {
|
|
107
|
+
const kind = requestedKind(`${step.action}`);
|
|
108
|
+
const quoted = step.action.match(/\bfill(?:\s+in)?\s+the\s+["“]([^"”]+)["”]/i)?.[1]?.trim();
|
|
109
|
+
const quotedKind = quoted ? requestedKind(quoted) : undefined;
|
|
110
|
+
const wantsNumber = kind === 'number' || quotedKind === 'number';
|
|
111
|
+
if (!wantsNumber && !/\bfill\b|\btype\b|\benter\b/i.test(step.action))
|
|
112
|
+
return undefined;
|
|
113
|
+
const numbers = fields.filter(field => fieldMatchesKind(field, 'number'));
|
|
114
|
+
if (numbers.length !== 1)
|
|
115
|
+
return undefined;
|
|
116
|
+
if (!wantsNumber && quoted && matchesAny(fields, quoted))
|
|
117
|
+
return undefined;
|
|
118
|
+
if (!wantsNumber)
|
|
119
|
+
return undefined;
|
|
120
|
+
const action = fillAction(numbers[0]);
|
|
121
|
+
if (action === step.action)
|
|
122
|
+
return undefined;
|
|
123
|
+
return { ...step, action };
|
|
124
|
+
}
|
|
125
|
+
function fillAction(field) {
|
|
126
|
+
const type = (field.type || '').toLowerCase();
|
|
127
|
+
const hint = type === 'number' ? ' (input[type=number])' : '';
|
|
128
|
+
const label = clean(field.preceding || field.label || field.name || '');
|
|
129
|
+
if (label)
|
|
130
|
+
return `Fill the "${label}" field${hint}`;
|
|
131
|
+
if (type)
|
|
132
|
+
return `Fill the ${type} input${hint}`;
|
|
133
|
+
return 'Fill the input';
|
|
134
|
+
}
|
|
135
|
+
function matchesAny(fields, wanted) {
|
|
136
|
+
return fields.some(field => exactField(field, wanted));
|
|
137
|
+
}
|
|
138
|
+
function uniqueFuzzy(fields, wanted) {
|
|
139
|
+
const hits = fields.filter(field => fuzzyField(field, wanted));
|
|
140
|
+
return hits.length === 1 ? hits[0] : undefined;
|
|
141
|
+
}
|
|
142
|
+
function exactField(field, wanted) {
|
|
143
|
+
const needle = wanted.trim().toLowerCase();
|
|
144
|
+
return [field.label, field.name, field.placeholder, field.id, field.preceding]
|
|
145
|
+
.some(value => Boolean(value && value.trim().toLowerCase() === needle));
|
|
146
|
+
}
|
|
147
|
+
function fuzzyField(field, wanted) {
|
|
148
|
+
if (exactField(field, wanted))
|
|
149
|
+
return true;
|
|
150
|
+
const kind = requestedKind(wanted);
|
|
151
|
+
if (kind && fieldMatchesKind(field, kind))
|
|
152
|
+
return true;
|
|
153
|
+
const wantedTokens = tokens(wanted);
|
|
154
|
+
if (wantedTokens.length === 0)
|
|
155
|
+
return false;
|
|
156
|
+
const hay = `${field.label || ''} ${field.name || ''} ${field.placeholder || ''} ${field.preceding || ''} ${field.heading || ''} ${field.type || ''}`.toLowerCase();
|
|
157
|
+
return wantedTokens.every(token => hay.includes(token));
|
|
158
|
+
}
|
|
159
|
+
function kindExists(fields, kind) {
|
|
160
|
+
return fields.some(field => fieldMatchesKind(field, kind));
|
|
161
|
+
}
|
|
162
|
+
function fieldMatchesKind(field, kind) {
|
|
163
|
+
const type = (field.type || '').toLowerCase();
|
|
164
|
+
const name = (field.name || '').toLowerCase();
|
|
165
|
+
if (kind === 'text') {
|
|
166
|
+
if (type === 'number' || type === 'checkbox' || type === 'radio' || type === 'range' || type === 'hidden')
|
|
167
|
+
return false;
|
|
168
|
+
if (!type)
|
|
169
|
+
return true;
|
|
170
|
+
return ['text', 'email', 'password', 'search', 'tel', 'url', 'textarea'].includes(type);
|
|
171
|
+
}
|
|
172
|
+
if (kind === 'number')
|
|
173
|
+
return type === 'number' || type === 'range' || name === 'number';
|
|
174
|
+
if (kind === 'checkbox')
|
|
175
|
+
return type === 'checkbox' || name === 'checkbox';
|
|
176
|
+
if (kind === 'radio')
|
|
177
|
+
return type === 'radio' || name === 'radio';
|
|
178
|
+
return type === kind || name === kind;
|
|
179
|
+
}
|
|
180
|
+
function requestedKind(text) {
|
|
181
|
+
const value = text.toLowerCase();
|
|
182
|
+
if (/\bcheck\s*boxes?\b|\bcheckbox\b/.test(value))
|
|
183
|
+
return 'checkbox';
|
|
184
|
+
if (/\bradio(?:\s+button)?s?\b/.test(value))
|
|
185
|
+
return 'radio';
|
|
186
|
+
if (/\btext\s*(input|field|box)\b|\btextbox\b/.test(value))
|
|
187
|
+
return 'text';
|
|
188
|
+
if (/\bnumber\s*input\b|\bnumeric\s*input\b|\bspinbutton\b/.test(value))
|
|
189
|
+
return 'number';
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
function missingReason(kind) {
|
|
193
|
+
if (kind === 'text')
|
|
194
|
+
return 'no text input';
|
|
195
|
+
return `no ${kind}`;
|
|
196
|
+
}
|
|
197
|
+
function tokens(value) {
|
|
198
|
+
return value.toLowerCase().split(/[^a-z0-9]+/).filter(token => token.length > 1 && !GENERIC.has(token));
|
|
199
|
+
}
|
|
200
|
+
function clean(value) {
|
|
201
|
+
return value.replace(/\s+/g, ' ').trim().replace(/["“”]/g, "'").slice(0, 80);
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=inventory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.js","sourceRoot":"","sources":["../../src/planner/inventory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAerD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE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IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IACzF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,eAAe,CAAC;IAC5C,OAAO,MAAM,IAAI,EAAE,CAAC;AACtB,CAAC;AAED,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1G,CAAC;AAED,SAAS,KAAK,CAAC,KAAa;IAC1B,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/E,CAAC"}
|
package/dist/runner/actions.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { Locator, Page } from 'playwright';
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import type { LLM } from '../llm/index.js';
|
|
8
8
|
import type { TestFlow, TestStep, StepStatus, TraceLocator } from '../types.js';
|
|
9
|
+
import { type LocateHit } from './locate.js';
|
|
9
10
|
export declare const ActionSchema: z.ZodEffects<z.ZodObject<{
|
|
10
11
|
tool: z.ZodEnum<["click", "fill", "goto", "wait", "assert_text", "press", "noop"]>;
|
|
11
12
|
/** CSS selector, URL (for goto), test id, or text snippet (for assert_text). */
|
|
@@ -52,7 +53,10 @@ export interface PageSkeletonForLLM {
|
|
|
52
53
|
label?: string;
|
|
53
54
|
placeholder?: string;
|
|
54
55
|
name?: string;
|
|
56
|
+
id?: string;
|
|
55
57
|
type?: string;
|
|
58
|
+
preceding?: string;
|
|
59
|
+
heading?: string;
|
|
56
60
|
}[];
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
@@ -90,9 +94,13 @@ export interface ActionOutcome {
|
|
|
90
94
|
status: StepStatus;
|
|
91
95
|
observation: string;
|
|
92
96
|
error?: string;
|
|
97
|
+
/** Set when a fallback locator replaced the model's target. */
|
|
98
|
+
resolved?: ResolvedAction;
|
|
99
|
+
element?: import('../types.js').BugElement;
|
|
93
100
|
}
|
|
94
101
|
export declare function executeAction(page: Page, action: ResolvedAction, timeoutMs: number, options?: {
|
|
95
102
|
strictOracles?: boolean;
|
|
103
|
+
located?: LocateHit;
|
|
96
104
|
}): Promise<ActionOutcome>;
|
|
97
105
|
export declare function buildLocator(page: Page, action: ResolvedAction): Locator;
|
|
98
106
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/runner/actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EAEb,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/runner/actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EAEb,MAAM,aAAa,CAAC;AAErB,OAAO,EAA2C,KAA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ist/runner/actions.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { clipText, coerceEnum, coerceToString, unwrapModelObject } from '../llm/coerce.js';
|
|
7
7
|
import { isAutomationFault } from '../automation/signatures.js';
|
|
8
|
+
import { impliedType, locateActionTarget, pageFn } from './locate.js';
|
|
8
9
|
const ACTION_TOOLS = ['click', 'fill', 'goto', 'wait', 'assert_text', 'press', 'noop'];
|
|
9
10
|
const ACTION_LOCATORS = ['css', 'role', 'text', 'placeholder', 'label', 'testid'];
|
|
10
11
|
const TOOL_ALIASES = {
|
|
@@ -76,7 +77,13 @@ export function directActionFromStep(action, skeleton) {
|
|
|
76
77
|
if (fill) {
|
|
77
78
|
const field = fill[1].trim();
|
|
78
79
|
const nameHint = action.match(/\bname\s*=\s*["“']([^"”']+)["”']/i)?.[1]?.trim();
|
|
79
|
-
const
|
|
80
|
+
const typeHint = action.match(/input\[type=(?:"|')?([a-z0-9-]+)/i)?.[1]?.toLowerCase();
|
|
81
|
+
const typed = typeHint
|
|
82
|
+
? skeleton.inputs.filter(item => (item.type || '').toLowerCase() === typeHint)
|
|
83
|
+
: [];
|
|
84
|
+
const input = (nameHint && findInput(skeleton.inputs, nameHint))
|
|
85
|
+
|| findInput(skeleton.inputs, field)
|
|
86
|
+
|| (typed.length === 1 ? typed[0] : undefined);
|
|
80
87
|
if (!input)
|
|
81
88
|
return null;
|
|
82
89
|
return fillActionForInput(input, undefined, `Field "${field}" is on the page.`);
|
|
@@ -143,7 +150,9 @@ export function groundFillAction(action, skeleton) {
|
|
|
143
150
|
return value === action.value ? action : { ...action, value };
|
|
144
151
|
}
|
|
145
152
|
const input = placeholderOnly || findInput(skeleton.inputs, wanted);
|
|
146
|
-
if (!input
|
|
153
|
+
if (!input)
|
|
154
|
+
return action;
|
|
155
|
+
if (!input.label && !input.name && !input.id && !input.placeholder && !input.type && !input.preceding)
|
|
147
156
|
return action;
|
|
148
157
|
const grounded = fillActionForInput(input, action.value, action.rationale);
|
|
149
158
|
const withValue = action.value === grounded.value ? action : { ...action, value: grounded.value };
|
|
@@ -181,6 +190,36 @@ function fillActionForInput(input, value, rationale) {
|
|
|
181
190
|
rationale: rationale || `Input name "${input.name}" is on the page.`,
|
|
182
191
|
};
|
|
183
192
|
}
|
|
193
|
+
if (input.id) {
|
|
194
|
+
return {
|
|
195
|
+
tool: 'fill',
|
|
196
|
+
locator: 'css',
|
|
197
|
+
target: `#${input.id.replace(/\\/g, '\\\\')}`,
|
|
198
|
+
value: sample,
|
|
199
|
+
rationale: rationale || `Input id "${input.id}" is on the page.`,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
if (input.placeholder) {
|
|
203
|
+
return {
|
|
204
|
+
tool: 'fill',
|
|
205
|
+
locator: 'placeholder',
|
|
206
|
+
target: input.placeholder,
|
|
207
|
+
value: sample,
|
|
208
|
+
rationale: rationale || `Placeholder "${input.placeholder}" is on the page.`,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (input.type && input.type !== 'text') {
|
|
212
|
+
const target = input.type === 'textarea' || input.type === 'select'
|
|
213
|
+
? input.type
|
|
214
|
+
: `input[type="${input.type}"]`;
|
|
215
|
+
return {
|
|
216
|
+
tool: 'fill',
|
|
217
|
+
locator: 'css',
|
|
218
|
+
target,
|
|
219
|
+
value: sample,
|
|
220
|
+
rationale: rationale || `Input type "${input.type}" is on the page.`,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
184
223
|
return {
|
|
185
224
|
tool: 'fill',
|
|
186
225
|
locator: 'placeholder',
|
|
@@ -190,8 +229,27 @@ function fillActionForInput(input, value, rationale) {
|
|
|
190
229
|
};
|
|
191
230
|
}
|
|
192
231
|
function findInput(inputs, wanted, only) {
|
|
193
|
-
const keys = only ? [only] : ['name', 'label', 'placeholder'];
|
|
194
|
-
|
|
232
|
+
const keys = only ? [only] : ['name', 'label', 'placeholder', 'id', 'preceding'];
|
|
233
|
+
const exact = inputs.find(input => keys.some(key => sameField(input[key], wanted)));
|
|
234
|
+
if (exact || only)
|
|
235
|
+
return exact;
|
|
236
|
+
const loose = inputs.filter(input => looseField(input, wanted));
|
|
237
|
+
return loose.length === 1 ? loose[0] : undefined;
|
|
238
|
+
}
|
|
239
|
+
function looseField(input, wanted) {
|
|
240
|
+
const implied = impliedType(wanted);
|
|
241
|
+
const type = (input.type || '').toLowerCase();
|
|
242
|
+
if (implied === 'number' && (type === 'number' || type === 'range'))
|
|
243
|
+
return true;
|
|
244
|
+
if (implied === 'text' && (type === 'text' || type === 'textarea' || type === 'email' || type === 'search' || type === 'tel' || type === 'url' || type === 'password'))
|
|
245
|
+
return true;
|
|
246
|
+
if (implied && implied !== 'text' && implied !== 'number' && type === implied)
|
|
247
|
+
return true;
|
|
248
|
+
const wantedTokens = wanted.toLowerCase().split(/[^a-z0-9]+/).filter(token => token.length > 1 && !['input', 'inputs', 'field', 'fields', 'box', 'the', 'control', 'element'].includes(token));
|
|
249
|
+
if (wantedTokens.length === 0)
|
|
250
|
+
return false;
|
|
251
|
+
const hay = `${input.label || ''} ${input.name || ''} ${input.placeholder || ''} ${input.preceding || ''} ${input.heading || ''} ${input.type || ''}`.toLowerCase();
|
|
252
|
+
return wantedTokens.every(token => hay.includes(token));
|
|
195
253
|
}
|
|
196
254
|
function inputByNameSelector(inputs, target) {
|
|
197
255
|
return inputs.find(input => input.name && nameSelector(input.name) === target);
|
|
@@ -343,28 +401,38 @@ export async function executeAction(page, action, timeoutMs, options) {
|
|
|
343
401
|
try {
|
|
344
402
|
switch (action.tool) {
|
|
345
403
|
case 'click': {
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
404
|
+
const located = await elementFor(page, action, options?.located);
|
|
405
|
+
if ('reason' in located)
|
|
406
|
+
return miss(located.reason);
|
|
407
|
+
const locator = located.locator;
|
|
408
|
+
const acted = located.action;
|
|
409
|
+
const disabled = await disabledOutcome(locator, acted, options?.strictOracles);
|
|
410
|
+
if (disabled)
|
|
411
|
+
return disabled;
|
|
412
|
+
await locator.click({ timeout: timeoutMs });
|
|
353
413
|
await settleSPA(page).catch(() => { });
|
|
354
|
-
return
|
|
414
|
+
return done('passed', `Clicked ${describeTarget(acted)}.`, acted);
|
|
355
415
|
}
|
|
356
416
|
case 'fill': {
|
|
357
|
-
const
|
|
417
|
+
const located = await elementFor(page, action, options?.located);
|
|
418
|
+
if ('reason' in located)
|
|
419
|
+
return miss(located.reason);
|
|
420
|
+
const locator = located.locator;
|
|
421
|
+
const acted = located.action;
|
|
422
|
+
const disabled = await disabledOutcome(locator, acted, options?.strictOracles);
|
|
423
|
+
if (disabled)
|
|
424
|
+
return disabled;
|
|
358
425
|
const meta = await readFillTarget(locator);
|
|
359
426
|
if (meta?.type === 'checkbox' || meta?.type === 'radio') {
|
|
360
|
-
await locator.
|
|
361
|
-
return
|
|
427
|
+
await locator.check({ timeout: timeoutMs });
|
|
428
|
+
return done('passed', `Checked ${describeTarget(acted)}.`, acted);
|
|
362
429
|
}
|
|
363
430
|
const safeValue = meta
|
|
364
431
|
? valueForInput(meta, action.value ?? '')
|
|
365
432
|
: (action.value ?? '');
|
|
366
|
-
|
|
367
|
-
|
|
433
|
+
const numeric = meta?.type === 'number' || meta?.type === 'tel' || meta?.type === 'range';
|
|
434
|
+
await fillWithFallback(page, locator, safeValue, timeoutMs, numeric);
|
|
435
|
+
return done('passed', `Typed "${truncate(safeValue, 40)}" into ${describeTarget(acted)}.`, acted);
|
|
368
436
|
}
|
|
369
437
|
case 'goto': {
|
|
370
438
|
const url = action.target || '';
|
|
@@ -376,9 +444,11 @@ export async function executeAction(page, action, timeoutMs, options) {
|
|
|
376
444
|
return { status: 'passed', observation: `Navigated to ${url}.` };
|
|
377
445
|
}
|
|
378
446
|
case 'wait': {
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
447
|
+
const located = await elementFor(page, action, options?.located);
|
|
448
|
+
if ('reason' in located)
|
|
449
|
+
return miss(located.reason);
|
|
450
|
+
await located.locator.waitFor({ state: 'visible', timeout: Math.min(timeoutMs, 1_000) });
|
|
451
|
+
return done('passed', `Confirmed ${describeTarget(located.action)} is visible.`, located.action);
|
|
382
452
|
}
|
|
383
453
|
case 'assert_text': {
|
|
384
454
|
const text = action.target || '';
|
|
@@ -396,13 +466,13 @@ export async function executeAction(page, action, timeoutMs, options) {
|
|
|
396
466
|
case 'press': {
|
|
397
467
|
const key = action.value || 'Enter';
|
|
398
468
|
if (action.target) {
|
|
399
|
-
const
|
|
400
|
-
if (
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
await locator.
|
|
469
|
+
const located = await elementFor(page, action, options?.located);
|
|
470
|
+
if ('reason' in located)
|
|
471
|
+
return miss(located.reason);
|
|
472
|
+
const disabled = await disabledOutcome(located.locator, located.action, options?.strictOracles);
|
|
473
|
+
if (disabled)
|
|
474
|
+
return disabled;
|
|
475
|
+
await located.locator.press(key, { timeout: timeoutMs });
|
|
406
476
|
}
|
|
407
477
|
else {
|
|
408
478
|
await page.keyboard.press(key);
|
|
@@ -524,7 +594,7 @@ export async function captureLocator(page, action) {
|
|
|
524
594
|
export async function skeletonForLLM(page) {
|
|
525
595
|
const url = page.url();
|
|
526
596
|
const title = await page.title().catch(() => '');
|
|
527
|
-
const collected = await page.evaluate(() => {
|
|
597
|
+
const collected = await page.evaluate(pageFn(() => {
|
|
528
598
|
function txt(el) {
|
|
529
599
|
return (el.textContent || '').trim().replace(/\s+/g, ' ');
|
|
530
600
|
}
|
|
@@ -572,20 +642,59 @@ export async function skeletonForLLM(page) {
|
|
|
572
642
|
}
|
|
573
643
|
return '';
|
|
574
644
|
}
|
|
645
|
+
function nearestContext(el) {
|
|
646
|
+
const chunks = [];
|
|
647
|
+
let node = el.previousElementSibling;
|
|
648
|
+
let hops = 0;
|
|
649
|
+
while (node && hops < 4) {
|
|
650
|
+
const text = txt(node);
|
|
651
|
+
if (text)
|
|
652
|
+
chunks.unshift(text.slice(0, 80));
|
|
653
|
+
node = node.previousElementSibling;
|
|
654
|
+
hops += 1;
|
|
655
|
+
}
|
|
656
|
+
let heading = '';
|
|
657
|
+
let parent = el.parentElement;
|
|
658
|
+
let depth = 0;
|
|
659
|
+
while (parent && depth < 6 && !heading) {
|
|
660
|
+
let sib = parent.previousElementSibling;
|
|
661
|
+
let sibHops = 0;
|
|
662
|
+
while (sib && sibHops < 4 && !heading) {
|
|
663
|
+
if (/^h[1-6]$/i.test(sib.tagName))
|
|
664
|
+
heading = txt(sib).slice(0, 80);
|
|
665
|
+
sib = sib.previousElementSibling;
|
|
666
|
+
sibHops += 1;
|
|
667
|
+
}
|
|
668
|
+
parent = parent.parentElement;
|
|
669
|
+
depth += 1;
|
|
670
|
+
}
|
|
671
|
+
return {
|
|
672
|
+
preceding: chunks.join(' ').replace(/\s+/g, ' ').trim().slice(0, 80),
|
|
673
|
+
heading,
|
|
674
|
+
};
|
|
675
|
+
}
|
|
575
676
|
const inputs = Array.from(document.querySelectorAll('input, textarea, select'))
|
|
576
677
|
.slice(0, 25)
|
|
577
678
|
.map(el => {
|
|
578
679
|
const i = el;
|
|
579
680
|
const label = fieldLabel(i);
|
|
681
|
+
const ctx = nearestContext(i);
|
|
682
|
+
const type = i.type || i.tagName.toLowerCase();
|
|
683
|
+
if (type === 'hidden')
|
|
684
|
+
return undefined;
|
|
580
685
|
return {
|
|
581
686
|
label: label || undefined,
|
|
582
687
|
placeholder: i.placeholder || undefined,
|
|
583
688
|
name: i.name || undefined,
|
|
584
|
-
|
|
689
|
+
id: i.id || undefined,
|
|
690
|
+
type,
|
|
691
|
+
preceding: ctx.preceding || undefined,
|
|
692
|
+
heading: ctx.heading || undefined,
|
|
585
693
|
};
|
|
586
|
-
})
|
|
694
|
+
})
|
|
695
|
+
.filter((item) => Boolean(item));
|
|
587
696
|
return { headings, buttons, links, inputs };
|
|
588
|
-
});
|
|
697
|
+
}));
|
|
589
698
|
return {
|
|
590
699
|
url,
|
|
591
700
|
title,
|
|
@@ -608,6 +717,29 @@ export function describeTarget(action) {
|
|
|
608
717
|
* A missing element throws immediately (`isDisabled` defaults to no wait) and
|
|
609
718
|
* falls through to the real action.
|
|
610
719
|
*/
|
|
720
|
+
/**
|
|
721
|
+
* A disabled control is not clicked or filled. Strict oracles record it as
|
|
722
|
+
* a product bug. Otherwise the step stops immediately instead of waiting
|
|
723
|
+
* for the control to become enabled.
|
|
724
|
+
*/
|
|
725
|
+
async function disabledOutcome(locator, action, strict) {
|
|
726
|
+
let disabled = false;
|
|
727
|
+
try {
|
|
728
|
+
disabled = await locator.isDisabled();
|
|
729
|
+
}
|
|
730
|
+
catch {
|
|
731
|
+
return undefined;
|
|
732
|
+
}
|
|
733
|
+
if (!disabled)
|
|
734
|
+
return undefined;
|
|
735
|
+
if (strict)
|
|
736
|
+
return failIfDisabled(locator, action);
|
|
737
|
+
return {
|
|
738
|
+
status: 'skipped',
|
|
739
|
+
observation: `The only match for ${describeTarget(action)} is disabled, so it was not used.`,
|
|
740
|
+
error: 'locator-unresolved',
|
|
741
|
+
};
|
|
742
|
+
}
|
|
611
743
|
async function failIfDisabled(locator, action) {
|
|
612
744
|
try {
|
|
613
745
|
if (await locator.first().isDisabled()) {
|
|
@@ -623,6 +755,54 @@ async function failIfDisabled(locator, action) {
|
|
|
623
755
|
}
|
|
624
756
|
return undefined;
|
|
625
757
|
}
|
|
758
|
+
async function elementFor(page, action, located) {
|
|
759
|
+
if (located)
|
|
760
|
+
return located;
|
|
761
|
+
return locateActionTarget(page, action);
|
|
762
|
+
}
|
|
763
|
+
function miss(reason) {
|
|
764
|
+
return { status: 'skipped', observation: reason, error: 'locator-unresolved' };
|
|
765
|
+
}
|
|
766
|
+
function done(status, observation, acted) {
|
|
767
|
+
return { status, observation, ...(acted ? { resolved: acted } : {}) };
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* `input[type=number]` accepts digits via `fill`. When the browser rejects
|
|
771
|
+
* that write, click the control and type the same digits.
|
|
772
|
+
*/
|
|
773
|
+
async function fillWithFallback(page, locator, value, timeoutMs, numeric) {
|
|
774
|
+
const fillTimeout = numeric ? Math.min(timeoutMs, 2_000) : timeoutMs;
|
|
775
|
+
try {
|
|
776
|
+
await locator.fill(value, { timeout: fillTimeout });
|
|
777
|
+
if (!numeric)
|
|
778
|
+
return;
|
|
779
|
+
const actual = await locator.inputValue().catch(() => '');
|
|
780
|
+
if (actual === value)
|
|
781
|
+
return;
|
|
782
|
+
throw new Error(`fill did not set number value (got "${actual}")`);
|
|
783
|
+
}
|
|
784
|
+
catch (err) {
|
|
785
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
786
|
+
if (!numeric || !isFillRejection(msg))
|
|
787
|
+
throw err;
|
|
788
|
+
}
|
|
789
|
+
await locator.click({ timeout: Math.min(timeoutMs, 2_000) });
|
|
790
|
+
await locator.press('Control+A').catch(() => { });
|
|
791
|
+
try {
|
|
792
|
+
await locator.pressSequentially(value, { timeout: Math.min(timeoutMs, 3_000) });
|
|
793
|
+
}
|
|
794
|
+
catch {
|
|
795
|
+
await page.keyboard.insertText(value);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
function isFillRejection(msg) {
|
|
799
|
+
const lower = msg.toLowerCase();
|
|
800
|
+
return lower.includes('cannot type text')
|
|
801
|
+
|| lower.includes('not an <input')
|
|
802
|
+
|| lower.includes('not editable')
|
|
803
|
+
|| lower.includes('fill did not set')
|
|
804
|
+
|| (lower.includes('timeout') && lower.includes('locator.fill'));
|
|
805
|
+
}
|
|
626
806
|
function isSoftAutomationMiss(msg) {
|
|
627
807
|
const lower = msg.toLowerCase();
|
|
628
808
|
return (lower.includes('timeout') && (lower.includes('waiting for locator')
|