Skip to content

Commit 7303590

Browse files
Copilotkobenguyent
andauthored
Apply remaining changes
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent f259711 commit 7303590

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎lib/helper/Playwright.js‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,13 +3576,16 @@ class Playwright extends Helper {
35763576
const locator = new Locator(context, 'css')
35773577
try {
35783578
if (!locator.isXPath()) {
3579-
return contextObject
3580-
.locator(`${locator.simplify()} >> text=${text}`)
3581-
.first()
3582-
.waitFor({ timeout: waitTimeout, state: 'visible' })
3583-
.catch(e => {
3584-
throw new Error(errorMessage)
3585-
})
3579+
const deadline = Date.now() + waitTimeout
3580+
do {
3581+
const els = await this._locate(locator)
3582+
for (const el of els) {
3583+
const texts = await el.evaluateAll(nodes => nodes.map(node => node.innerText ?? node.textContent))
3584+
if (texts.some(t => typeof t === 'string' && t.includes(text))) return
3585+
}
3586+
await new Promise(resolve => setTimeout(resolve, 100))
3587+
} while (Date.now() < deadline)
3588+
throw new Error(errorMessage)
35863589
}
35873590

35883591
if (locator.isXPath()) {

‎test/helper/webapi.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,11 @@ export function tests() {
16781678
await I.see('Dynamic text')
16791679
})
16801680

1681+
it('should wait for text in context with locator.at', async () => {
1682+
await I.amOnPage('/dynamic')
1683+
await I.waitForText('Dynamic text', 2, new Locator('#text').at(1))
1684+
})
1685+
16811686
it('should fail if no context', async function () {
16821687
let failed = false
16831688
await I.amOnPage('/dynamic')

0 commit comments

Comments
 (0)