diff --git a/src/Zemu.ts b/src/Zemu.ts index c3f0dc1..b85cc61 100644 --- a/src/Zemu.ts +++ b/src/Zemu.ts @@ -748,6 +748,39 @@ export default class Zemu { return imageIndex; } + async approve( + path: string, + testcaseName: string, + text: string | RegExp, + waitForScreenUpdate = true, + takeSnapshots = true, + imageIndex: number, + ) { + // Approve can be performed with Tap or PressAndHold + const approveButton = getTouchElement(this.startOptions.model, this.startOptions.approveAction); + const textRegex = new RegExp(text, "i"); + const snapshotPrefixTmp = resolve(`${path}/snapshots-tmp/${testcaseName}`); + const filename = this.getSnapshotPath(snapshotPrefixTmp, imageIndex, takeSnapshots); + const touchDevice = isTouchDevice(this.startOptions.model); + + if (this.startOptions.approveAction === ButtonKind.DynamicTapButton) { + const events = await this.getEvents(); + const matchingEvent = events.find((event: IEvent) => textRegex.test(event.text)); + + if (matchingEvent != null) { + approveButton.x = Math.round(matchingEvent.x + matchingEvent.w / 2); + approveButton.y = Math.round(matchingEvent.y + matchingEvent.h / 2); + } + } + + const nav: INavElement = { + type: touchDevice ? ActionKind.Touch : ActionKind.BothClick, + button: approveButton, + }; + await this.runAction(nav, filename, waitForScreenUpdate, true); + return imageIndex; + } + async navigateAndCompareUntilText( path: string, testcaseName: string,