Skip to content
Merged
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
3 changes: 2 additions & 1 deletion lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -4428,7 +4428,8 @@ async function proceedSee(assertType, text, context, strict = false) {
description = `element ${locator.toString()}`
const els = await this._locate(locator)
assertElementExists(els, locator.toString())
allText = await Promise.all(els.map(el => el.innerText()))
allText = (await Promise.all(els.map(el => el.evaluateAll(nodes => nodes.map(node => node.innerText ?? node.textContent))))).flat()
assertElementExists(allText, locator.toString())
}

if (store?.currentStep?.opts?.ignoreCase === true) {
Expand Down
80 changes: 80 additions & 0 deletions test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,86 @@ describe('Playwright', function () {
})
})

describe('#see with context when a matched element is removed', () => {
let locatorProto
let originalAll

beforeEach(async () => {
await I.amOnPage('/form/field')
await I.executeScript(() => {
for (const text of ['old toast', 'new toast']) {
const el = document.createElement('div')
el.className = 'toast'
el.textContent = text
document.body.append(el)
}
})

locatorProto = Object.getPrototypeOf(page.locator('body'))
originalAll = locatorProto.all
locatorProto.all = async function () {
locatorProto.all = originalAll
const els = await originalAll.call(this)
await page.evaluate(() => document.querySelector('.toast')?.remove())
return els
}
page.setDefaultTimeout(10000)
})

afterEach(() => {
locatorProto.all = originalAll
page.setDefaultTimeout(I.options.timeout)
})

it('should see text in a remaining element without waiting for timeout', async () => {
const start = Date.now()
await I.see('new toast', '.toast')
expect(Date.now() - start).to.be.below(1000)
})

it('should not see text of the removed element without waiting for timeout', async () => {
const start = Date.now()
await I.dontSee('old toast', '.toast')
expect(Date.now() - start).to.be.below(1000)
})

it('should fail text equality check when every matched element is removed', async () => {
await I.executeScript(() => document.querySelectorAll('.toast')[1].remove())
const start = Date.now()
let error
try {
await I.seeTextEquals('old toast', '.toast')
} catch (err) {
error = err
}
expect(error?.message).to.include('was not found')
expect(Date.now() - start).to.be.below(1000)
})
})

describe('#see with context matching a non-HTML element', () => {
beforeEach(async () => {
await I.amOnPage('/form/field')
await I.executeScript(() => {
document.body.insertAdjacentHTML('beforeend', '<svg width="200" height="50"><text class="chart-label" x="5" y="20">chart label</text></svg>')
})
})

it('should see text of an SVG element', async () => {
await I.see('chart label', '.chart-label')
})

it('should fail to not see text of an SVG element', async () => {
let error
try {
await I.dontSee('chart label', '.chart-label')
} catch (err) {
error = err
}
expect(error).to.be.instanceOf(AssertionFailedError)
})
})

describe('check fields: #seeInField, #seeCheckboxIsChecked, ...', () => {
it('should throw error if field is not empty', () =>
I.amOnPage('/form/empty')
Expand Down
Loading