Skip to content

Commit 56eb92a

Browse files
Skn0ttdgozman
andcommitted
cherry-pick(#36227): fix: java style selector string
Signed-off-by: Dmitry Gozman <[email protected]> Co-authored-by: Dmitry Gozman <[email protected]>
1 parent 1f643a3 commit 56eb92a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/playwright-core/src/server/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
8686
const customEngines: InjectedScriptOptions['customEngines'] = [];
8787
const selectorsRegistry = this.frame._page.browserContext.selectors();
8888
for (const [name, { source }] of selectorsRegistry._engines)
89-
customEngines.push({ name, source });
89+
customEngines.push({ name, source: `(${source})` });
9090
const sdkLanguage = this.frame.attribution.playwright.options.sdkLanguage;
9191
const options: InjectedScriptOptions = {
9292
isUnderTest: isUnderTest(),

tests/page/selectors-register.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,17 @@ it('isVisible should be atomic', async ({ playwright, page }) => {
128128
expect(result).toBe(true);
129129
expect(await page.evaluate(() => document.querySelector('div').style.display)).toBe('none');
130130
});
131+
132+
it('should take java-style string', async ({ playwright, page }) => {
133+
const createDummySelector = `{
134+
query(root, selector) {
135+
return root.querySelector(selector);
136+
},
137+
queryAll(root, selector) {
138+
return root.querySelectorAll(selector);
139+
}
140+
}`;
141+
await playwright.selectors.register('objectLiteral', createDummySelector);
142+
await page.setContent(`<div>Hello</div>`);
143+
await page.textContent('objectLiteral=div');
144+
});

0 commit comments

Comments
 (0)