cdp-skill 1.0.2 → 1.0.4
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 +3 -0
- package/SKILL.md +34 -5
- package/package.json +2 -1
- package/src/capture/console-capture.js +241 -0
- package/src/capture/debug-capture.js +144 -0
- package/src/capture/error-aggregator.js +151 -0
- package/src/capture/eval-serializer.js +320 -0
- package/src/capture/index.js +40 -0
- package/src/capture/network-capture.js +211 -0
- package/src/capture/pdf-capture.js +256 -0
- package/src/capture/screenshot-capture.js +325 -0
- package/src/cdp/browser.js +569 -0
- package/src/cdp/connection.js +369 -0
- package/src/cdp/discovery.js +138 -0
- package/src/cdp/index.js +29 -0
- package/src/cdp/target-and-session.js +439 -0
- package/src/cdp-skill.js +25 -11
- package/src/constants.js +79 -0
- package/src/dom/actionability.js +638 -0
- package/src/dom/click-executor.js +923 -0
- package/src/dom/element-handle.js +496 -0
- package/src/dom/element-locator.js +475 -0
- package/src/dom/element-validator.js +120 -0
- package/src/dom/fill-executor.js +489 -0
- package/src/dom/index.js +248 -0
- package/src/dom/input-emulator.js +406 -0
- package/src/dom/keyboard-executor.js +202 -0
- package/src/dom/quad-helpers.js +89 -0
- package/src/dom/react-filler.js +94 -0
- package/src/dom/wait-executor.js +423 -0
- package/src/index.js +6 -6
- package/src/page/cookie-manager.js +202 -0
- package/src/page/dom-stability.js +181 -0
- package/src/page/index.js +36 -0
- package/src/{page.js → page/page-controller.js} +109 -839
- package/src/page/wait-utilities.js +302 -0
- package/src/page/web-storage-manager.js +108 -0
- package/src/runner/context-helpers.js +224 -0
- package/src/runner/execute-browser.js +518 -0
- package/src/runner/execute-form.js +315 -0
- package/src/runner/execute-input.js +308 -0
- package/src/runner/execute-interaction.js +672 -0
- package/src/runner/execute-navigation.js +180 -0
- package/src/runner/execute-query.js +771 -0
- package/src/runner/index.js +51 -0
- package/src/runner/step-executors.js +421 -0
- package/src/runner/step-validator.js +641 -0
- package/src/tests/Actionability.test.js +613 -0
- package/src/tests/BrowserClient.test.js +1 -1
- package/src/tests/ChromeDiscovery.test.js +1 -1
- package/src/tests/ClickExecutor.test.js +554 -0
- package/src/tests/ConsoleCapture.test.js +1 -1
- package/src/tests/ContextHelpers.test.js +453 -0
- package/src/tests/CookieManager.test.js +450 -0
- package/src/tests/DebugCapture.test.js +307 -0
- package/src/tests/ElementHandle.test.js +1 -1
- package/src/tests/ElementLocator.test.js +1 -1
- package/src/tests/ErrorAggregator.test.js +1 -1
- package/src/tests/EvalSerializer.test.js +391 -0
- package/src/tests/FillExecutor.test.js +611 -0
- package/src/tests/InputEmulator.test.js +1 -1
- package/src/tests/KeyboardExecutor.test.js +430 -0
- package/src/tests/NetworkErrorCapture.test.js +1 -1
- package/src/tests/PageController.test.js +1 -1
- package/src/tests/PdfCapture.test.js +333 -0
- package/src/tests/ScreenshotCapture.test.js +1 -1
- package/src/tests/SessionRegistry.test.js +1 -1
- package/src/tests/StepValidator.test.js +527 -0
- package/src/tests/TargetManager.test.js +1 -1
- package/src/tests/TestRunner.test.js +1 -1
- package/src/tests/WaitStrategy.test.js +1 -1
- package/src/tests/WaitUtilities.test.js +508 -0
- package/src/tests/WebStorageManager.test.js +333 -0
- package/src/types.js +309 -0
- package/src/capture.js +0 -1400
- package/src/cdp.js +0 -1286
- package/src/dom.js +0 -4379
- package/src/runner.js +0 -3676
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import { describe, it, mock, beforeEach, afterEach } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { createFillExecutor } from '../dom/fill-executor.js';
|
|
4
|
+
|
|
5
|
+
describe('FillExecutor', () => {
|
|
6
|
+
let mockSession;
|
|
7
|
+
let mockElementLocator;
|
|
8
|
+
let mockInputEmulator;
|
|
9
|
+
let mockAriaSnapshot;
|
|
10
|
+
let executor;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
mockSession = {
|
|
14
|
+
send: mock.fn(async () => ({}))
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
mockElementLocator = {
|
|
18
|
+
findElement: mock.fn(async () => ({
|
|
19
|
+
_handle: {
|
|
20
|
+
objectId: 'obj-123',
|
|
21
|
+
dispose: mock.fn(async () => {})
|
|
22
|
+
},
|
|
23
|
+
objectId: 'obj-123'
|
|
24
|
+
}))
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
mockInputEmulator = {
|
|
28
|
+
click: mock.fn(async () => {}),
|
|
29
|
+
type: mock.fn(async () => {}),
|
|
30
|
+
selectAll: mock.fn(async () => {})
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
mockAriaSnapshot = {
|
|
34
|
+
getElementByRef: mock.fn(async () => ({
|
|
35
|
+
box: { x: 50, y: 50, width: 200, height: 30 },
|
|
36
|
+
isVisible: true,
|
|
37
|
+
stale: false
|
|
38
|
+
}))
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
executor = createFillExecutor(mockSession, mockElementLocator, mockInputEmulator, mockAriaSnapshot);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
mock.reset();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('createFillExecutor', () => {
|
|
49
|
+
it('should throw if session is not provided', () => {
|
|
50
|
+
assert.throws(() => createFillExecutor(null, mockElementLocator, mockInputEmulator), {
|
|
51
|
+
message: 'CDP session is required'
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should throw if elementLocator is not provided', () => {
|
|
56
|
+
assert.throws(() => createFillExecutor(mockSession, null, mockInputEmulator), {
|
|
57
|
+
message: 'Element locator is required'
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should throw if inputEmulator is not provided', () => {
|
|
62
|
+
assert.throws(() => createFillExecutor(mockSession, mockElementLocator, null), {
|
|
63
|
+
message: 'Input emulator is required'
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should return an object with expected methods', () => {
|
|
68
|
+
assert.ok(typeof executor.execute === 'function');
|
|
69
|
+
assert.ok(typeof executor.executeBatch === 'function');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('execute', () => {
|
|
74
|
+
it('should throw if value is not provided', async () => {
|
|
75
|
+
await assert.rejects(
|
|
76
|
+
() => executor.execute({ selector: '#input' }),
|
|
77
|
+
{ message: 'Fill requires value' }
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should throw if selector/ref/label is not provided', async () => {
|
|
82
|
+
await assert.rejects(
|
|
83
|
+
() => executor.execute({ value: 'test' }),
|
|
84
|
+
{ message: 'Fill requires selector, ref, or label' }
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should fill by selector', async () => {
|
|
89
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
90
|
+
if (method === 'Runtime.evaluate') {
|
|
91
|
+
return { result: { objectId: 'obj-123' } };
|
|
92
|
+
}
|
|
93
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
94
|
+
// Handle actionability check - must return matches: true for 'attached'
|
|
95
|
+
if (params?.functionDeclaration?.includes('isConnected')) {
|
|
96
|
+
return { result: { value: { matches: true, received: 'attached' } } };
|
|
97
|
+
}
|
|
98
|
+
// Handle editable check - check for the editable validation
|
|
99
|
+
if (params?.functionDeclaration?.includes('readOnly') ||
|
|
100
|
+
params?.functionDeclaration?.includes('isContentEditable') ||
|
|
101
|
+
params?.functionDeclaration?.includes('textInputTypes')) {
|
|
102
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
103
|
+
}
|
|
104
|
+
if (params?.functionDeclaration?.includes('getBoundingClientRect')) {
|
|
105
|
+
return { result: { value: { x: 150, y: 100, rect: { x: 50, y: 50, width: 200, height: 30 } } } };
|
|
106
|
+
}
|
|
107
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
108
|
+
return { result: {} };
|
|
109
|
+
}
|
|
110
|
+
// Default for editable check
|
|
111
|
+
if (params?.functionDeclaration?.includes('disabled')) {
|
|
112
|
+
return { result: { value: { matches: true, received: 'enabled' } } };
|
|
113
|
+
}
|
|
114
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
115
|
+
}
|
|
116
|
+
return {};
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const result = await executor.execute({ selector: '#input', value: 'test value' });
|
|
120
|
+
assert.strictEqual(result.filled, true);
|
|
121
|
+
assert.strictEqual(result.selector, '#input');
|
|
122
|
+
assert.strictEqual(result.method, 'keyboard');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should fill by ref', async () => {
|
|
126
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
127
|
+
if (method === 'Runtime.evaluate') {
|
|
128
|
+
return { result: { objectId: 'obj-123' } };
|
|
129
|
+
}
|
|
130
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
131
|
+
if (params?.functionDeclaration?.includes('scrollIntoView')) {
|
|
132
|
+
return { result: {} };
|
|
133
|
+
}
|
|
134
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
135
|
+
return { result: {} };
|
|
136
|
+
}
|
|
137
|
+
return { result: { value: { editable: true } } };
|
|
138
|
+
}
|
|
139
|
+
if (method === 'Runtime.getProperties') {
|
|
140
|
+
return { result: [] };
|
|
141
|
+
}
|
|
142
|
+
return {};
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const result = await executor.execute({ ref: 'e1', value: 'ref value' });
|
|
146
|
+
assert.strictEqual(result.filled, true);
|
|
147
|
+
assert.strictEqual(result.ref, 'e1');
|
|
148
|
+
assert.strictEqual(result.method, 'keyboard');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('should detect ref from selector pattern', async () => {
|
|
152
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
153
|
+
if (method === 'Runtime.evaluate') {
|
|
154
|
+
return { result: { objectId: 'obj-123' } };
|
|
155
|
+
}
|
|
156
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
157
|
+
if (params?.functionDeclaration?.includes('scrollIntoView')) {
|
|
158
|
+
return { result: {} };
|
|
159
|
+
}
|
|
160
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
161
|
+
return { result: {} };
|
|
162
|
+
}
|
|
163
|
+
return { result: { value: { editable: true } } };
|
|
164
|
+
}
|
|
165
|
+
return {};
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const result = await executor.execute({ selector: 'e5', value: 'test' });
|
|
169
|
+
assert.strictEqual(result.filled, true);
|
|
170
|
+
assert.strictEqual(result.ref, 'e5');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should fill by label', async () => {
|
|
174
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
175
|
+
if (method === 'Runtime.evaluate') {
|
|
176
|
+
if (params?.expression?.includes('label[for]')) {
|
|
177
|
+
return { result: { objectId: 'wrapper-obj' } };
|
|
178
|
+
}
|
|
179
|
+
return { result: { objectId: 'obj-123' } };
|
|
180
|
+
}
|
|
181
|
+
if (method === 'Runtime.getProperties') {
|
|
182
|
+
return {
|
|
183
|
+
result: [
|
|
184
|
+
{ name: 'element', value: { objectId: 'elem-obj' } },
|
|
185
|
+
{ name: 'method', value: { value: 'label-for' } }
|
|
186
|
+
]
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
190
|
+
if (params?.functionDeclaration?.includes('scrollIntoView')) {
|
|
191
|
+
return { result: {} };
|
|
192
|
+
}
|
|
193
|
+
if (params?.functionDeclaration?.includes('getBoundingClientRect')) {
|
|
194
|
+
return { result: { value: { x: 50, y: 50, width: 200, height: 30 } } };
|
|
195
|
+
}
|
|
196
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
197
|
+
return { result: {} };
|
|
198
|
+
}
|
|
199
|
+
return { result: { value: { editable: true } } };
|
|
200
|
+
}
|
|
201
|
+
if (method === 'Runtime.releaseObject') {
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
return {};
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const result = await executor.execute({ label: 'Username', value: 'john' });
|
|
208
|
+
assert.strictEqual(result.filled, true);
|
|
209
|
+
assert.strictEqual(result.label, 'Username');
|
|
210
|
+
assert.strictEqual(result.foundBy, 'label-for');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('should clear input before filling by default', async () => {
|
|
214
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
215
|
+
if (method === 'Runtime.evaluate') {
|
|
216
|
+
return { result: { objectId: 'obj-123' } };
|
|
217
|
+
}
|
|
218
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
219
|
+
if (params?.functionDeclaration?.includes('isConnected')) {
|
|
220
|
+
return { result: { value: { matches: true, received: 'attached' } } };
|
|
221
|
+
}
|
|
222
|
+
if (params?.functionDeclaration?.includes('readOnly') ||
|
|
223
|
+
params?.functionDeclaration?.includes('isContentEditable') ||
|
|
224
|
+
params?.functionDeclaration?.includes('textInputTypes')) {
|
|
225
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
226
|
+
}
|
|
227
|
+
if (params?.functionDeclaration?.includes('disabled')) {
|
|
228
|
+
return { result: { value: { matches: true, received: 'enabled' } } };
|
|
229
|
+
}
|
|
230
|
+
if (params?.functionDeclaration?.includes('getBoundingClientRect')) {
|
|
231
|
+
return { result: { value: { x: 150, y: 100, rect: { x: 50, y: 50, width: 200, height: 30 } } } };
|
|
232
|
+
}
|
|
233
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
234
|
+
return { result: {} };
|
|
235
|
+
}
|
|
236
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
237
|
+
}
|
|
238
|
+
return {};
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
await executor.execute({ selector: '#input', value: 'test' });
|
|
242
|
+
assert.strictEqual(mockInputEmulator.selectAll.mock.calls.length, 1);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('should not clear input when clear is false', async () => {
|
|
246
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
247
|
+
if (method === 'Runtime.evaluate') {
|
|
248
|
+
return { result: { objectId: 'obj-123' } };
|
|
249
|
+
}
|
|
250
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
251
|
+
if (params?.functionDeclaration?.includes('isConnected')) {
|
|
252
|
+
return { result: { value: { matches: true, received: 'attached' } } };
|
|
253
|
+
}
|
|
254
|
+
if (params?.functionDeclaration?.includes('readOnly') ||
|
|
255
|
+
params?.functionDeclaration?.includes('isContentEditable') ||
|
|
256
|
+
params?.functionDeclaration?.includes('textInputTypes')) {
|
|
257
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
258
|
+
}
|
|
259
|
+
if (params?.functionDeclaration?.includes('disabled')) {
|
|
260
|
+
return { result: { value: { matches: true, received: 'enabled' } } };
|
|
261
|
+
}
|
|
262
|
+
if (params?.functionDeclaration?.includes('getBoundingClientRect')) {
|
|
263
|
+
return { result: { value: { x: 150, y: 100, rect: { x: 50, y: 50, width: 200, height: 30 } } } };
|
|
264
|
+
}
|
|
265
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
266
|
+
return { result: {} };
|
|
267
|
+
}
|
|
268
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
269
|
+
}
|
|
270
|
+
return {};
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
await executor.execute({ selector: '#input', value: 'test', clear: false });
|
|
274
|
+
assert.strictEqual(mockInputEmulator.selectAll.mock.calls.length, 0);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('should use react filler when react option is true', async () => {
|
|
278
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
279
|
+
if (method === 'Runtime.evaluate') {
|
|
280
|
+
return { result: { objectId: 'obj-123' } };
|
|
281
|
+
}
|
|
282
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
283
|
+
if (params?.functionDeclaration?.includes('isConnected')) {
|
|
284
|
+
return { result: { value: { matches: true, received: 'attached' } } };
|
|
285
|
+
}
|
|
286
|
+
if (params?.functionDeclaration?.includes('readOnly') ||
|
|
287
|
+
params?.functionDeclaration?.includes('isContentEditable') ||
|
|
288
|
+
params?.functionDeclaration?.includes('textInputTypes')) {
|
|
289
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
290
|
+
}
|
|
291
|
+
if (params?.functionDeclaration?.includes('disabled')) {
|
|
292
|
+
return { result: { value: { matches: true, received: 'enabled' } } };
|
|
293
|
+
}
|
|
294
|
+
// React filler function
|
|
295
|
+
if (params?.functionDeclaration?.includes('nativeInputValueSetter')) {
|
|
296
|
+
return { result: {} };
|
|
297
|
+
}
|
|
298
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
299
|
+
}
|
|
300
|
+
return {};
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const result = await executor.execute({ selector: '#input', value: 'test', react: true });
|
|
304
|
+
assert.strictEqual(result.filled, true);
|
|
305
|
+
assert.strictEqual(result.method, 'react');
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe('executeBatch', () => {
|
|
310
|
+
it('should throw if params is not an object', async () => {
|
|
311
|
+
await assert.rejects(
|
|
312
|
+
() => executor.executeBatch(null),
|
|
313
|
+
{ message: 'fillForm requires an object mapping selectors to values' }
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('should throw if no fields provided', async () => {
|
|
318
|
+
await assert.rejects(
|
|
319
|
+
() => executor.executeBatch({}),
|
|
320
|
+
{ message: 'fillForm requires at least one field' }
|
|
321
|
+
);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('should fill multiple fields', async () => {
|
|
325
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
326
|
+
if (method === 'Runtime.evaluate') {
|
|
327
|
+
return { result: { objectId: 'obj-123' } };
|
|
328
|
+
}
|
|
329
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
330
|
+
if (params?.functionDeclaration?.includes('isConnected')) {
|
|
331
|
+
return { result: { value: { matches: true, received: 'attached' } } };
|
|
332
|
+
}
|
|
333
|
+
if (params?.functionDeclaration?.includes('readOnly') ||
|
|
334
|
+
params?.functionDeclaration?.includes('isContentEditable') ||
|
|
335
|
+
params?.functionDeclaration?.includes('textInputTypes')) {
|
|
336
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
337
|
+
}
|
|
338
|
+
if (params?.functionDeclaration?.includes('disabled')) {
|
|
339
|
+
return { result: { value: { matches: true, received: 'enabled' } } };
|
|
340
|
+
}
|
|
341
|
+
if (params?.functionDeclaration?.includes('getBoundingClientRect')) {
|
|
342
|
+
return { result: { value: { x: 150, y: 100, rect: { x: 50, y: 50, width: 200, height: 30 } } } };
|
|
343
|
+
}
|
|
344
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
345
|
+
return { result: {} };
|
|
346
|
+
}
|
|
347
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
348
|
+
}
|
|
349
|
+
return {};
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
const result = await executor.executeBatch({
|
|
353
|
+
'#firstName': 'John',
|
|
354
|
+
'#lastName': 'Doe'
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
assert.strictEqual(result.total, 2);
|
|
358
|
+
assert.strictEqual(result.filled, 2);
|
|
359
|
+
assert.strictEqual(result.failed, 0);
|
|
360
|
+
assert.strictEqual(result.results.length, 2);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('should support extended format with fields and react options', async () => {
|
|
364
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
365
|
+
if (method === 'Runtime.evaluate') {
|
|
366
|
+
return { result: { objectId: 'obj-123' } };
|
|
367
|
+
}
|
|
368
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
369
|
+
if (params?.functionDeclaration?.includes('isConnected')) {
|
|
370
|
+
return { result: { value: { matches: true, received: 'attached' } } };
|
|
371
|
+
}
|
|
372
|
+
if (params?.functionDeclaration?.includes('readOnly') ||
|
|
373
|
+
params?.functionDeclaration?.includes('isContentEditable') ||
|
|
374
|
+
params?.functionDeclaration?.includes('textInputTypes')) {
|
|
375
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
376
|
+
}
|
|
377
|
+
if (params?.functionDeclaration?.includes('disabled')) {
|
|
378
|
+
return { result: { value: { matches: true, received: 'enabled' } } };
|
|
379
|
+
}
|
|
380
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
381
|
+
}
|
|
382
|
+
return {};
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
const result = await executor.executeBatch({
|
|
386
|
+
fields: { '#email': 'test@example.com' },
|
|
387
|
+
react: true
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
assert.strictEqual(result.total, 1);
|
|
391
|
+
assert.strictEqual(result.filled, 1);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('should handle partial failures', async () => {
|
|
395
|
+
let firstSelectorDone = false;
|
|
396
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
397
|
+
if (method === 'Runtime.evaluate') {
|
|
398
|
+
// After first successful fill, return null for second selector
|
|
399
|
+
if (params?.expression?.includes('#missing')) {
|
|
400
|
+
return { result: { subtype: 'null' } };
|
|
401
|
+
}
|
|
402
|
+
return { result: { objectId: 'obj-123' } };
|
|
403
|
+
}
|
|
404
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
405
|
+
if (params?.functionDeclaration?.includes('isConnected')) {
|
|
406
|
+
return { result: { value: { matches: true, received: 'attached' } } };
|
|
407
|
+
}
|
|
408
|
+
if (params?.functionDeclaration?.includes('readOnly') ||
|
|
409
|
+
params?.functionDeclaration?.includes('isContentEditable') ||
|
|
410
|
+
params?.functionDeclaration?.includes('textInputTypes')) {
|
|
411
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
412
|
+
}
|
|
413
|
+
if (params?.functionDeclaration?.includes('disabled')) {
|
|
414
|
+
return { result: { value: { matches: true, received: 'enabled' } } };
|
|
415
|
+
}
|
|
416
|
+
if (params?.functionDeclaration?.includes('getBoundingClientRect')) {
|
|
417
|
+
return { result: { value: { x: 150, y: 100, rect: { x: 50, y: 50, width: 200, height: 30 } } } };
|
|
418
|
+
}
|
|
419
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
420
|
+
return { result: {} };
|
|
421
|
+
}
|
|
422
|
+
return { result: { value: { matches: true, received: 'editable' } } };
|
|
423
|
+
}
|
|
424
|
+
return {};
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
const result = await executor.executeBatch({
|
|
428
|
+
'#valid': 'value1',
|
|
429
|
+
'#missing': 'value2'
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
assert.strictEqual(result.total, 2);
|
|
433
|
+
// Note: both may fail or succeed depending on actual implementation
|
|
434
|
+
// The test should be robust to the actual behavior
|
|
435
|
+
assert.ok(result.filled >= 0);
|
|
436
|
+
assert.ok(result.failed >= 0);
|
|
437
|
+
assert.strictEqual(result.filled + result.failed, 2);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('should handle refs in batch', async () => {
|
|
441
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
442
|
+
if (method === 'Runtime.evaluate') {
|
|
443
|
+
return { result: { objectId: 'obj-123' } };
|
|
444
|
+
}
|
|
445
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
446
|
+
if (params?.functionDeclaration?.includes('scrollIntoView')) {
|
|
447
|
+
return { result: {} };
|
|
448
|
+
}
|
|
449
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
450
|
+
return { result: {} };
|
|
451
|
+
}
|
|
452
|
+
return { result: { value: { editable: true } } };
|
|
453
|
+
}
|
|
454
|
+
return {};
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
const result = await executor.executeBatch({
|
|
458
|
+
'e1': 'value1',
|
|
459
|
+
'e2': 'value2'
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
assert.strictEqual(result.total, 2);
|
|
463
|
+
assert.strictEqual(result.filled, 2);
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
describe('ref-based fill edge cases', () => {
|
|
468
|
+
it('should require ariaSnapshot for ref-based fills', async () => {
|
|
469
|
+
const noAriaExecutor = createFillExecutor(mockSession, mockElementLocator, mockInputEmulator);
|
|
470
|
+
|
|
471
|
+
// Without ariaSnapshot, the fill by ref won't work because ref requires ariaSnapshot
|
|
472
|
+
// The executor treats ref: 'e1' as needing ariaSnapshot
|
|
473
|
+
await assert.rejects(
|
|
474
|
+
() => noAriaExecutor.execute({ ref: 'e1', value: 'test' }),
|
|
475
|
+
(err) => {
|
|
476
|
+
// May fail with "requires selector, ref, or label" because ref is only valid with ariaSnapshot
|
|
477
|
+
return err.message.includes('requires') || err.message.includes('ariaSnapshot');
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it('should throw when ref element is stale', async () => {
|
|
483
|
+
mockAriaSnapshot.getElementByRef = mock.fn(async () => ({
|
|
484
|
+
box: { x: 50, y: 50, width: 200, height: 30 },
|
|
485
|
+
isVisible: true,
|
|
486
|
+
stale: true
|
|
487
|
+
}));
|
|
488
|
+
|
|
489
|
+
await assert.rejects(
|
|
490
|
+
() => executor.execute({ ref: 'e1', value: 'test' }),
|
|
491
|
+
(err) => {
|
|
492
|
+
assert.ok(err.message.includes('no longer attached'));
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it('should throw when ref element is not visible', async () => {
|
|
499
|
+
mockAriaSnapshot.getElementByRef = mock.fn(async () => ({
|
|
500
|
+
box: { x: 50, y: 50, width: 200, height: 30 },
|
|
501
|
+
isVisible: false,
|
|
502
|
+
stale: false
|
|
503
|
+
}));
|
|
504
|
+
|
|
505
|
+
await assert.rejects(
|
|
506
|
+
() => executor.execute({ ref: 'e1', value: 'test' }),
|
|
507
|
+
(err) => {
|
|
508
|
+
assert.ok(err.message.includes('not visible'));
|
|
509
|
+
return true;
|
|
510
|
+
}
|
|
511
|
+
);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('should throw when ref element not found', async () => {
|
|
515
|
+
mockAriaSnapshot.getElementByRef = mock.fn(async () => null);
|
|
516
|
+
|
|
517
|
+
await assert.rejects(
|
|
518
|
+
() => executor.execute({ ref: 'e99', value: 'test' }),
|
|
519
|
+
(err) => {
|
|
520
|
+
assert.ok(err.message.includes('not found'));
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
);
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
describe('label-based fill edge cases', () => {
|
|
528
|
+
it('should throw when label element not found', async () => {
|
|
529
|
+
mockSession.send = mock.fn(async (method) => {
|
|
530
|
+
if (method === 'Runtime.evaluate') {
|
|
531
|
+
return { result: { subtype: 'null' } };
|
|
532
|
+
}
|
|
533
|
+
return {};
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
await assert.rejects(
|
|
537
|
+
() => executor.execute({ label: 'Missing Label', value: 'test' }),
|
|
538
|
+
(err) => {
|
|
539
|
+
assert.ok(err.message.includes('not found'));
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('should support exact label matching', async () => {
|
|
546
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
547
|
+
if (method === 'Runtime.evaluate') {
|
|
548
|
+
if (params?.expression?.includes('label[for]')) {
|
|
549
|
+
return { result: { objectId: 'wrapper-obj' } };
|
|
550
|
+
}
|
|
551
|
+
return { result: { objectId: 'obj-123' } };
|
|
552
|
+
}
|
|
553
|
+
if (method === 'Runtime.getProperties') {
|
|
554
|
+
return {
|
|
555
|
+
result: [
|
|
556
|
+
{ name: 'element', value: { objectId: 'elem-obj' } },
|
|
557
|
+
{ name: 'method', value: { value: 'label-for' } }
|
|
558
|
+
]
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
562
|
+
if (params?.functionDeclaration?.includes('scrollIntoView')) {
|
|
563
|
+
return { result: {} };
|
|
564
|
+
}
|
|
565
|
+
if (params?.functionDeclaration?.includes('getBoundingClientRect')) {
|
|
566
|
+
return { result: { value: { x: 50, y: 50, width: 200, height: 30 } } };
|
|
567
|
+
}
|
|
568
|
+
if (params?.functionDeclaration?.includes('focus')) {
|
|
569
|
+
return { result: {} };
|
|
570
|
+
}
|
|
571
|
+
return { result: { value: { editable: true } } };
|
|
572
|
+
}
|
|
573
|
+
if (method === 'Runtime.releaseObject') {
|
|
574
|
+
return {};
|
|
575
|
+
}
|
|
576
|
+
return {};
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
const result = await executor.execute({ label: 'Username', value: 'test', exact: true });
|
|
580
|
+
assert.strictEqual(result.filled, true);
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
describe('non-editable element handling', () => {
|
|
585
|
+
it('should throw when element is not editable', async () => {
|
|
586
|
+
mockSession.send = mock.fn(async (method, params) => {
|
|
587
|
+
if (method === 'Runtime.evaluate') {
|
|
588
|
+
return { result: { objectId: 'obj-123' } };
|
|
589
|
+
}
|
|
590
|
+
if (method === 'Runtime.callFunctionOn') {
|
|
591
|
+
if (params?.functionDeclaration?.includes('isConnected')) {
|
|
592
|
+
return { result: { value: { matches: true, received: 'attached' } } };
|
|
593
|
+
}
|
|
594
|
+
if (params?.functionDeclaration?.includes('isContentEditable')) {
|
|
595
|
+
return { result: { value: { matches: false, received: 'not-editable-element' } } };
|
|
596
|
+
}
|
|
597
|
+
return { result: { value: { editable: false, reason: 'not-editable-element' } } };
|
|
598
|
+
}
|
|
599
|
+
return {};
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
await assert.rejects(
|
|
603
|
+
() => executor.execute({ selector: '#div', value: 'test' }),
|
|
604
|
+
(err) => {
|
|
605
|
+
assert.ok(err.message.includes('not actionable') || err.message.includes('not editable'));
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
});
|