UNPKG

3.35 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 isNativeContext: boolean;
20 mobileContext: string | undefined;
21 isIOS: boolean;
22 isSauce: boolean;
23 isSeleniumStandalone: boolean;
24 isBidi: boolean;
25}
26type Fn = (...args: unknown[]) => unknown;
27type ValueOf<T> = T[keyof T];
28type ObtainMethods<T> = {
29 [Prop in keyof T]: T[Prop] extends Fn ? ThenArg<ReturnType<T[Prop]>> : never;
30};
31type WebDriverBidiCommands = typeof WebDriverBidiProtocol;
32export type BidiCommands = WebDriverBidiCommands[keyof WebDriverBidiCommands]['socket']['command'];
33export type BidiResponses = ValueOf<ObtainMethods<Pick<BidiHandler, BidiCommands>>>;
34export type RemoteConfig = Options.WebDriver & Capabilities.WithRequestedCapabilities;
35type BidiInterface = ObtainMethods<Pick<BidiHandler, BidiCommands>>;
36type WebDriverClassicEvents = {
37 command: {
38 command: string;
39 method: string;
40 endpoint: string;
41 body: unknown;
42 };
43 result: {
44 command: string;
45 method: string;
46 endpoint: string;
47 body: unknown;
48 result: unknown;
49 };
50 bidiCommand: Omit<CommandData, 'id'>;
51 bidiResult: CommandResponse;
52 'request.performance': {
53 durationMillisecond: number;
54 error: string;
55 request: unknown;
56 retryCount: number;
57 success: boolean;
58 };
59};
60export type BidiEventMap = {
61 [Event in keyof Omit<WebDriverBidiCommands, 'sendCommand' | 'sendAsyncCommand'>]: BidiInterface[WebDriverBidiCommands[Event]['socket']['command']];
62};
63type GetParam<T extends {
64 method: string;
65 params: unknown;
66}, U extends string> = T extends {
67 method: U;
68} ? T['params'] : never;
69export type EventMap = {
70 [Event in EventData['method']]: GetParam<EventData, Event>;
71} & WebDriverClassicEvents;
72interface BidiEventHandler {
73 on<K extends keyof EventMap>(event: K, listener: (this: Client, param: EventMap[K]) => void): this;
74 once<K extends keyof EventMap>(event: K, listener: (this: Client, param: EventMap[K]) => void): this;
75}
76export interface BaseClient extends EventEmitter, SessionFlags {
77 sessionId: string;
78 capabilities: WebdriverIO.Capabilities;
79 requestedCapabilities: Capabilities.WithRequestedCapabilities['capabilities'];
80 options: Options.WebDriver;
81}
82export interface Client extends Omit<BaseClient, keyof BidiEventHandler>, ProtocolCommands, BidiHandler, BidiEventHandler {
83}
84export interface AttachOptions extends Partial<SessionFlags>, Partial<Options.WebDriver> {
85 sessionId: string;
86 capabilities?: WebdriverIO.Capabilities;
87 requestedCapabilities?: Capabilities.WithRequestedCapabilities['capabilities'];
88}
89export {};
90//# sourceMappingURL=types.d.ts.map
\No newline at end of file