import * as SUT from '../index' ; import { showMousePosition } from '../../../dom-actions' ; import { hasHandleFocus } from '../../../handle-actions/has-handle-focus' ; import { defaultInvokeOptions , InvokeOptions } from '../invoke-method-on-selector' ; import { defaultVerboseOptions , isHandleChecked } from '../../../handle-actions' ; import { Browser , chromium } from 'playwright' ; import * as path from 'path' ; describe ( 'invoke method on selector' , ( ) : void => { let browser = undefined ; beforeEach ( ( ) : void => { } ) ; afterEach ( async ( ) : Promise < void > => { if ( browser ) { await browser . close ( ) ; } } ) ; test ( 'should wait for the selector to exist in DOM before invoking method - chromium' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : false } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; await showMousePosition ( page ) ; const url = `file:${ path . join ( __dirname , 'invoke-method-on-selector.test.html' ) }` ; await page . goto ( url ) ; const selector = '#dynamically-added-checkbox' ; const options = { ... defaultInvokeOptions , } ; await SUT . invokeMethodOnSelector ( 'click' , selector , page , options ) ; const handle = await page . $ ( selector ) ; expect ( await hasHandleFocus ( handle ) ) . toBe ( false ) ; expect ( await isHandleChecked ( handle , defaultVerboseOptions ) ) . toBe ( true ) ; } ) ; } ) ;