@@ -19,6 +19,7 @@ import {
1919 uploadFile ,
2020 pressKey ,
2121 clickAt ,
22+ typeText ,
2223} from '../../src/tools/input.js' ;
2324import { parseKey } from '../../src/utils/keyboard.js' ;
2425import { serverHooks } from '../server.js' ;
@@ -355,7 +356,7 @@ describe('input', () => {
355356 it ( 'fills out a textarea marked as combobox' , async ( ) => {
356357 await withMcpContext ( async ( response , context ) => {
357358 const page = context . getSelectedPage ( ) ;
358- await page . setContent ( html `< textarea role ="combobox " / > ` ) ;
359+ await page . setContent ( html `< textarea role ="combobox "> </ textarea > ` ) ;
359360 await context . createTextSnapshot ( ) ;
360361 await fill . handler (
361362 {
@@ -383,7 +384,7 @@ describe('input', () => {
383384 it ( 'fills out a textarea with long text' , async ( ) => {
384385 await withMcpContext ( async ( response , context ) => {
385386 const page = context . getSelectedPage ( ) ;
386- await page . setContent ( html `< textarea / > ` ) ;
387+ await page . setContent ( html `< textarea > </ textarea > ` ) ;
387388 await context . createTextSnapshot ( ) ;
388389 page . setDefaultTimeout ( 1000 ) ;
389390 await fill . handler (
@@ -411,6 +412,90 @@ describe('input', () => {
411412 } ) ;
412413 } ) ;
413414
415+ it ( 'types text' , async ( ) => {
416+ await withMcpContext ( async ( response , context ) => {
417+ const page = context . getSelectedPage ( ) ;
418+ await page . setContent ( html `< textarea > </ textarea > ` ) ;
419+ await page . click ( 'textarea' ) ;
420+ await context . createTextSnapshot ( ) ;
421+ await typeText . handler (
422+ {
423+ params : {
424+ text : 'test' ,
425+ } ,
426+ } ,
427+ response ,
428+ context ,
429+ ) ;
430+ assert . strictEqual ( response . responseLines [ 0 ] , 'Typed text "test"' ) ;
431+ assert . strictEqual (
432+ await page . evaluate ( ( ) => {
433+ return document . body . querySelector ( 'textarea' ) ?. value ;
434+ } ) ,
435+ 'test' ,
436+ ) ;
437+ } ) ;
438+ } ) ;
439+
440+ it ( 'types text with submit key' , async ( ) => {
441+ await withMcpContext ( async ( response , context ) => {
442+ const page = context . getSelectedPage ( ) ;
443+ await page . setContent ( html `< textarea > </ textarea > ` ) ;
444+ await page . click ( 'textarea' ) ;
445+ await context . createTextSnapshot ( ) ;
446+ await typeText . handler (
447+ {
448+ params : {
449+ text : 'test' ,
450+ submitKey : 'Tab' ,
451+ } ,
452+ } ,
453+ response ,
454+ context ,
455+ ) ;
456+ assert . strictEqual (
457+ response . responseLines [ 0 ] ,
458+ 'Typed text "test + Tab"' ,
459+ ) ;
460+ assert . strictEqual (
461+ await page . evaluate ( ( ) => {
462+ return document . body . querySelector ( 'textarea' ) ?. value ;
463+ } ) ,
464+ 'test' ,
465+ ) ;
466+ assert . ok (
467+ await page . evaluate ( ( ) => {
468+ return (
469+ document . body . querySelector ( 'textarea' ) !== document . activeElement
470+ ) ;
471+ } ) ,
472+ ) ;
473+ } ) ;
474+ } ) ;
475+
476+ it ( 'errors on invalid submit key' , async ( ) => {
477+ await withMcpContext ( async ( response , context ) => {
478+ const page = context . getSelectedPage ( ) ;
479+ await page . setContent ( html `< textarea > </ textarea > ` ) ;
480+ await page . click ( 'textarea' ) ;
481+ await context . createTextSnapshot ( ) ;
482+ try {
483+ await typeText . handler (
484+ {
485+ params : {
486+ text : 'test' ,
487+ submitKey : 'XXX' ,
488+ } ,
489+ } ,
490+ response ,
491+ context ,
492+ ) ;
493+ } catch ( err ) {
494+ assert . strictEqual ( err . message , 'Unknown key: "XXX"' ) ;
495+ }
496+ } ) ;
497+ } ) ;
498+
414499 it ( 'reproduction: fill isolation' , async ( ) => {
415500 await withMcpContext ( async ( _response , context ) => {
416501 const page = context . getSelectedPage ( ) ;
0 commit comments