Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(trace): avoid recording BindingCall actions (#35851)

Adam Gastineau854534cdfe99
diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts
index bdc36d3a6a..34d7b83980 100644
--- a/packages/playwright-core/src/client/page.ts
+++ b/packages/playwright-core/src/client/page.ts
@@ -846,6 +846,7 @@ export class BindingCall extends ChannelOwner<channels.BindingCallChannel> {
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BindingCallInitializer) {
super(parent, type, guid, initializer);
+ this.markAsInternalType();
}
async call(func: (source: structs.BindingSource, ...args: any[]) => any) {
diff --git a/tests/playwright-test/playwright.trace.spec.ts b/tests/playwright-test/playwright.trace.spec.ts
index 28a7150c8e..2315edc8c8 100644
--- a/tests/playwright-test/playwright.trace.spec.ts
+++ b/tests/playwright-test/playwright.trace.spec.ts
@@ -999,6 +999,48 @@ test('should record nested steps, even after timeout', async ({ runInlineTest },
]);
});
+test('should not produce an action entry for calling a binding', async ({ runInlineTest }, testInfo) => {
+ const result = await runInlineTest({
+ 'playwright.config.ts': `
+ module.exports = { use: { trace: 'on' } };
+ `,
+ 'a.spec.ts': `
+ import { test, expect } from '@playwright/test';
+ test('passes', async ({ page }) => {
+ let wasCalled = false;
+ await page.exposeBinding('customBinding', () => {
+ wasCalled = true;
+ return 'foo';
+ });
+
+ const output = await page.evaluate(() => window['customBinding']());
+ expect(wasCalled).toBe(true);
+ expect(output).toBe('foo');
+ });
+ `,
+ }, { workers: 1 });
+
+ expect(result.exitCode).toBe(0);
+ expect(result.passed).toBe(1);
+ const trace = await parseTrace(testInfo.outputPath('test-results', 'a-passes', 'trace.zip'));
+ expect(trace.actionTree).toEqual([
+ 'Before Hooks',
+ ' fixture: browser',
+ ' browserType.launch',
+ ' fixture: context',
+ ' browser.newContext',
+ ' fixture: page',
+ ' browserContext.newPage',
+ 'page.exposeBinding',
+ 'page.evaluate',
+ 'expect.toBe',
+ 'expect.toBe',
+ 'After Hooks',
+ ' fixture: page',
+ ' fixture: context',
+ ]);
+});
+
test('should attribute worker fixture teardown to the right test', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `