import * as SUT from '../index' ; import { getClientRectangleOf , showMousePosition } from '../../../dom-actions' ; import { ClickOptions , defaultClickOptions } from '../../../handle-actions' ; import { Browser , chromium } from 'playwright' ; import * as path from 'path' ; describe ( 'click at position' , ( ) : void => { let browser = undefined ; beforeEach ( ( ) : void => { } ) ; afterEach ( async ( ) : Promise < void > => { if ( browser ) { await browser . close ( ) ; } } ) ; test ( 'should click at position - chromium' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; await showMousePosition ( page ) ; const url = `file:${ path . join ( __dirname , 'click-at-position.test.html' ) }` ; await page . goto ( url ) ; const inputSelector = '#flexSwitchCheckChecked' ; const switchContainer = '#switch-container' ; const clientRectangle = await getClientRectangleOf ( switchContainer , page ) ; const xCenter = clientRectangle . left + clientRectangle . width / 2 ; const yCenter = clientRectangle . top + clientRectangle . height / 2 ; const xLeft = clientRectangle . left ; const input = await page . $ ( inputSelector ) ; const options = { ... defaultClickOptions , } ; expect ( await input ?. isChecked ( ) ) . toBe ( false ) ; await SUT . clickAtPosition ( { x : xCenter , y : yCenter } , page , options ) ; expect ( await input ?. isChecked ( ) ) . toBe ( false ) ; await SUT . clickAtPosition ( { x : xLeft + 10 , y : yCenter } , page , options ) ; expect ( await input ?. isChecked ( ) ) . toBe ( true ) ; } ) ; } ) ;