import * as SUT from '../../playwright-fluent' ; import { noWaitNoThrowOptions } from '../../../utils' ; import * as path from 'path' ; describe ( 'Playwright Fluent - expectThat isDisabled' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new SUT . PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should give back an error when selector does not exists' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-is-disabled.test.html' ) }` ; const selector = 'foobar' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . isDisabled ( { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Selector 'foobar' was not found in DOM." ) ; } ) ; test ( 'should give back an error when selector object does not exists' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-is-disabled.test.html' ) }` ; const selector = p . selector ( 'foobar' ) ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . isDisabled ( { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Selector 'selector(foobar)' was not found in DOM." ) ; } ) ; test ( 'should wait until selector exists and is disabled - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-is-disabled.test.html' ) }` ; const selector = '#dynamically-added-input' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . isDisabled ( ) ; const isDisabled = await p . isDisabled ( selector , noWaitNoThrowOptions ) ; expect ( isDisabled ) . toBe ( true ) ; } ) ; test ( 'should wait until selector object exists and is disabled - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-is-disabled.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'dynamically added' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . isDisabled ( ) ; const isDisabled = await p . isDisabled ( selector , noWaitNoThrowOptions ) ; expect ( isDisabled ) . toBe ( true ) ; } ) ; test ( 'should wait until selector exists and is readOnly - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-is-disabled.test.html' ) }` ; const selector = '#dynamically-added-readonly-input' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . isDisabled ( ) ; const isDisabled = await p . isDisabled ( selector , noWaitNoThrowOptions ) ; expect ( isDisabled ) . toBe ( true ) ; } ) ; test ( 'should wait until selector object exists and is read-only - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-is-disabled.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'dynamically added readonly input' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . isDisabled ( ) ; const isDisabled = await p . isDisabled ( selector , noWaitNoThrowOptions ) ; expect ( isDisabled ) . toBe ( true ) ; } ) ; } ) ;