@@ -2801,22 +2801,37 @@ class Playwright extends Helper {
28012801 // We apply 2 strategies here: wait for text as innert text on page (wide strategy) - older
28022802 // or we use native Playwright matcher to wait for text in element (narrow strategy) - newer
28032803 // 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 ( [
28052810 new Promise ( ( _ , reject ) => {
2806- setTimeout ( ( ) => reject ( errorMessage ) , waitTimeout )
2811+ timeoutId = setTimeout ( ( ) => reject ( errorMessage ) , waitTimeout )
28072812 } ) ,
28082813 this . page . waitForFunction ( text => document . body && document . body . innerText . indexOf ( text ) > - 1 , text , { timeout : timeoutGap } ) ,
28092814 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+ }
28112820 const textPresent = await contextObject
28122821 . locator ( `:has-text(${ JSON . stringify ( text ) } )` )
28132822 . first ( )
28142823 . isVisible ( )
28152824 if ( ! textPresent ) retry ( errorMessage )
28162825 } ,
2817- { retries : 1000 , minTimeout : 500 , maxTimeout : 500 , factor : 1 } ,
2826+ { retries : 10 , minTimeout : 100 , maxTimeout : 500 , factor : 1.5 } ,
28182827 ) ,
28192828 ] )
2829+
2830+ // Clean up when race resolves/rejects
2831+ return racePromise . finally ( ( ) => {
2832+ if ( timeoutId ) clearTimeout ( timeoutId )
2833+ shouldStop = true
2834+ } )
28202835 }
28212836
28222837 /**
0 commit comments