UNPKG

3.25 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';
6import type { CommandData } from './bidi/remoteTypes.js';
7import type { CommandResponse } from './bidi/localTypes.js';
8export interface JSONWPCommandError extends Error {
9 code?: string;
10 statusCode?: string;
11 statusMessage?: string;
12}
13export interface SessionFlags {
14 isW3C: boolean;
15 isChromium: boolean;
16 isFirefox: boolean;
17 isAndroid: boolean;
18 isMobile: boolean;
19 isIOS: boolean;
20 isSauce: boolean;
21 isSeleniumStandalone: 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>>>;
32export type RemoteConfig = Options.WebDriver & Capabilities.WithRequestedCapabilities;
33type BidiInterface = ObtainMethods<Pick<BidiHandler, BidiCommands>>;
34type WebDriverClassicEvents = {
35 command: {
36 command: string;
37 method: string;
38 endpoint: string;
39 body: any;
40 };
41 result: {
42 command: string;
43 method: string;
44 endpoint: string;
45 body: any;
46 result: any;
47 };
48 bidiCommand: Omit<CommandData, 'id'>;
49 bidiResult: CommandResponse;
50 'request.performance': {
51 durationMillisecond: number;
52 error: string;
53 request: any;
54 retryCount: number;
55 success: boolean;
56 };
57};
58export type BidiEventMap = {
59 [Event in keyof Omit<WebDriverBidiCommands, 'sendCommand' | 'sendAsyncCommand'>]: BidiInterface[WebDriverBidiCommands[Event]['socket']['command']];
60};
61type GetParam<T extends {
62 method: string;
63 params: any;
64}, U extends string> = T extends {
65 method: U;
66} ? T['params'] : never;
67export type EventMap = {
68 [Event in EventData['method']]: GetParam<EventData, Event>;
69} & WebDriverClassicEvents;
70interface BidiEventHandler {
71 on<K extends keyof EventMap>(event: K, listener: (this: Client, param: EventMap[K]) => void): this;
72 once<K extends keyof EventMap>(event: K, listener: (this: Client, param: EventMap[K]) => void): this;
73}
74export interface BaseClient extends EventEmitter, SessionFlags {
75 sessionId: string;
76 capabilities: WebdriverIO.Capabilities;
77 requestedCapabilities: Capabilities.WithRequestedCapabilities['capabilities'];
78 options: Options.WebDriver;
79}
80export interface Client extends Omit<BaseClient, keyof BidiEventHandler>, ProtocolCommands, BidiHandler, BidiEventHandler {
81}
82export interface AttachOptions extends Partial<SessionFlags>, Partial<Options.WebDriver> {
83 sessionId: string;
84 capabilities?: WebdriverIO.Capabilities;
85 requestedCapabilities?: Capabilities.WithRequestedCapabilities['capabilities'];
86}
87export {};
88//# sourceMappingURL=types.d.ts.map
\No newline at end of file