testplane
Version:
Tests framework based on mocha and wdio
80 lines • 3.4 kB
JavaScript
"use strict";
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");
const network_1 = require("./domains/network");
const fetch_1 = require("./domains/fetch");
const page_1 = require("./domains/page");
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.network = new network_1.CDPNetwork(connection);
this.fetch = new fetch_1.CDFetch(connection);
this.page = new page_1.CDPPage(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, cdpEventMessage.sessionId);
break;
case "Profiler":
this.profiler.emit(method, cdpEventMessage.params, cdpEventMessage.sessionId);
break;
case "Debugger":
this.debugger.emit(method, cdpEventMessage.params, cdpEventMessage.sessionId);
break;
case "Runtime":
this.runtime.emit(method, cdpEventMessage.params, cdpEventMessage.sessionId);
break;
case "DOM":
this.dom.emit(method, cdpEventMessage.params, cdpEventMessage.sessionId);
break;
case "CSS":
this.css.emit(method, cdpEventMessage.params, cdpEventMessage.sessionId);
break;
case "Network":
this.network.emit(method, cdpEventMessage.params, cdpEventMessage.sessionId);
break;
case "Fetch":
this.fetch.emit(method, cdpEventMessage.params, cdpEventMessage.sessionId);
break;
case "Page":
this.page.emit(method, cdpEventMessage.params, cdpEventMessage.sessionId);
break;
}
}
}
exports.CDP = CDP;
//# sourceMappingURL=index.js.map