Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -3576,13 +3576,16 @@ class Playwright extends Helper {
const locator = new Locator(context, 'css')
try {
if (!locator.isXPath()) {
return contextObject
.locator(`${locator.simplify()} >> text=${text}`)
.first()
.waitFor({ timeout: waitTimeout, state: 'visible' })
.catch(e => {
throw new Error(errorMessage)
})
const deadline = Date.now() + waitTimeout
do {
const els = await this._locate(locator)
for (const el of els) {
const texts = await el.evaluateAll(nodes => nodes.map(node => node.innerText ?? node.textContent))
if (texts.some(t => typeof t === 'string' && t.includes(text))) return
}
await new Promise(resolve => setTimeout(resolve, 100))
} while (Date.now() < deadline)
throw new Error(errorMessage)
}

if (locator.isXPath()) {
Expand Down
5 changes: 5 additions & 0 deletions test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,11 @@ export function tests() {
await I.see('Dynamic text')
})

it('should wait for text in context with locator.at', async () => {
await I.amOnPage('/dynamic')
await I.waitForText('Dynamic text', 2, new Locator('#text').at(1))
})

it('should fail if no context', async function () {
let failed = false
await I.amOnPage('/dynamic')
Expand Down
Loading