import { PlaywrightFluent } from '../../playwright-fluent' ; import path from 'path' ; describe ( 'Playwright Fluent - expectThatDialog().hasMessage(message)' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should assert dialog has message alert - chromium' , async ( ) : Promise < void > => { const browser = 'chromium' ; const url = `file:${ path . join ( __dirname , 'expect-dialog-has-message-alert.test.html' ) }` ; await p . withBrowser ( browser ) . withOptions ( { headless : true } ) . WithDialogs ( ) . navigateTo ( url ) . expectThatDialog ( ) . isOfType ( 'alert' ) . expectThatDialog ( ) . hasMessage ( 'alert' ) ; } ) ; test ( 'should assert dialog has message confirm - chromium' , async ( ) : Promise < void > => { const browser = 'chromium' ; const url = `file:${ path . join ( __dirname , 'expect-dialog-has-message-confirm.test.html' ) }` ; await p . withBrowser ( browser ) . withOptions ( { headless : true } ) . WithDialogs ( ) . navigateTo ( url ) . expectThatDialog ( ) . isOfType ( 'confirm' ) . expectThatDialog ( ) . hasMessage ( 'confirm' ) ; } ) ; test ( 'should assert dialog has message prompt - chromium' , async ( ) : Promise < void > => { const browser = 'chromium' ; const url = `file:${ path . join ( __dirname , 'expect-dialog-has-message-prompt.test.html' ) }` ; await p . withBrowser ( browser ) . withOptions ( { headless : true } ) . WithDialogs ( ) . navigateTo ( url ) . expectThatDialog ( ) . isOfType ( 'prompt' ) . expectThatDialog ( ) . hasMessage ( 'prompt' ) ; } ) ; test ( 'should assert wrong message on opened dialog - chromium' , async ( ) : Promise < void > => { const browser = 'chromium' ; const url = `file:${ path . join ( __dirname , 'expect-dialog-has-message-prompt.test.html' ) }` ; let result = undefined ; try { await p . withBrowser ( browser ) . withOptions ( { headless : true } ) . WithDialogs ( ) . navigateTo ( url ) . expectThatDialog ( ) . isOfType ( 'prompt' ) . expectThatDialog ( ) . hasMessage ( 'yo! this is an alert!' , { timeoutInMilliseconds : 0 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Current dialog has message 'yo! please prompt!' but it should be 'yo! this is an alert!'" ) ; } ) ; test ( 'should assert that no subscription to page dialog events has been done - chromium' , async ( ) : Promise < void > => { const browser = 'chromium' ; const url = `file:${ path . join ( __dirname , 'expect-dialog-has-message-prompt.test.html' ) }` ; let result = undefined ; try { await p . withBrowser ( browser ) . withOptions ( { headless : true } ) . navigateTo ( url ) . expectThatDialog ( ) . hasMessage ( 'prompt' , { timeoutInMilliseconds : 1000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "No dialog has been opened. Maybe you forgot to call the '.withDialogs()' on the playwright-fluent instance." ) ; } ) ; } ) ;