UNPKG

3.03 kBTypeScriptView Raw
1/// <reference types="node" resolution-mode="require"/>
2import type { EventEmitter } from 'node:events';
3import type { Options, Capabilities, ThenArg } from '@wdio/types';
4import type { WebDriverBidiProtocol, ProtocolCommands } from '@wdio/protocols';
5import type { BidiHandler } from './bidi/handler.js';
6import type { EventData } from './bidi/localTypes.js';
7export interface JSONWPCommandError extends Error {
8 code?: string;
9 statusCode?: string;
10 statusMessage?: string;
11}
12export interface SessionFlags {
13 isW3C: boolean;
14 isChromium: boolean;
15 isFirefox: boolean;
16 isAndroid: boolean;
17 isMobile: boolean;
18 isIOS: boolean;
19 isSauce: boolean;
20 isSeleniumStandalone: boolean;
21 isDevTools: boolean;
22 isBidi: boolean;
23}
24type Fn = (...args: any) => any;
25type ValueOf<T> = T[keyof T];
26type ObtainMethods<T> = {
27 [Prop in keyof T]: T[Prop] extends Fn ? ThenArg<ReturnType<T[Prop]>> : never;
28};
29type WebDriverBidiCommands = typeof WebDriverBidiProtocol;
30export type BidiCommands = WebDriverBidiCommands[keyof WebDriverBidiCommands]['socket']['command'];
31export type BidiResponses = ValueOf<ObtainMethods<Pick<BidiHandler, BidiCommands>>>;
32type BidiInterface = ObtainMethods<Pick<BidiHandler, BidiCommands>>;
33type WebDriverClassicEvents = {
34 command: {
35 method: string;
36 endpoint: string;
37 body: any;
38 };
39 result: {
40 method: string;
41 endpoint: string;
42 body: any;
43 result: any;
44 };
45 'request.performance': {
46 durationMillisecond: number;
47 error: string;
48 request: any;
49 retryCount: number;
50 success: boolean;
51 };
52};
53export type BidiEventMap = {
54 [Event in keyof Omit<WebDriverBidiCommands, 'sendCommand' | 'sendAsyncCommand'>]: BidiInterface[WebDriverBidiCommands[Event]['socket']['command']];
55};
56type GetParam<T extends {
57 method: string;
58 params: any;
59}, U extends string> = T extends {
60 method: U;
61} ? T['params'] : never;
62type EventMap = {
63 [Event in EventData['method']]: GetParam<EventData, Event>;
64} & WebDriverClassicEvents;
65export interface BidiEventHandler {
66 on<K extends keyof EventMap>(event: K, listener: (this: Client, param: EventMap[K]) => void): this;
67 once<K extends keyof EventMap>(event: K, listener: (this: Client, param: EventMap[K]) => void): this;
68}
69export interface BaseClient extends EventEmitter, SessionFlags {
70 sessionId: string;
71 capabilities: Capabilities.DesiredCapabilities | Capabilities.W3CCapabilities;
72 requestedCapabilities: Capabilities.DesiredCapabilities | Capabilities.W3CCapabilities;
73 options: Options.WebDriver;
74}
75export interface Client extends Omit<BaseClient, keyof BidiEventHandler>, ProtocolCommands, BidiHandler, BidiEventHandler {
76}
77export interface AttachOptions extends Partial<SessionFlags>, Partial<Options.WebDriver> {
78 sessionId: string;
79 capabilities?: Capabilities.DesiredCapabilities | Capabilities.W3CCapabilities;
80 isW3C?: boolean;
81}
82export {};
83//# sourceMappingURL=types.d.ts.map
\No newline at end of file