Skip to content

Commit 6c88fcb

Browse files
author
Michael Pollind
committed
improve locators logic
Signed-off-by: Michael Pollind <[email protected]>
1 parent 3d98694 commit 6c88fcb

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

packages/page-objects/src/locators/locators.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,16 @@ export function fromText(locator?: By): (el: WebElement) => Promise<string> {
621621
}
622622

623623
export async function findBestContainingElement(container: IRectangle, testElements: WebElement[]): Promise<WebElement | undefined> {
624-
let areas: number[] = [];
625-
for (let i = 0; i < testElements.length; i++) {
626-
const rect = await testElements[i].getRect();
627-
const ax = Math.max(container.x, rect.x);
628-
const ay = Math.max(container.y, rect.y);
629-
const bx = Math.min(container.x + container.width, rect.x + rect.width);
630-
const by = Math.min(container.y + container.height, rect.y + rect.height);
631-
areas.push((bx - ax) * (by - ay));
632-
}
624+
const areas: number[] = await Promise.all(
625+
testElements.map(async (value) => {
626+
const rect = await value.getRect();
627+
const ax = Math.max(container.x, rect.x);
628+
const ay = Math.max(container.y, rect.y);
629+
const bx = Math.min(container.x + container.width, rect.x + rect.width);
630+
const by = Math.min(container.y + container.height, rect.y + rect.height);
631+
return (bx - ax) * (by - ay);
632+
}),
633+
);
633634
let bestIdx: number = -1;
634635
for (let i = 0; i < testElements.length; i++) {
635636
if (areas[i] < 0) {

0 commit comments

Comments
 (0)