Skip to content

Commit c0dd657

Browse files
committed
chore: tidy up matchAndTapImage logging
1 parent f6f8764 commit c0dd657

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

run/types/DeviceWrapper.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ export class DeviceWrapper {
10171017
// Find all candidate elements matching the locator
10181018
const elements = await this.findElements(locator.strategy, locator.selector);
10191019
this.info(
1020-
`[matchAndTapImage] Found ${elements.length} elements for ${locator.strategy} "${locator.selector}"`
1020+
`[matchAndTapImage] Starting image matching: ${elements.length} elements with ${locator.strategy} "${locator.selector}"`
10211021
);
10221022

10231023
// Load the reference image buffer from disk
@@ -1030,8 +1030,7 @@ export class DeviceWrapper {
10301030
} | null = null;
10311031

10321032
// Iterate over each candidate element
1033-
for (const [i, el] of elements.entries()) {
1034-
this.info(`[matchAndTapImage] Processing element ${i + 1}/${elements.length}`);
1033+
for (const el of elements) {
10351034

10361035
// Take a screenshot of the element
10371036
const base64 = await this.getElementScreenshot(el.ELEMENT);
@@ -1064,7 +1063,6 @@ export class DeviceWrapper {
10641063
const { rect: matchRect, score } = await getImageOccurrence(elementBuffer, resizedRef, {
10651064
threshold,
10661065
});
1067-
this.info(`[matchAndTapImage] Match score for element ${i + 1}: ${score.toFixed(4)}`);
10681066

10691067
/**
10701068
* Matching is done on a resized reference image to account for device pixel density.
@@ -1097,29 +1095,25 @@ export class DeviceWrapper {
10971095
// If earlyMatch is enabled and the score is high enough, tap immediately
10981096
if (earlyMatch && score >= earlyMatchThreshold) {
10991097
this.info(
1100-
`[matchAndTapImage] Tapping first match with ${(score * 100).toFixed(2)}% confidence`
1098+
`[matchAndTapImage] Tapping first high-confidence match (${(score * 100).toFixed(2)}%)`
11011099
);
11021100
await clickOnCoordinates(this, center);
11031101
return;
11041102
}
11051103
// Otherwise, keep track of the best match so far
11061104
if (!bestMatch || score > bestMatch.score) {
11071105
bestMatch = { center, score };
1108-
this.info(`[matchAndTapImage] New best match: ${(score * 100).toFixed(2)}% confidence`);
11091106
}
1110-
} catch (err) {
1111-
// If matching fails for this element, log and continue to the next
1112-
this.info(
1113-
`[matchAndTapImage] Matching failed for element ${i + 1}:`,
1114-
err instanceof Error ? err.message : err
1115-
);
1107+
} catch {
1108+
continue; // No match in this element, try next
11161109
}
11171110
}
11181111
// If no good match was found, throw an error
11191112
if (!bestMatch) {
1120-
throw new Error(
1113+
console.log(
11211114
`[matchAndTapImage] No matching image found among ${elements.length} elements for ${locator.strategy} "${locator.selector}"`
11221115
);
1116+
throw new Error('Unable to find the expected UI element on screen');
11231117
}
11241118
// Tap the best match found
11251119
this.info(

0 commit comments

Comments
 (0)