UNPKG

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