Skip to content

Commit 743f603

Browse files
miraoclaude
andauthored
fix(playwright): replace constructor.name checks with stable public API (#5559) (#5560)
* fix(playwright): replace constructor.name checks with stable public API (#5559) Playwright 1.60 switched to an esbuild bundle which silently renames internal classes (e.g. Locator → _Locator), breaking all constructor.name checks. Replace them with duck-typing on stable public-API methods: Page/Frame expose url(), Locator exposes innerText(), FrameLocator exposes neither. Also adds a regression test that calls I.see() without an explicit context inside a CSS within() block — the exact path that timed out. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * ci: trigger GitHub Actions after base branch change --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 222f360 commit 743f603

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

lib/helper/Playwright.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ class Playwright extends Helper {
26832683
if (arg && typeof arg.evaluate === 'function' && typeof arg.locator === 'function') {
26842684
return arg.evaluate(fn)
26852685
}
2686-
if (this.context && this.context.constructor.name === 'FrameLocator') {
2686+
if (this.context && typeof this.context.url !== 'function' && typeof this.context.innerText !== 'function') {
26872687
return this.context.locator(':root').evaluate(fn, arg)
26882688
}
26892689
return this.page.evaluate.apply(this.page, [fn, arg])
@@ -3420,7 +3420,7 @@ class Playwright extends Helper {
34203420
}
34213421

34223422
async _getContext() {
3423-
if ((this.context && this.context.constructor.name === 'FrameLocator') || this.context) {
3423+
if (this.context) {
34243424
return this.context
34253425
}
34263426
if (this.frame) {
@@ -4359,7 +4359,9 @@ async function proceedSee(assertType, text, context, strict = false) {
43594359
if (!context) {
43604360
const el = await this.context
43614361

4362-
allText = el.constructor.name !== 'Locator' ? [await el.locator('body').innerText()] : [await el.innerText()]
4362+
allText = typeof el.url !== 'function' && typeof el.innerText === 'function'
4363+
? [await el.innerText()]
4364+
: [await el.locator('body').innerText()]
43634365

43644366
description = 'web application'
43654367
} else {

test/helper/webapi.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,13 @@ export function tests() {
16591659
if (!err) assert.fail('seen "Information"')
16601660
}
16611661
})
1662+
1663+
it('within on css locator should use locator scope in see without explicit context', async function () {
1664+
await I.amOnPage('/form/example4')
1665+
await I._withinBegin({ css: '#register' })
1666+
await I.see('E-Mail')
1667+
await I.dontSee('Toggle navigation')
1668+
})
16621669
})
16631670

16641671
describe('scroll: #scrollTo, #scrollPageToTop, #scrollPageToBottom', () => {

0 commit comments

Comments
 (0)