Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(logging): log the API calls (#464)
Pavel Feldmana8b9920a14f7
diff --git a/src/chromium/crConnection.ts b/src/chromium/crConnection.tsindex 02bd3ba489..a49a7a8177 100644--- a/src/chromium/crConnection.ts+++ b/src/chromium/crConnection.ts@@ -20,7 +20,7 @@ import { ConnectionTransport } from '../transport';import { assert } from '../helper';import { Protocol } from './protocol';-const debugProtocol = platform.debug('playwright:protocol');+const debugProtocol = platform.debug('pw:protocol');export const ConnectionEvents = {Disconnected: Symbol('ConnectionEvents.Disconnected')diff --git a/src/dom.ts b/src/dom.tsindex cc16cf659c..05a4ec04b7 100644--- a/src/dom.ts+++ b/src/dom.ts@@ -122,6 +122,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {constructor(context: FrameExecutionContext, remoteObject: any) {super(context, remoteObject);this._page = context.frame._page;+ return helper.logPublicApiCalls('handle', this);}asElement(): ElementHandle<T> | null {diff --git a/src/firefox/ffConnection.ts b/src/firefox/ffConnection.tsindex 354839fd30..301cbf19cf 100644--- a/src/firefox/ffConnection.ts+++ b/src/firefox/ffConnection.ts@@ -20,7 +20,7 @@ import * as platform from '../platform';import { ConnectionTransport } from '../transport';import { Protocol } from './protocol';-const debugProtocol = platform.debug('playwright:protocol');+const debugProtocol = platform.debug('pw:protocol');export const ConnectionEvents = {Disconnected: Symbol('Disconnected'),diff --git a/src/frames.ts b/src/frames.tsindex 15d30b9cf8..57c7e542fe 100644--- a/src/frames.ts+++ b/src/frames.ts@@ -293,6 +293,8 @@ export class Frame {if (this._parentFrame)this._parentFrame._childFrames.add(this);++ return helper.logPublicApiCalls('frame', this);}async goto(url: string, options?: GotoOptions): Promise<network.Response | null> {diff --git a/src/helper.ts b/src/helper.tsindex 89b5d0044a..2a1f1f52ad 100644--- a/src/helper.ts+++ b/src/helper.ts@@ -18,7 +18,7 @@import { TimeoutError } from './errors';import * as platform from './platform';-export const debugError = platform.debug(`playwright:error`);+export const debugError = platform.debug(`pw:error`);export type RegisteredListener = {emitter: platform.EventEmitterType;@@ -60,6 +60,26 @@ class Helper {}}+ static logPublicApiCalls(className: string, object: any): any {+ const log = platform.debug('pw:api');+ if (!log.enabled)+ return object;+ return new Proxy(object, {+ get(target, key: string) {+ const value = target[key];+ if (typeof key === 'string' && key.startsWith('_') || typeof value !== 'function')+ return value;+ return function(...args: any) {+ if (args.length)+ log(`${className}.${key} %o`, args);+ else+ log(`${className}.${key}`);+ return value.apply(this, args);+ };+ }+ });+ }+static addEventListener(emitter: platform.EventEmitterType,eventName: (string | symbol),diff --git a/src/javascript.ts b/src/javascript.tsindex 2d09043a88..02efdc272e 100644--- a/src/javascript.ts+++ b/src/javascript.ts@@ -16,6 +16,7 @@import * as types from './types';import * as dom from './dom';+import { helper } from './helper';export interface ExecutionContextDelegate {evaluate(context: ExecutionContext, returnByValue: boolean, pageFunction: string | Function, ...args: any[]): Promise<any>;@@ -57,6 +58,7 @@ export class JSHandle<T = any> {constructor(context: ExecutionContext, remoteObject: any) {this._context = context;this._remoteObject = remoteObject;+ return helper.logPublicApiCalls('handle', this);}evaluate: types.EvaluateOn<T> = (pageFunction, ...args) => {diff --git a/src/page.ts b/src/page.tsindex 6eecf2d823..5aaeb12c35 100644--- a/src/page.ts+++ b/src/page.ts@@ -137,6 +137,7 @@ export class Page extends platform.EventEmitter {if (delegate.pdf)this.pdf = delegate.pdf.bind(delegate);this.coverage = delegate.coverage();+ return helper.logPublicApiCalls('page', this);}_didClose() {@@ -537,7 +538,9 @@ export class Worker {constructor(url: string) {this._url = url;this._executionContextPromise = new Promise(x => this._executionContextCallback = x);+ return helper.logPublicApiCalls('worker', this);}+_createExecutionContext(delegate: js.ExecutionContextDelegate) {this._existingExecutionContext = new js.ExecutionContext(delegate);this._executionContextCallback(this._existingExecutionContext);diff --git a/src/webkit/wkConnection.ts b/src/webkit/wkConnection.tsindex 0de057614b..3556993c38 100644--- a/src/webkit/wkConnection.ts+++ b/src/webkit/wkConnection.ts@@ -20,8 +20,8 @@ import * as platform from '../platform';import { ConnectionTransport } from '../transport';import { Protocol } from './protocol';-const debugProtocol = platform.debug('playwright:protocol');-const debugWrappedMessage = platform.debug('wrapped');+const debugProtocol = platform.debug('pw:protocol');+const debugWrappedMessage = platform.debug('pw:wrapped');// WKBrowserServer uses this special id to issue Browser.close command which we// should ignore.