Skip to content

Commit 10f97e6

Browse files
committed
Fix waitForText timeout regression by checking title text
1 parent 9339e5c commit 10f97e6

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/helper/Playwright.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,22 +2802,27 @@ class Playwright extends Helper {
28022802
}
28032803
}
28042804

2805-
// Use a simple Promise.race with two complementary strategies:
2806-
// 1. page.waitForFunction - checks entire document text content including title, body, etc.
2807-
// 2. contextObject.locator with :has-text - uses Playwright's native text matching
2808-
// Both approaches will wait for the full timeout duration
2805+
// Use two complementary strategies that both respect the full timeout:
2806+
// Strategy 1: waitForFunction checks body text AND title text
2807+
// Strategy 2: native Playwright locator for visible elements
28092808
return Promise.race([
2810-
// Strategy 1: Check entire document text content (including title)
2811-
this.page.waitForFunction(
2809+
// Strategy 1: Check both body text and title text (fixes original bug)
2810+
contextObject.waitForFunction(
28122811
text => {
2813-
// Check document text content - includes title and all visible text
2814-
const documentText = document.documentElement.innerText || document.documentElement.textContent || ''
2815-
return documentText.indexOf(text) > -1
2812+
// Check body text (original behavior)
2813+
if (document.body && document.body.innerText.indexOf(text) > -1) {
2814+
return true
2815+
}
2816+
// Also check document title (new addition to fix title text detection)
2817+
if (document.title && document.title.indexOf(text) > -1) {
2818+
return true
2819+
}
2820+
return false
28162821
},
28172822
text,
28182823
{ timeout: waitTimeout },
28192824
),
2820-
// Strategy 2: Use Playwright's native text locator
2825+
// Strategy 2: Use Playwright's native text locator for visible elements
28212826
contextObject
28222827
.locator(`:has-text(${JSON.stringify(text)})`)
28232828
.first()

0 commit comments

Comments
 (0)