File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,13 @@ 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 textLengthIn1kChars = Math . floor ( value . length / 1_000 ) ;
164+ const timeoutPer1kChars = 5_000 ; // ms
165+ const fillTimeout =
166+ context . getSelectedPage ( ) . getDefaultTimeout ( ) +
167+ textLengthIn1kChars * timeoutPer1kChars ;
168+ await handle . asLocator ( ) . setTimeout ( fillTimeout ) . fill ( value ) ;
163169 }
164170 } finally {
165171 void handle . dispose ( ) ;
@@ -183,6 +189,7 @@ export const fill = defineTool({
183189 } ,
184190 handler : async ( request , response , context ) => {
185191 await context . waitForEventsAfterAction ( async ( ) => {
192+ await context . getSelectedPage ( ) . keyboard . type ( request . params . value ) ;
186193 await fillFormElement (
187194 request . params . uid ,
188195 request . params . value ,
Original file line number Diff line number Diff 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' , ( ) => {
You can’t perform that action at this time.
0 commit comments