File tree 1 file changed +10
-9
lines changed
packages/page-objects/src/locators
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -621,15 +621,16 @@ export function fromText(locator?: By): (el: WebElement) => Promise<string> {
621
621
}
622
622
623
623
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
+ ) ;
633
634
let bestIdx : number = - 1 ;
634
635
for ( let i = 0 ; i < testElements . length ; i ++ ) {
635
636
if ( areas [ i ] < 0 ) {
You can’t perform that action at this time.
0 commit comments