import * as SUT from '../../playwright-fluent' ; import * as path from 'path' ; describe ( 'Playwright Fluent - expect has value' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new SUT . PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should wait until selector has expected value - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-has-value.test.html' ) }` ; const selector = '#dynamically-added-input' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . hover ( selector ) ; await p . expectThatSelector ( selector ) . hasValue ( 'hovered' ) ; } ) ; test ( 'should wait until selector object has expected value - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-has-value.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'dynamically added' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . hasValue ( 'dynamically added' ) ; const currentValue = await selector . value ( ) ; expect ( currentValue ) . toBe ( 'dynamically added input' ) ; } ) ; test ( 'should throw on a non existing selector - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-has-value.test.html' ) }` ; const selector = 'foobar' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . hasValue ( 'yo' , { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Selector 'foobar' was not found in DOM." ) ; } ) ; test ( 'should throw on a non existing selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-has-value.test.html' ) }` ; const selector = p . selector ( 'foobar' ) ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . hasValue ( 'yo' , { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Selector 'selector(foobar)' was not found in DOM." ) ; } ) ; test ( 'should throw when selector does not contain value - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-has-value.test.html' ) }` ; const selector = '#dynamically-added-input' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . hasValue ( 'yo' , { timeoutInMilliseconds : 4000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Value of selector '#dynamically-added-input' does not contain 'yo', but instead it contains 'dynamically added input'" ) ; } ) ; test ( 'should throw when selector object does not contain value - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'expect-has-value.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'dynamically added' ) ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . expectThatSelector ( selector ) . hasValue ( 'yo' , { timeoutInMilliseconds : 4000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( `Value of 'selector(input)
  .withValue(dynamically added)' does not contain 'yo', but instead it contains 'dynamically added input'` ) ; } ) ; } ) ;