import * as playwright from "playwright" ; import { XrmUiTest } from "./XrmUITest" ; /**
 * Scheme to define how to access a button
 * Either by data-id (language independent) or by button label (language dependent, but easily visible in UI)
 */ export interface ButtonIdentifier { example byDataId ? : string ; example byLabel ? : string ; example custom ? : string ; } /**
 * Module for interacting with D365 Buttons
 */ export class Button { private _page : playwright . Page ; constructor ( private xrmUiTest ) { this . _page = xrmUiTest . page ; this . xrmUiTest = xrmUiTest ; } returns expandMoreCommands = async ( ) : Promise < boolean > => { try { await this . click ( { byDataId : "OverflowButton" } , false ) ; await this . xrmUiTest . waitForIdleness ( ) ; return true ; } catch { return false ; } } ; private buildSelector = ( identifier ) => { if ( identifier . byDataId ) { return `button[data-id='${ identifier . byDataId }']` ; } if ( identifier . byLabel ) { return `button[aria-label='${ identifier . byLabel }']` ; } if ( identifier . custom ) { return identifier . custom ; } } ; param buttonIdentifier param openMoreCommands returns click = async ( buttonIdentifier , openMoreCommands = true ) : Promise < void > => { const selector = this . buildSelector ( buttonIdentifier ) ; const button = await this . _page . $ ( selector ) ; if ( ! button && openMoreCommands && await this . expandMoreCommands ( ) ) { return this . click ( buttonIdentifier , false ) ; } if ( ! button ) { throw new Error ( "Failed to find button" ) ; } await button . click ( ) ; return this . xrmUiTest . waitForIdleness ( ) ; } ; param buttonIdentifier param openMoreCommands returns isVisible = async ( buttonIdentifier , openMoreCommands = true ) : Promise < boolean > => { const selector = this . buildSelector ( buttonIdentifier ) ; const button = await this . _page . $ ( selector ) ; if ( ! button && openMoreCommands && await this . expandMoreCommands ( ) ) { return this . isVisible ( buttonIdentifier , false ) ; } return button ?. isVisible ( ) ?? false ; } ; }