import * as SUT from '../../playwright-fluent' ; import * as path from 'path' ; describe ( 'Playwright Fluent - pasteText' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new SUT . PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should first click on an element - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'paste-text.test.html' ) }` ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . pasteText ( 'foobar' ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( 'You must first click on an editable element before pasting text' ) ; } ) ; test ( 'should first click on an editable element - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'paste-text.test.html' ) }` ; const selector = '#not-editable-content' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . pasteText ( 'foobar' ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( 'You must first click on an editable element before pasting text' ) ; } ) ; test ( 'should paste text in an input selector that has no paste event handler- chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'paste-text.test.html' ) }` ; const selector = '#targetInput' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . pasteText ( 'foobar' , { handlePasteEvent : true } ) ; const currentValue = await p . getValueOf ( selector ) ; expect ( currentValue ) . toBe ( 'foobar' ) ; } ) ; test ( 'should paste text in a contenteditable selector that has no paste event handler- chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'paste-text.test.html' ) }` ; const selector = 'p#target' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . pasteText ( 'foobar' , { handlePasteEvent : true } ) ; const currentValue = await p . getInnerTextOf ( selector ) ; expect ( currentValue ) . toBe ( 'foobar' ) ; } ) ; test ( 'should paste text in an input selector that has a paste event handler- chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'paste-text.test.html' ) }` ; const selector = '#emptyInput' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . wait ( 1000 ) . pasteText ( 'foobar' ) ; const currentValue = await p . getValueOf ( selector ) ; expect ( currentValue ) . toBe ( 'FOOBAR' ) ; } ) ; test ( 'should type text in an input selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'paste-text.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'paste your text' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . pasteText ( 'foobar' , { handlePasteEvent : true } ) ; const currentValue = await p . getValueOf ( '#targetInput' ) ; expect ( currentValue ) . toBe ( 'foobar' ) ; } ) ; } ) ;