import * as SUT from '../../playwright-fluent' ; import * as path from 'path' ; describe ( 'Playwright Fluent - typeText' , ( ) : 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 , 'typetext.test.html' ) }` ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . typeText ( 'foobar' ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( 'You must first click on an editable element before typing text' ) ; } ) ; test ( 'should first click on an editable element - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'typetext.test.html' ) }` ; const selector = '#not-editable-content' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . typeText ( 'foobar' ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( 'You must first click on an editable element before typing text' ) ; } ) ; test ( 'should type text in an input selector - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'typetext.test.html' ) }` ; const selector = '#in-view-port' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . typeText ( 'foobar' ) ; const currentValue = await p . getValueOf ( selector ) ; expect ( currentValue ) . toBe ( 'foobar' ) ; } ) ; test ( 'should clear text before typing in an input selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'typetext.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'I am in viewport' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . typeText ( 'foobar' ) ; const currentValue = await p . getValueOf ( '#in-view-port' ) ; expect ( currentValue ) . toBe ( 'foobar' ) ; } ) ; test ( 'should type text in an empty input selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'typetext.test.html' ) }` ; const selector = p . selector ( 'input#in-view-port-and-empty' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . typeText ( 'foobar' ) ; const currentValue = await p . getValueOf ( '#in-view-port-and-empty' ) ; expect ( currentValue ) . toBe ( 'foobar' ) ; } ) ; test ( 'should type text in an editable selector - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'typetext.test.html' ) }` ; const selector = 'p#editable-content' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . typeText ( 'foobar' ) ; const currentValue = await p . getInnerTextOf ( selector ) ; expect ( currentValue ) . toBe ( 'foobar' ) ; } ) ; } ) ;