UNPKG

@wdio/devtools-service

Version:

A WebdriverIO service that allows you to run Chrome DevTools commands in your tests

109 lines 4.82 kB
import type { TraceEvent } from '@tracerbench/trace-event'; import type { CDPSession } from 'puppeteer-core/lib/esm/puppeteer/api/CDPSession.js'; import type { Page } from 'puppeteer-core/lib/esm/puppeteer/api/Page.js'; import type { RequestPayload } from './handler/network.js'; import type { DeviceOptions, DeviceDescription, DevtoolsConfig, EnablePerformanceAuditsOptions, GathererDriver, PWAAudits } from './types.js'; export default class CommandHandler { private _session; private _page; private _driver; private _options; private _browser; private _isTracing; private _networkHandler; private _traceEvents?; private _shouldRunPerformanceAudits; private _cacheEnabled?; private _cpuThrottling?; private _networkThrottling?; private _formFactor?; private _traceGatherer?; private _devtoolsGatherer?; private _coverageGatherer?; private _pwaGatherer?; constructor(_session: CDPSession, _page: Page, _driver: GathererDriver, _options: DevtoolsConfig, _browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser); /** * The cdp command is a custom command added to the browser scope that allows you * to call directly commands to the protocol. */ cdp(domain: string, command: string, args?: {}): Promise<any>; /** * Helper method to get the nodeId of an element in the page. * NodeIds are similar like WebDriver node ids an identifier for a node. * It can be used as a parameter for other Chrome DevTools methods, e.g. DOM.focus. */ getNodeId(selector: string): Promise<number>; /** * Helper method to get the nodeId of an element in the page. * NodeIds are similar like WebDriver node ids an identifier for a node. * It can be used as a parameter for other Chrome DevTools methods, e.g. DOM.focus. */ getNodeIds(selector: string): Promise<number[]>; /** * Start tracing the browser. You can optionally pass in custom tracing categories and the * sampling frequency. */ startTracing({ categories, path, screenshots }?: any): Promise<void>; /** * Stop tracing the browser. */ endTracing(): Promise<TraceEvent[] | undefined>; /** * Returns the tracelogs that was captured within the tracing period. * You can use this command to store the trace logs on the file system to analyse the trace * via Chrome DevTools interface. */ getTraceLogs(): TraceEvent[] | undefined; /** * Returns page weight information of the last page load. */ getPageWeight(): { pageWeight: number; transferred: number; requestCount: number; details: { Document?: RequestPayload | undefined; Stylesheet?: RequestPayload | undefined; Image?: RequestPayload | undefined; Media?: RequestPayload | undefined; Font?: RequestPayload | undefined; Script?: RequestPayload | undefined; TextTrack?: RequestPayload | undefined; XHR?: RequestPayload | undefined; Fetch?: RequestPayload | undefined; Prefetch?: RequestPayload | undefined; EventSource?: RequestPayload | undefined; WebSocket?: RequestPayload | undefined; Manifest?: RequestPayload | undefined; SignedExchange?: RequestPayload | undefined; Ping?: RequestPayload | undefined; CSPViolationReport?: RequestPayload | undefined; Preflight?: RequestPayload | undefined; Other?: RequestPayload | undefined; }; }; /** * set flag to run performance audits for page transitions */ enablePerformanceAudits({ networkThrottling, cpuThrottling, cacheEnabled, formFactor }?: EnablePerformanceAuditsOptions): void; /** * custom command to disable performance audits */ disablePerformanceAudits(): void; /** * set device emulation */ emulateDevice(device: string | DeviceDescription, deviceOptions?: DeviceOptions): Promise<void>; /** * helper method to set throttling profile */ setThrottlingProfile(networkThrottling?: "online" | "offline" | "GPRS" | "Regular 2G" | "Good 2G" | "Regular 3G" | "Good 3G" | "Regular 4G" | "DSL" | "Wifi", cpuThrottling?: number, cacheEnabled?: boolean): Promise<void>; checkPWA(auditsToBeRun?: PWAAudits[]): Promise<import("./types.js").AuditResult>; getCoverageReport(): Promise<import("./types.js").Coverage | null>; _logCoverage(): Promise<void>; private _propagateWSEvents; _initCommand(): Promise<void>; _beforeCmd(commandName: string, params: any[]): Promise<void> | undefined; _afterCmd(commandName: string): Promise<void> | undefined; } //# sourceMappingURL=commands.d.ts.map