import * as SUT from '../../playwright-fluent' ; import * as path from 'path' ; describe ( 'Playwright Fluent - clearText' , ( ) : 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 , 'clear-text.test.html' ) }` ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . clearText ( ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( 'You must first click on an editable element before clearing text' ) ; } ) ; test ( 'should first click on an editable element - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'clear-text.test.html' ) }` ; const selector = '#not-editable-content' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . clearText ( ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( 'You must first click on an editable element before clearing text' ) ; } ) ; test ( 'should raise an error when clicked div is not editable - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'clear-text.test.html' ) }` ; const selector = '#content-not-editable-div' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . clearText ( ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( 'You must first click on an editable element before clearing text' ) ; } ) ; test ( 'should clear text in an input selector - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'clear-text.test.html' ) }` ; const selector = '#in-view-port' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . clearText ( ) ; const currentValue = await p . getValueOf ( selector ) ; expect ( currentValue ) . toBe ( '' ) ; } ) ; test ( 'should clear text in an input selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'clear-text.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'I am in viewport' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . clear ( ) ; const currentValue = await p . getValueOf ( '#in-view-port' ) ; expect ( currentValue ) . toBe ( '' ) ; } ) ; test ( 'should clear text in a contenteditable selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'clear-text.test.html' ) }` ; const selector = p . selector ( 'p' ) . withText ( 'dynamically added' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . clearText ( ) ; const currentText = await p . getInnerTextOf ( 'p#dynamically-added' ) ; expect ( currentText ) . toBe ( '' ) ; } ) ; test ( 'should clear text in a contenteditable div selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'clear-text.test.html' ) }` ; const selector = p . selector ( 'div[contenteditable="true"]' ) . withText ( 'editable div' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . click ( selector ) . clearText ( ) ; const currentText = await p . getInnerTextOf ( 'div#content-editable-div' ) ; expect ( currentText ) . toBe ( '' ) ; } ) ; } ) ;