import { PlaywrightFluent } from '../../playwright-fluent' ; import path from 'path' ; describe ( 'Playwright Fluent - typeTextInDialogAndSubmit()' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should type text and submit dialog prompt - chromium' , async ( ) : Promise < void > => { const browser = 'chromium' ; const url = `file:${ path . join ( __dirname , 'typetext-in-dialog-and-submit-prompt.test.html' ) }` ; const answerSelector = '#answer' ; await p . withBrowser ( browser ) . withOptions ( { headless : true } ) . WithDialogs ( ) . navigateTo ( url ) . expectThat ( answerSelector ) . hasValue ( 'waiting for your answer ...' ) . waitForDialog ( ) . expectThatDialog ( ) . isOfType ( 'prompt' ) . expectThatDialog ( ) . hasMessage ( 'yo?' ) . expectThatDialog ( ) . hasValue ( 'yes' ) . typeTextInDialogAndSubmit ( 'foobar' ) . expectThat ( answerSelector ) . hasValue ( 'foobar' ) ; } ) ; test ( 'should assert that no dialog has been opened - chromium' , async ( ) : Promise < void > => { const browser = 'chromium' ; const url = `file:${ path . join ( __dirname , 'typetext-in-dialog-and-submit-prompt.test.html' ) }` ; let result = undefined ; try { await p . withBrowser ( browser ) . withOptions ( { headless : true } ) . navigateTo ( url ) . typeTextInDialogAndSubmit ( 'foobar' ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( 'Cannot accept dialog because no dialog has been opened' ) ; } ) ; } ) ;