@@ -2802,31 +2802,36 @@ class Playwright extends Helper {
28022802 }
28032803 }
28042804
2805- // Simple approach: use waitForFunction that checks all text sources
2806- // This handles both body text and title text in one strategy
2807- return contextObject
2808- . waitForFunction (
2809- text => {
2805+ // Based on original implementation but fixed to check title text and remove problematic promiseRetry
2806+ // Original used timeoutGap for waitForFunction to give it slightly more time than the locator
2807+ const timeoutGap = waitTimeout + 1000
2808+
2809+ return Promise . race ( [
2810+ // Strategy 1: waitForFunction that checks both body AND title text
2811+ // Original only checked document.body.innerText, missing title text like "TestEd"
2812+ contextObject . waitForFunction (
2813+ function ( text ) {
28102814 // Check body text (original behavior)
2811- if ( document . body && document . body . innerText . indexOf ( text ) > - 1 ) {
2815+ if ( document . body && document . body . innerText && document . body . innerText . indexOf ( text ) > - 1 ) {
28122816 return true
28132817 }
28142818 // Check document title (fixes the TestEd in title issue)
28152819 if ( document . title && document . title . indexOf ( text ) > - 1 ) {
28162820 return true
28172821 }
2818- // Also check document.documentElement.innerText which includes title
2819- if ( document . documentElement && document . documentElement . innerText . indexOf ( text ) > - 1 ) {
2820- return true
2821- }
28222822 return false
28232823 } ,
28242824 text ,
2825- { timeout : waitTimeout } ,
2826- )
2827- . catch ( err => {
2828- throw new Error ( errorMessage )
2829- } )
2825+ { timeout : timeoutGap } ,
2826+ ) ,
2827+ // Strategy 2: Native Playwright text locator (replaces problematic promiseRetry)
2828+ contextObject
2829+ . locator ( `:has-text(${ JSON . stringify ( text ) } )` )
2830+ . first ( )
2831+ . waitFor ( { timeout : waitTimeout } ) ,
2832+ ] ) . catch ( err => {
2833+ throw new Error ( errorMessage )
2834+ } )
28302835 }
28312836
28322837 /**
0 commit comments