Skip to content

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

fix: use logger from config if specified (#8697)

Yury Semikhatskye5e461c0de88
diff --git a/src/client/browserType.ts b/src/client/browserType.ts
index 084a831114..b16ba9d822 100644
--- a/src/client/browserType.ts
+++ b/src/client/browserType.ts
@@ -69,7 +69,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
}
async launch(options: LaunchOptions = {}): Promise<Browser> {
- const logger = options.logger;
+ const logger = options.logger || this._defaultLaunchOptions.logger;
return this._wrapApiCall(async (channel: channels.BrowserTypeChannel) => {
assert(!(options as any).userDataDir, 'userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
@@ -94,6 +94,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
}
async launchPersistentContext(userDataDir: string, options: LaunchPersistentContextOptions = {}): Promise<BrowserContext> {
+ const logger = options.logger || this._defaultLaunchOptions.logger;
return this._wrapApiCall(async (channel: channels.BrowserTypeChannel) => {
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
options = { ...this._defaultLaunchOptions, ...this._defaultContextOptions, ...options };
@@ -109,11 +110,11 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
const result = await channel.launchPersistentContext(persistentParams);
const context = BrowserContext.from(result.context);
context._options = contextParams;
- context._logger = options.logger;
+ context._logger = logger;
context._setBrowserType(this);
await this._onDidCreateContext?.(context);
return context;
- }, options.logger);
+ }, logger);
}
connect(options: api.ConnectOptions & { wsEndpoint?: string }): Promise<api.Browser>;
diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.ts
index 1cff43167d..d4cec95972 100644
--- a/tests/playwright-test/playwright.spec.ts
+++ b/tests/playwright-test/playwright.spec.ts
@@ -220,6 +220,34 @@ test('should respect context options in various contexts', async ({ runInlineTes
expect(result.passed).toBe(4);
});
+test('should call logger from launchOptions config', async ({ runInlineTest }, testInfo) => {
+ const result = await runInlineTest({
+ 'a.test.ts': `
+ const { test } = pwt;
+ const log = [];
+ test.use({
+ launchOptions: {
+ logger: {
+ log: (name, severity, message) => log.push({name, severity, message}),
+ isEnabled: (name, severity) => severity !== 'verbose'
+ }
+ }
+ });
+
+ test('should support config logger', async ({browser}) => {
+ expect(browser.version()).toBeTruthy();
+ expect(log.length > 0).toBeTruthy();
+ expect(log.filter(item => item.severity === 'info').length > 0).toBeTruthy();
+ expect(log.filter(item => item.message.includes('browserType.launch started')).length > 0).toBeTruthy();
+ expect(log.filter(item => item.message.includes('browserType.launch succeeded')).length > 0).toBeTruthy();
+ });
+ `,
+ }, { workers: 1 });
+
+ expect(result.exitCode).toBe(0);
+ expect(result.passed).toBe(1);
+});
+
test('should report error and pending operations on timeout', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'a.test.ts': `