testplane
Version:
Tests framework based on mocha and wdio
65 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CDP = void 0;
const connection_1 = require("./connection");
const target_1 = require("./domains/target");
const profiler_1 = require("./domains/profiler");
const debugger_1 = require("./domains/debugger");
const runtime_1 = require("./domains/runtime");
const dom_1 = require("./domains/dom");
const css_1 = require("./domains/css");
class CDP {
static async create(browser) {
// "isChrome" is "true" when automationProtocol is "devtools"
const isChromiumLike = browser.publicAPI.isChromium || browser.publicAPI.isChrome;
if (!isChromiumLike) {
return null;
}
const connection = await connection_1.CDPConnection.create(browser).catch(() => null);
return connection ? new this(connection) : null;
}
constructor(connection) {
this._connection = connection;
this.target = new target_1.CDPTarget(connection);
this.profiler = new profiler_1.CDPProfiler(connection);
this.debugger = new debugger_1.CDPDebugger(connection);
this.runtime = new runtime_1.CDPRuntime(connection);
this.dom = new dom_1.CDPDom(connection);
this.css = new css_1.CDPCss(connection);
this._connection.onEventMessage = this._onEventMessage.bind(this);
}
async request(method, params, cdpSessionId) {
return this._connection.request(method, {
params: params ?? undefined,
sessionId: cdpSessionId ?? undefined,
});
}
close() {
this._connection.close();
}
_onEventMessage(cdpEventMessage) {
const [domain, method] = cdpEventMessage.method.split(".", 2);
switch (domain) {
case "Target":
this.target.emit(method, cdpEventMessage.params);
break;
case "Profiler":
this.profiler.emit(method, cdpEventMessage.params);
break;
case "Debugger":
this.debugger.emit(method, cdpEventMessage.params);
break;
case "Runtime":
this.runtime.emit(method, cdpEventMessage.params);
break;
case "DOM":
this.dom.emit(method, cdpEventMessage.params);
break;
case "CSS":
this.css.emit(method, cdpEventMessage.params);
break;
}
}
}
exports.CDP = CDP;
//# sourceMappingURL=index.js.map