@appium/types 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.ts CHANGED
@@ -1,348 +1,112 @@
1
- import type { Method as _Method } from 'axios';
2
- import type { EventEmitter } from 'events';
3
- import type { Server } from 'http';
4
- import type { Logger } from 'npmlog';
5
- import type { Class as _Class, MultidimensionalReadonlyArray } from 'type-fest';
6
- import { ServerArgs } from './config';
7
- import { Capabilities, W3CCapabilities } from './capabilities';
8
-
9
- export { AppiumW3CCapabilities } from './capabilities';
10
- export { AppiumConfig, NormalizedAppiumConfig } from './config';
1
+ import type {Server as WSServer} from 'ws';
2
+ import type {Socket} from 'net';
3
+ import type {Server} from 'http';
4
+ import type {Class as _Class, ConditionalPick, MultidimensionalReadonlyArray} from 'type-fest';
5
+ import {ServerArgs} from './config';
6
+ import {Capabilities, W3CCapabilities} from './capabilities';
7
+ import type {Express} from 'express';
8
+ import {ExternalDriver} from './driver';
9
+ import type {Logger} from 'npmlog';
10
+
11
+ export * from './driver';
12
+ export * from './plugin';
13
+ export {AppiumW3CCapabilities} from './capabilities';
14
+ export {AppiumConfig, NormalizedAppiumConfig} from './config';
11
15
  export * from './appium-config';
12
- export { ServerArgs, Capabilities, W3CCapabilities };
16
+ export {ServerArgs, Capabilities, W3CCapabilities};
13
17
 
14
18
  /**
15
- * Methods and properties which both `AppiumDriver` and `BaseDriver` inherit.
19
+ * A log prefix for {@linkcode AppiumLogger}
20
+ *
21
+ * If a function, the function will return the prefix. Log messages will be prefixed with this value.
16
22
  */
17
- export interface Core {
18
- sessionId: string | null;
19
- opts: ServerArgs;
20
- initialOpts: ServerArgs;
21
- caps?: Capabilities;
22
- originalCaps?: W3CCapabilities;
23
- protocol?: string;
24
- helpers: DriverHelpers;
25
- basePath: string;
26
- relaxedSecurityEnabled: boolean;
27
- allowInsecure: string[];
28
- denyInsecure: string[];
29
- newCommandTimeoutMs: number;
30
- implicitWaitMs: number;
31
- locatorStrategies: string[];
32
- webLocatorStrategies: string[];
33
- eventEmitter: EventEmitter;
34
- settings: DeviceSettings;
35
- log: AppiumLogger;
36
- driverData?: DriverData;
37
- isCommandsQueueEnabled: boolean;
38
- eventHistory: EventHistory;
39
- desiredCapConstraints: Constraints;
40
- onUnexpectedShutdown(handler: () => any): void;
41
- getStatus(): Promise<unknown>;
42
- logExtraCaps(caps: Capabilities): void;
43
- sessionExists(sessionId: string): boolean;
44
- validateDesiredCaps(caps: Capabilities): boolean;
45
- isW3CProtocol(): boolean;
46
- isMjsonwpProtocol(): boolean;
47
- isFeatureEnabled(name: string): boolean;
48
- ensureFeatureEnabled(name: string): void;
49
- validateLocatorStrategy(strategy: string, webContext?: boolean): void;
50
- proxyActive(sessionId?: string): boolean;
51
- getProxyAvoidList(sessionId?: string): [string, RegExp][];
52
- canProxy(sessionId?: string): boolean;
53
- proxyRouteIsAvoided(sessionId: string, method: string, url: string): boolean;
54
- addManagedDriver(driver: Driver): void;
55
- getManagedDrivers(): Driver[];
56
- clearNewCommandTimeout(): Promise<void>;
57
- logEvent(eventName: string): void;
58
- }
23
+ export type AppiumLoggerPrefix = string | (() => string);
59
24
 
60
- export interface Driver
61
- extends SessionCommands,
62
- LogCommands,
63
- FindCommands,
64
- SettingsCommands,
65
- TimeoutCommands,
66
- EventCommands,
67
- SessionHandler<[string, any], void>,
68
- Core {
69
- // The following methods are implemented by `BaseDriver`.
70
- executeCommand(cmd: string, ...args: any[]): Promise<any>;
71
- startUnexpectedShutdown(err?: Error): Promise<void>;
72
- startNewCommandTimeout(): Promise<void>;
73
- reset(): Promise<void>;
25
+ /**
26
+ * Possible "log levels" for {@linkcode AppiumLogger}.
27
+ *
28
+ * Extracted from `npmlog`.
29
+ */
30
+ export type AppiumLoggerLevel = 'silly' | 'verbose' | 'debug' | 'info' | 'http' | 'warn' | 'error';
74
31
 
75
- assignServer?(
76
- server: AppiumServer,
77
- host: string,
78
- port: number,
79
- path: string,
80
- ): void;
32
+ /**
33
+ * Describes the `npmlog`-based internal logger.
34
+ *
35
+ * @see https://npm.im/npmlog
36
+ */
37
+ export interface AppiumLogger {
38
+ /**
39
+ * Returns the underlying `npmlog` {@link Logger}.
40
+ */
41
+ unwrap(): Logger;
42
+ level: AppiumLoggerLevel;
43
+ levels: AppiumLoggerLevel[];
44
+ /**
45
+ * Log prefix, if applicable.
46
+ */
47
+ prefix?: AppiumLoggerPrefix;
48
+ debug(...args: any[]): void;
49
+ info(...args: any[]): void;
50
+ warn(...args: any[]): void;
51
+ error(...args: any[]): void;
52
+ verbose(...args: any[]): void;
53
+ silly(...args: any[]): void;
54
+ http(...args: any[]): void;
55
+ errorAndThrow(...args: any[]): never;
81
56
  }
82
57
 
83
58
  /**
84
- * External drivers must subclass `BaseDriver`, and can implement any of these methods.
85
- * None of these are implemented within Appium itself.
59
+ * Appium's slightly-modified {@linkcode Server http.Server}.
86
60
  */
87
- export interface ExternalDriver extends Driver {
88
- // The following properties are assigned by appium */
89
- readonly server: AppiumServer;
90
- readonly serverHost: string;
91
- readonly serverPort: number;
92
- readonly serverPath: string;
93
-
94
- // WebDriver
95
- setUrl?(url: string): Promise<void>;
96
- getUrl?(): Promise<string>;
97
- back?(): Promise<void>;
98
- forward?(): Promise<void>;
99
- refresh?(): Promise<void>;
100
- title?(): Promise<string>;
101
- getWindowHandle?(): Promise<string>;
102
- closeWindow?(): Promise<string[]>;
103
- setWindow?(handle: string): Promise<void>;
104
- getWindowHandles?(): Promise<string[]>;
105
- setFrame?(id: null | number | string): Promise<void>;
106
- getWindowRect?(): Promise<Rect>;
107
- setWindowRect?(
108
- x: number,
109
- y: number,
110
- width: number,
111
- height: number,
112
- ): Promise<Rect>;
113
- maximizeWindow?(): Promise<Rect>;
114
- minimizeWindow?(): Promise<Rect>;
115
- fullScreenWindow?(): Promise<Rect>;
116
- createNewWindow?(type?: NewWindowType): Promise<NewWindow>;
117
- active?(): Promise<Element>;
118
- elementSelected?(elementId: string): Promise<boolean>;
119
- getAttribute?(name: string, elementId: string): Promise<string | null>;
120
- getProperty?(name: string, elementId: string): Promise<string | null>;
121
- getCssProperty?(name: string, elementId: string): Promise<string>;
122
- getText?(elementId: string): Promise<string>;
123
- getName?(elementId: string): Promise<string>;
124
- getElementRect?(elementId: string): Promise<Rect>;
125
- elementEnabled?(elementId: string): Promise<boolean>;
126
- elementDisplayed?(elementId: string): Promise<boolean>;
127
- click?(elementId: string): Promise<void>;
128
- clear?(elementId: string): Promise<void>;
129
- setValue?(text: string, elementId: string): Promise<void>;
130
- execute?(script: string, args: unknown[]): Promise<unknown>;
131
- executeAsync?(script: string, args: unknown[]): Promise<unknown>;
132
- getCookies?(): Promise<Cookie[]>;
133
- getCookie?(name: string): Promise<Cookie>;
134
- setCookie?(cookie: Cookie): Promise<void>;
135
- deleteCookie?(name: string): Promise<void>;
136
- deleteCookies?(): Promise<void>;
137
- performActions?(actions: Actions[]): Promise<void>;
138
- releaseActions?(): Promise<void>;
139
- postDismissAlert?(): Promise<void>;
140
- postAcceptAlert?(): Promise<void>;
141
- getAlertText?(): Promise<string | null>;
142
- setAlertText?(text: string): Promise<void>;
143
- getScreenshot?(): Promise<string>;
144
- getElementScreenshot?(elementId: string): Promise<string>;
61
+ export type AppiumServer = Omit<Server, 'close'> & AppiumServerExtension;
145
62
 
146
- // Appium W3C WebDriver Extension
147
- mobileShake?(): Promise<void>;
148
- getDeviceTime?(format?: string): Promise<string>;
149
- lock?(seconds?: number): Promise<void>;
150
- unlock?(): Promise<void>;
151
- isLocked?(): Promise<boolean>;
152
- startRecordingScreen?(options?: ScreenRecordOptions): Promise<void>;
153
- stopRecordingScreen?(options?: ScreenRecordOptions): Promise<string>;
154
- getPerformanceDataTypes?(): Promise<string[]>;
155
- getPerformanceData?(
156
- packageName: string,
157
- dataType: string,
158
- dataReadTimeout?: number,
159
- ): Promise<string[]>;
160
- pressKeyCode?(
161
- keycode: number,
162
- metastate?: number,
163
- flags?: number,
164
- ): Promise<void>;
165
- longPressKeyCode?(
166
- keycode: number,
167
- metastate?: number,
168
- flags?: number,
169
- ): Promise<void>;
170
- fingerprint?(fingerprintId: number): Promise<void>;
171
- sendSMS?(phoneNumber: string, message: string): Promise<void>;
172
- gsmCall?(phoneNumber: string, action: string): Promise<void>;
173
- gsmSignal?(signalStrength: string): Promise<void>;
174
- gsmVoice?(state: string): Promise<void>;
175
- powerCapacity?(percent: number): Promise<void>;
176
- powerAC?(state: string): Promise<void>;
177
- networkSpeed?(netspeed: string): Promise<void>;
178
- keyevent?(keycode: string, metastate?: string): Promise<void>;
179
- mobileRotation?(
180
- x: number,
181
- y: number,
182
- radius: number,
183
- rotation: number,
184
- touchCount: number,
185
- duration: string,
186
- elementId?: string,
187
- ): Promise<void>;
188
- getCurrentActivity?(): Promise<string>;
189
- getCurrentPackage?(): Promise<string>;
190
- installApp?(appPath: string, options?: unknown): Promise<void>;
191
- activateApp?(appId: string, options?: unknown): Promise<void>;
192
- removeApp?(appId: string, options?: unknown): Promise<void>;
193
- terminateApp?(appId: string, options?: unknown): Promise<void>;
194
- isAppInstalled?(appId: string): Promise<boolean>;
195
- queryAppState?(appId: string): Promise<number>;
196
- hideKeyboard?(
197
- strategy?: string,
198
- key?: string,
199
- keyCode?: string,
200
- keyName?: string,
201
- ): Promise<void>;
202
- isKeyboardShown?(): Promise<boolean>;
203
- pushFile?(path: string, data: string): Promise<void>;
204
- pullFile?(path: string): Promise<string>;
205
- pullFolder?(path: string): Promise<string>;
206
- toggleFlightMode?(): Promise<void>;
207
- toggleData?(): Promise<void>;
208
- toggleWiFi?(): Promise<void>;
209
- toggleLocationServices?(): Promise<void>;
210
- openNotifications?(): Promise<void>;
211
- startActivity?(
212
- appPackage: string,
213
- appActivity: string,
214
- appWaitPackage?: string,
215
- appWaitActivity?: string,
216
- intentAction?: string,
217
- intentCategory?: string,
218
- intentFlags?: string,
219
- optionalIntentArguments?: string,
220
- dontStopAppOnReset?: boolean,
63
+ export interface AppiumServerExtension {
64
+ close(): Promise<void>;
65
+ addWebSocketHandler(
66
+ handlerPathname: string,
67
+ handlerServer: WSServer
221
68
  ): Promise<void>;
222
- getSystemBars?(): Promise<unknown[]>;
223
- getDisplayDensity?(): Promise<number>;
224
- touchId?(match: boolean): Promise<void>;
225
- toggleEnrollTouchId?(enabled: boolean): Promise<void>;
226
- launchApp?(): Promise<void>;
227
- closeApp?(): Promise<void>;
228
- background?(seconds: null | number): Promise<void>;
229
- endCoverage?(intent: string, path: string): Promise<void>;
230
- getStrings?(
231
- language?: string,
232
- stringFile?: string,
233
- ): Promise<Record<string, unknown>>;
234
- setValueImmediate?(value: string, elementId: string): Promise<void>;
235
- replaceValue?(value: string, elementId: string): Promise<void>;
236
- receiveAsyncResponse?(response: unknown): Promise<void>;
237
- setClipboard?(
238
- content: string,
239
- contentType?: string,
240
- label?: string,
241
- ): Promise<void>;
242
- getClipboard?(contentType?: string): Promise<string>;
243
-
244
- // JSONWP
245
- asyncScriptTimeout?(ms: number): Promise<void>;
246
- getWindowSize?(): Promise<Size>;
247
- getLocation?(elementId: string): Promise<Position>;
248
- getLocationInView?(elementId: string): Promise<Position>;
249
- getSize?(elementId: string): Promise<Size>;
250
- elementShadowRoot?(elementId: string): Promise<Element>;
251
- findElementFromShadowRoot?(
252
- strategy: string,
253
- selector: string,
254
- shadowId: string
255
- ): Promise<Element>;
256
- findElementsFromShadowRoot?(
257
- strategy: string,
258
- selector: string,
259
- shadowId: string
260
- ): Promise<Element[]>;
261
- equalsElement?(elementId: string, otherElementId: string): Promise<boolean>;
262
- submit?(elementId: string): Promise<void>;
263
- keys?(value: string[]): Promise<void>;
264
- availableIMEEngines?(): Promise<string[]>;
265
- getActiveIMEEngine?(): Promise<string>;
266
- isIMEActivated?(): Promise<boolean>;
267
- deactivateIMEEngine?(): Promise<void>;
268
- activateIMEEngine?(engine: string): Promise<void>;
269
- getOrientation?(): Promise<string>;
270
- setOrientation?(orientation: string): Promise<void>;
271
- moveTo?(
272
- element?: null | string,
273
- xOffset?: number,
274
- yOffset?: number,
275
- ): Promise<void>;
276
- buttonDown?(button?: number): Promise<void>;
277
- buttonUp?(button?: number): Promise<void>;
278
- clickCurrent?(button?: number): Promise<void>;
279
- doubleClick?(): Promise<void>;
280
- touchDown?(x: number, y: number): Promise<void>;
281
- touchUp?(x: number, y: number): Promise<void>;
282
- touchMove?(x: number, y: number): Promise<void>;
283
- touchLongClick?(elementId: string): Promise<void>;
284
- flick?(
285
- element?: string,
286
- xSpeed?: number,
287
- ySpeed?: number,
288
- xOffset?: number,
289
- yOffset?: number,
290
- speed?: number,
291
- ): Promise<void>;
292
- getGeoLocation?(): Promise<Location>;
293
- setGeoLocation?(location: Partial<Location>): Promise<void>;
294
-
295
- // MJSONWIRE
296
- getCurrentContext?(): Promise<string | null>;
297
- setContext?(name: string): Promise<void>;
298
- getContexts?(): Promise<string[]>;
299
- getPageIndex?(elementId: string): Promise<string>;
300
- getNetworkConnection?(): Promise<number>;
301
- setNetworkConnection?(type: number): Promise<void>;
302
- performTouch?(actions: unknown): Promise<void>;
303
- performMultiAction?(actions: unknown, elementId: string): Promise<void>;
304
- getRotation?(): Promise<Rotation>;
305
- setRotation?(x: number, y: number, z: number): Promise<void>;
306
-
307
- // Chromium DevTools
308
- executeCdp?(cmd: string, params: unknown): Promise<unknown>;
309
-
310
- // Web Authentication
311
- addVirtualAuthenticator?(
312
- protocol: string,
313
- transport: string,
314
- hasResidentKey?: boolean,
315
- hasUserVerification?: boolean,
316
- isUserConsenting?: boolean,
317
- isUserVerified?: boolean,
318
- ): Promise<void>;
319
- removeVirtualAuthenticator?(): Promise<void>;
320
- addAuthCredential?(
321
- credentialId: string,
322
- isResidentCredential: boolean,
323
- rpId: string,
324
- privateKey: string,
325
- userHandle?: string,
326
- signCount?: number,
327
- ): Promise<void>;
328
- getAuthCredential?(): Promise<Credential[]>;
329
- removeAllAuthCredentials?(): Promise<void>;
330
- removeAuthCredential?(): Promise<void>;
331
- setUserAuthVerified?(isUserVerified: boolean): Promise<void>;
69
+ removeWebSocketHandler(handlerPathname: string): Promise<boolean>;
70
+ removeAllWebSocketHandlers(): Promise<boolean>;
71
+ getWebSocketHandlers(
72
+ keysFilter: string | null | undefined
73
+ ): Promise<Record<string, WSServer>>;
74
+ webSocketsMapping: Record<string, WSServer>;
75
+ }
332
76
 
333
- proxyCommand?(
334
- url: string,
335
- method: HTTPMethod,
336
- body?: string,
337
- ): Promise<unknown>;
77
+ export interface AppiumServerSocket extends Socket {
78
+ _openReqCount: number;
338
79
  }
339
80
 
340
- export interface Method<T extends ExternalDriver = ExternalDriver> {
341
- command?: keyof T; // T[keyof T] needs to return a Promise.
81
+ /**
82
+ * The definition of an extension method, which will be provided via Appium's API.
83
+ *
84
+ */
85
+ export interface Method<T> {
86
+ /**
87
+ * Name of the command.
88
+ */
89
+ command?: keyof ConditionalPick<Required<T>, DriverCommand>;
90
+ /**
91
+ * If true, this `Method` will never proxy.
92
+ */
342
93
  neverProxy?: boolean;
94
+ /**
95
+ * Specifies shape of payload
96
+ */
343
97
  payloadParams?: PayloadParams;
344
98
  }
345
99
 
100
+ /**
101
+ * An instance method of a driver class, whose name may be referenced by {@linkcode Method.command}, and serves as an Appium command.
102
+ *
103
+ * Note that this signature differs from a `PluginCommand`.
104
+ */
105
+ export type DriverCommand<TArgs = any, TRetval = unknown> = (...args: TArgs[]) => Promise<TRetval>;
106
+
107
+ /**
108
+ * Defines the shape of a payload for a {@linkcode Method}.
109
+ */
346
110
  export interface PayloadParams {
347
111
  wrap?: string;
348
112
  unwrap?: string;
@@ -351,282 +115,15 @@ export interface PayloadParams {
351
115
  validate?: (obj: any, protocol: string) => boolean | string | undefined;
352
116
  makeArgs?: (obj: any) => any;
353
117
  }
354
-
355
- export type MethodMap<T extends ExternalDriver = ExternalDriver> = Record<string, Record<string, Method<T>>>;
356
-
357
- export interface Constraint {
358
- presence?: boolean | {allowEmpty: boolean};
359
- isString?: boolean;
360
- isNumber?: boolean;
361
- isBoolean?: boolean;
362
- isObject?: boolean;
363
- isArray?: boolean;
364
- deprecated?: boolean;
365
- inclusion?: any[];
366
- }
367
- export type Constraints = Record<string, Constraint>;
368
-
369
- export interface Element {
370
- 'element-6066-11e4-a52e-4f735466cecf': string;
371
- }
372
-
373
- export interface DriverHelpers {
374
- configureApp: (
375
- app: string,
376
- supportedAppExtensions: string[],
377
- ) => Promise<string>;
378
- isPackageOrBundle: (app: string) => boolean;
379
- duplicateKeys: <T>(input: T, firstKey: string, secondKey: string) => T;
380
- parseCapsArray: (cap: string | string[]) => string[];
381
- generateDriverLogPrefix: (obj: Core, sessionId?: string) => string;
382
- }
383
-
384
- export type SettingsUpdateListener<
385
- T extends Record<string, unknown> = Record<string, unknown>,
386
- > = (prop: keyof T, newValue: unknown, curValue: unknown) => Promise<void>;
387
-
388
- export interface DeviceSettings<
389
- T extends Record<string, unknown> = Record<string, unknown>,
390
- > {
391
- update(newSettings: T): Promise<void>;
392
- getSettings(): T;
393
- }
394
-
395
- export interface LogType<TDriver, LogEntry = string> {
396
- description: string;
397
- getter: (driver: TDriver) => Promise<LogEntry[]>;
398
- }
399
-
400
- // WebDriver
401
-
402
- export interface Rect {
403
- x: number;
404
- y: number;
405
- width: number;
406
- height: number;
407
- }
408
-
409
- export type NewWindowType = 'tab' | 'window';
410
-
411
- export interface NewWindow {
412
- handle: string;
413
- type: NewWindowType;
414
- }
415
-
416
- export interface Cookie {
417
- name: string;
418
- value: string;
419
- path?: string;
420
- domain?: string;
421
- secure?: boolean;
422
- httpOnly?: boolean;
423
- expiry?: number;
424
- sameSite?: 'Lax' | 'Strict';
425
- }
426
-
427
- export interface Actions {
428
- type?: string;
429
- actions: Action[];
430
- parameters?: {
431
- pointerType?: string;
432
- };
433
- }
434
-
435
- export interface Action {
436
- duration?: number;
437
- type: string;
438
- value?: string;
439
- x?: number;
440
- y?: number;
441
- button?: number;
442
- origin?: string;
443
- }
444
-
445
- // Appium W3C WebDriver Extension
446
-
447
- export interface ScreenRecordOptions {
448
- remotePath?: string;
449
- username?: string;
450
- password?: string;
451
- method?: string;
452
- forceRestart?: boolean;
453
- timeLimit?: string;
454
- videoType?: string;
455
- videoQuality?: string;
456
- videoFps?: string;
457
- videoScale?: string;
458
- bitRate?: string;
459
- videoSize?: string;
460
- bugReport?: string;
461
- }
462
-
463
- // JSONWP
464
-
465
- export type Size = Pick<Rect, 'width' | 'height'>;
466
-
467
- export type Position = Pick<Rect, 'x' | 'y'>;
468
-
469
- export interface Location {
470
- latitude: number;
471
- longitude: number;
472
- altitude: number;
473
- }
474
-
475
- export interface Rotation {
476
- x: number;
477
- y: number;
478
- z: number;
479
- }
480
-
481
- // Web Authentication
482
-
483
- export interface Credential {
484
- credentialId: string;
485
- isResidentCredential: boolean;
486
- rpId: string;
487
- privateKey: string;
488
- userHandle?: string;
489
- signCount: number;
490
- largeBlob?: string;
491
- }
492
-
493
- export interface EventHistory {
494
- commands: EventHistoryCommand[];
495
- [key: string]: any;
496
- }
497
-
498
- export interface EventHistoryCommand {
499
- cmd: string;
500
- startTime: number;
501
- endTime: number;
502
- }
503
- export type HTTPMethod = _Method;
504
-
505
- export type Prefix = string|(() => string);
506
-
507
- export interface AppiumLogger {
508
- unwrap(): Logger;
509
- level: string;
510
- levels: string[];
511
- prefix?: Prefix,
512
- debug: (...args: any[]) => void;
513
- info: (...args: any[]) => void;
514
- warn: (...args: any[]) => void;
515
- error: (...args: any[]) => void;
516
- verbose: (...args: any[]) => void;
517
- silly: (...args: any[]) => void;
518
- http: (...args: any[]) => void;
519
- errorAndThrow: (...args: any[]) => never;
520
- }
521
-
522
- export type AppiumServer = Omit<Server, 'close'> & {
523
- close: () => Promise<void>;
524
- };
525
-
526
- export interface TimeoutCommands {
527
- timeouts(
528
- type: string,
529
- ms: number | string,
530
- script?: number,
531
- pageLoad?: number,
532
- implicit?: number | string,
533
- ): Promise<void>;
534
- setNewCommandTimeout(ms: number): void;
535
- implicitWait(ms: number | string): Promise<void>;
536
- setImplicitWait(ms: number): void;
537
- implicitWaitForCondition(condition: () => Promise<any>): Promise<unknown>;
538
- getTimeouts(): Promise<Record<string, number>>;
539
- implicitWaitW3C(ms: number): Promise<void>;
540
- implicitWaitMJSONWP(ms: number): Promise<void>;
541
- pageLoadTimeoutW3C(ms: number): Promise<void>;
542
- pageLoadTimeoutMJSONWP(ms: number): Promise<void>;
543
- scriptTimeoutW3C(ms: number): Promise<void>;
544
- scriptTimeoutMJSONWP(ms: number): Promise<void>;
545
- newCommandTimeout(ms: number): Promise<void>;
546
- parseTimeoutArgument(ms: number | string): number;
547
- }
548
-
549
- export interface EventCommands {
550
- logCustomEvent(vendor: string, event: string): Promise<void>;
551
- getLogEvents(type?: string | string[]): Promise<EventHistory | Record<string, number>>;
552
- }
553
-
554
- export interface SessionCommands {
555
- getSessions(): Promise<MultiSessionData[]>;
556
- getSession(): Promise<SingularSessionData>;
557
- }
558
-
559
- export interface MultiSessionData {
560
- id: string;
561
- capabilities: Capabilities;
562
- }
563
-
564
- export type SingularSessionData = Capabilities & {events?: EventHistory};
565
-
566
- export interface FindCommands {
567
- findElement(strategy: string, selector: string): Promise<Element>;
568
- findElements(strategy: string, selector: string): Promise<Element[]>;
569
- findElementFromElement(
570
- strategy: string,
571
- selector: string,
572
- elementId: string,
573
- ): Promise<Element>;
574
- findElementsFromElement(
575
- strategy: string,
576
- selector: string,
577
- elementId: string,
578
- ): Promise<Element[]>;
579
-
580
- findElOrEls<Mult extends boolean>(
581
- strategy: string,
582
- selector: string,
583
- mult: Mult,
584
- context?: string,
585
- ): Promise<Mult extends true ? Element[] : Element>;
586
-
587
- findElOrElsWithProcessing<Mult extends boolean>(
588
- strategy: string,
589
- selector: string,
590
- mult: Mult,
591
- context?: string,
592
- ): Promise<Mult extends true ? Element[] : Element>;
593
-
594
- getPageSource(): Promise<string>;
595
- }
596
-
597
- export interface LogCommands {
598
- supportedLogTypes: Record<string, LogType<Driver>>;
599
- getLogTypes(): Promise<string[]>;
600
- /**
601
- * Gets logs
602
- *
603
- * TODO: `logType` should be a key in `supportedLogTypes`, and the return value of this function
604
- * should be the associated `LogType` object's `LogEntry` parameterized type.
605
- * @param logType - Name/key of log type as defined in {@linkcode LogCommands.supportedLogTypes}.
606
- */
607
- getLog(logType: string): Promise<any[]>;
608
- }
609
-
610
- export interface SettingsCommands {
611
- updateSettings: (settings: Record<string, any>) => Promise<void>;
612
- getSettings(): Promise<Record<string, any>>;
613
- }
614
-
615
- export interface SessionHandler<CreateResult, DeleteResult> {
616
- createSession(
617
- w3cCaps1: W3CCapabilities,
618
- w3cCaps2?: W3CCapabilities,
619
- w3cCaps?: W3CCapabilities,
620
- driverData?: DriverData[],
621
- ): Promise<CreateResult>;
622
-
623
- deleteSession(
624
- sessionId?: string,
625
- driverData?: DriverData[],
626
- ): Promise<DeleteResult>;
627
- }
628
-
629
- export type DriverData = Record<string, unknown>;
118
+ /**
119
+ * A mapping of URL paths to HTTP methods to {@linkcode Method}s.
120
+ *
121
+ * @todo Should use {@linkcode HTTPMethod} here
122
+ */
123
+ export type MethodMap<Extension = ExternalDriver> = Record<
124
+ string,
125
+ Record<string, Method<Extension & ExternalDriver>>
126
+ >;
630
127
 
631
128
  /**
632
129
  * Wraps {@linkcode _Class `type-fest`'s `Class`} to include static members.
@@ -634,5 +131,53 @@ export type DriverData = Record<string, unknown>;
634
131
  export type Class<
635
132
  Proto,
636
133
  StaticMembers extends object = {},
637
- Args extends unknown[] = any[],
134
+ Args extends unknown[] = any[]
638
135
  > = _Class<Proto, Args> & StaticMembers;
136
+
137
+ /**
138
+ * The string referring to a "driver"-type extension
139
+ */
140
+ export type DriverType = 'driver';
141
+
142
+ /**
143
+ * The string referring to a "plugin"-type extension
144
+ *
145
+ */
146
+ export type PluginType = 'plugin';
147
+
148
+ /**
149
+ * The strings referring to all extension types.
150
+ */
151
+ export type ExtensionType = DriverType | PluginType;
152
+
153
+ /**
154
+ * Optionally updates an Appium express app and http server, by calling
155
+ * methods that may mutate those objects. For example, you could call:
156
+ *
157
+ * `expressApp.get('/foo', handler)`
158
+ *
159
+ * In order to add a new route to Appium with this plugin. Or, you could add
160
+ * new listeners to the httpServer object.
161
+ *
162
+ * @param expressApp - the Express 'app' object used by Appium for route handling
163
+ * @param httpServer - the node HTTP server that hosts the app
164
+ */
165
+ export type UpdateServerCallback = (expressApp: Express, httpServer: AppiumServer) => Promise<void>;
166
+
167
+ /**
168
+ * Possible HTTP methods, as stolen from `axios`.
169
+ *
170
+ * @see https://npm.im/axios
171
+ */
172
+ export type HTTPMethod =
173
+ | 'get' | 'GET'
174
+ | 'delete' | 'DELETE'
175
+ | 'head' | 'HEAD'
176
+ | 'options' | 'OPTIONS'
177
+ | 'post' | 'POST'
178
+ | 'put' | 'PUT'
179
+ | 'patch' | 'PATCH'
180
+ | 'purge' | 'PURGE'
181
+ | 'link' | 'LINK'
182
+ | 'unlink' | 'UNLINK';
183
+