豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit a83a338

Browse files
authored
fix: increase timeouts for long text input (#787)
Fixes #786
1 parent 6d0e4ca commit a83a338

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

scripts/test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const nodeArgs = [
5353
'spec',
5454
'--test-force-exit',
5555
'--test',
56-
'--test-timeout=30000',
56+
'--test-timeout=60000',
5757
...flags,
5858
...files,
5959
];

src/tools/input.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ async function fillFormElement(
159159
if (aXNode && aXNode.role === 'combobox') {
160160
await selectOption(handle, aXNode, value);
161161
} else {
162-
await handle.asLocator().fill(value);
162+
// Increase timeout for longer input values.
163+
const timeoutPerChar = 10; // ms
164+
const fillTimeout =
165+
context.getSelectedPage().getDefaultTimeout() +
166+
value.length * timeoutPerChar;
167+
await handle.asLocator().setTimeout(fillTimeout).fill(value);
163168
}
164169
} finally {
165170
void handle.dispose();
@@ -183,6 +188,7 @@ export const fill = defineTool({
183188
},
184189
handler: async (request, response, context) => {
185190
await context.waitForEventsAfterAction(async () => {
191+
await context.getSelectedPage().keyboard.type(request.params.value);
186192
await fillFormElement(
187193
request.params.uid,
188194
request.params.value,

tests/tools/input.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,38 @@ describe('input', () => {
301301
assert.strictEqual(selectedValue, 'v2');
302302
});
303303
});
304+
305+
it('fills out a textarea with long text', async () => {
306+
await withMcpContext(async (response, context) => {
307+
const page = context.getSelectedPage();
308+
await page.setContent(html`<textarea />`);
309+
await page.focus('textarea');
310+
await context.createTextSnapshot();
311+
await page.setDefaultTimeout(1000);
312+
await fill.handler(
313+
{
314+
params: {
315+
uid: '1_1',
316+
value: '1'.repeat(3000),
317+
},
318+
},
319+
response,
320+
context,
321+
);
322+
assert.strictEqual(
323+
response.responseLines[0],
324+
'Successfully filled out the element',
325+
);
326+
assert.ok(response.includeSnapshot);
327+
assert.ok(
328+
await page.evaluate(() => {
329+
return (
330+
document.body.querySelector('textarea')?.value.length === 3_000
331+
);
332+
}),
333+
);
334+
});
335+
});
304336
});
305337

306338
describe('drags', () => {

tests/tools/performance.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('performance', () => {
140140
});
141141
});
142142

143-
it.only('supports filePath', async () => {
143+
it('supports filePath', async () => {
144144
const rawData = loadTraceAsBuffer('basic-trace.json.gz');
145145
// rawData is the decompressed buffer (based on loadTraceAsBuffer implementation).
146146
// We want to simulate saving it as a .gz file, so the tool should compress it.

0 commit comments

Comments
 (0)