@@ -2801,22 +2801,37 @@ class Playwright extends Helper {
2801
2801
// We apply 2 strategies here: wait for text as innert text on page (wide strategy) - older
2802
2802
// or we use native Playwright matcher to wait for text in element (narrow strategy) - newer
2803
2803
// If a user waits for text on a page they are mostly expect it to be there, so wide strategy can be helpful even PW strategy is available
2804
- return Promise . race ( [
2804
+
2805
+ // Use a flag to stop retries when race resolves
2806
+ let shouldStop = false
2807
+ let timeoutId
2808
+
2809
+ const racePromise = Promise . race ( [
2805
2810
new Promise ( ( _ , reject ) => {
2806
- setTimeout ( ( ) => reject ( errorMessage ) , waitTimeout )
2811
+ timeoutId = setTimeout ( ( ) => reject ( errorMessage ) , waitTimeout )
2807
2812
} ) ,
2808
2813
this . page . waitForFunction ( text => document . body && document . body . innerText . indexOf ( text ) > - 1 , text , { timeout : timeoutGap } ) ,
2809
2814
promiseRetry (
2810
- async retry => {
2815
+ async ( retry , number ) => {
2816
+ // Stop retrying if race has resolved
2817
+ if ( shouldStop ) {
2818
+ throw new Error ( 'Operation cancelled' )
2819
+ }
2811
2820
const textPresent = await contextObject
2812
2821
. locator ( `:has-text(${ JSON . stringify ( text ) } )` )
2813
2822
. first ( )
2814
2823
. isVisible ( )
2815
2824
if ( ! textPresent ) retry ( errorMessage )
2816
2825
} ,
2817
- { retries : 1000 , minTimeout : 500 , maxTimeout : 500 , factor : 1 } ,
2826
+ { retries : 10 , minTimeout : 100 , maxTimeout : 500 , factor : 1.5 } ,
2818
2827
) ,
2819
2828
] )
2829
+
2830
+ // Clean up when race resolves/rejects
2831
+ return racePromise . finally ( ( ) => {
2832
+ if ( timeoutId ) clearTimeout ( timeoutId )
2833
+ shouldStop = true
2834
+ } )
2820
2835
}
2821
2836
2822
2837
/**
0 commit comments