@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/build/capabilities.d.ts.map +1 -1
- package/build/config.d.ts.map +1 -1
- package/build/driver.d.ts +440 -0
- package/build/driver.d.ts.map +1 -0
- package/build/index.d.ts +117 -405
- package/build/index.d.ts.map +1 -1
- package/build/plugin.d.ts +79 -0
- package/build/plugin.d.ts.map +1 -0
- package/lib/capabilities.ts +11 -12
- package/lib/config.ts +20 -23
- package/lib/driver.ts +601 -0
- package/lib/index.ts +148 -603
- package/lib/plugin.ts +92 -0
- package/package.json +14 -8
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { MethodMap, UpdateServerCallback, Class, AppiumLogger } from '.';
|
|
2
|
+
import { Driver, ExternalDriver } from './driver';
|
|
3
|
+
/**
|
|
4
|
+
* The interface describing the constructor and static properties of a Plugin.
|
|
5
|
+
*/
|
|
6
|
+
export interface PluginStatic<T extends Plugin = Plugin> {
|
|
7
|
+
/**
|
|
8
|
+
* Allows a plugin to modify the Appium server instance.
|
|
9
|
+
*/
|
|
10
|
+
updateServer?: UpdateServerCallback;
|
|
11
|
+
/**
|
|
12
|
+
* Plugins can define new methods for the Appium server to map to command names, of the same
|
|
13
|
+
* format as used in Appium's `routes.js`, for example, this would be a valid `newMethodMap`:
|
|
14
|
+
* @example
|
|
15
|
+
* {
|
|
16
|
+
* '/session/:sessionId/new_method': {
|
|
17
|
+
* GET: {command: 'getNewThing'},
|
|
18
|
+
* POST: {command: 'setNewThing', payloadParams: {required: ['someParam']}}
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
newMethodMap?: MethodMap<T>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* An instance of a "plugin" extension.
|
|
26
|
+
*
|
|
27
|
+
* Likewise, the `prototype` of a {@link PluginClass `Plugin` class}.
|
|
28
|
+
*/
|
|
29
|
+
export interface Plugin {
|
|
30
|
+
/**
|
|
31
|
+
* Name of the plugin. Derived from the metadata.
|
|
32
|
+
*/
|
|
33
|
+
name: string;
|
|
34
|
+
/**
|
|
35
|
+
* A logger with prefix identifying the plugin
|
|
36
|
+
*/
|
|
37
|
+
logger: AppiumLogger;
|
|
38
|
+
/**
|
|
39
|
+
* CLI args for this plugin (if any are accepted and provided).
|
|
40
|
+
*/
|
|
41
|
+
cliArgs: Record<string, any>;
|
|
42
|
+
/**
|
|
43
|
+
* Listener for unexpected server shutdown, which allows a plugin to do cleanup or take custom actions.
|
|
44
|
+
*/
|
|
45
|
+
onUnexpectedShutdown?: (driver: Driver, cause: Error | string) => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Handle an Appium command, optionally running and using or throwing away the value of the
|
|
48
|
+
* original Appium behavior (or the behavior of the next plugin in a plugin chain).
|
|
49
|
+
*/
|
|
50
|
+
handle?: (next: NextPluginCallback, driver: Driver, cmdName: string, ...args: any[]) => Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A reference to an async function which encapsulates what would normally
|
|
54
|
+
* happen if this plugin were not handling a command. Used by {@link PluginInterface.handle}.
|
|
55
|
+
*
|
|
56
|
+
* Given `next()` is a `NextPluginCallback`: if this is the only plugin
|
|
57
|
+
* handling the command, `await next()` would therefore trigger the normal
|
|
58
|
+
* handling logic in the driver which is in use. If another plugin is
|
|
59
|
+
* registered, it would run *that* plugin's `handle` method and return the
|
|
60
|
+
* result for use here. Note that if this plugin does *not* call `await next()`,
|
|
61
|
+
* then the normal command logic will not be run, and this plugin is responsible
|
|
62
|
+
* for managing new command timeouts and command logging, for example:
|
|
63
|
+
* `driver.stopNewCommandTimeout()` -- before running plugin logic
|
|
64
|
+
* `driver.startNewCommandTimeout()` -- after running plugin logic
|
|
65
|
+
* `driver._eventHistory.commands.push({cmd: cmdName, startTime, endTime}) --
|
|
66
|
+
* after running plugin logic
|
|
67
|
+
*/
|
|
68
|
+
export declare type NextPluginCallback = () => Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Implementation of a command within a plugin
|
|
71
|
+
*/
|
|
72
|
+
export declare type PluginCommand<TArgs = any> = (next: NextPluginCallback, driver: ExternalDriver, ...args: TArgs[]) => Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Mainly for internal use.
|
|
75
|
+
*
|
|
76
|
+
* The third parameter is the possible constructor signatures for the plugin class.
|
|
77
|
+
*/
|
|
78
|
+
export declare type PluginClass = Class<Plugin, PluginStatic, [string, Record<string, unknown>]>;
|
|
79
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../lib/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,oBAAoB,EAAE,KAAK,EAAE,YAAY,EAAC,MAAM,GAAG,CAAC;AACvE,OAAO,EAAC,MAAM,EAAE,cAAc,EAAC,MAAM,UAAU,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACrD;;OAEG;IACH,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC;;;;;;;;;;OAUG;IACH,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B;;OAEG;IACH,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChF;;;OAGG;IACH,MAAM,CAAC,EAAE,CACP,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,oBAAY,kBAAkB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAErD;;GAEG;AACH,oBAAY,aAAa,CAAC,KAAK,GAAG,GAAG,IAAI,CACvC,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,cAAc,EACtB,GAAG,IAAI,EAAE,KAAK,EAAE,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB;;;;GAIG;AACH,oBAAY,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
package/lib/capabilities.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {Capabilities as WdioCaps} from '@wdio/types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The mask of a W3C-style namespaced capability proped name.
|
|
@@ -19,31 +19,31 @@ type StringRecord = Record<string, any>;
|
|
|
19
19
|
* All known capabilities derived from wdio's {@linkcode WdioCaps.Capabilities Capabilities} type, accepting additional optional caps.
|
|
20
20
|
* All properties are optional.
|
|
21
21
|
*/
|
|
22
|
-
type BaseCapabilities<OptionalCaps extends StringRecord = StringRecord> =
|
|
23
|
-
|
|
22
|
+
type BaseCapabilities<OptionalCaps extends StringRecord = StringRecord> = Partial<
|
|
23
|
+
WdioCaps.Capabilities & OptionalCaps
|
|
24
|
+
>;
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* All known capabilities derived from wdio's {@linkcode WdioCaps.Capabilities Capabilities} type and wdio's {@linkcode WdioCaps.AppiumCapabilities} type, accepting additional optional caps.
|
|
27
|
-
*
|
|
28
|
+
*
|
|
28
29
|
* In practice, the properties `platformName` and `automationName` are required by Appium.
|
|
29
30
|
*/
|
|
30
|
-
export type Capabilities<OptionalCaps extends StringRecord = StringRecord> =
|
|
31
|
-
|
|
31
|
+
export type Capabilities<OptionalCaps extends StringRecord = StringRecord> = BaseCapabilities<
|
|
32
|
+
WdioCaps.AppiumCapabilities & OptionalCaps
|
|
33
|
+
>;
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* All known capabilities derived from wdio's {@linkcode WdioCaps.Capabilities Capabilities} type and wdio's {@linkcode WdioCaps.AppiumW3CCapabilities} type, accepting additional optional _namespaced_ caps.
|
|
35
37
|
*/
|
|
36
38
|
export type AppiumW3CCapabilities<
|
|
37
|
-
OptionalNamespacedCaps extends NamespacedRecord = NamespacedRecord
|
|
39
|
+
OptionalNamespacedCaps extends NamespacedRecord = NamespacedRecord
|
|
38
40
|
> = BaseCapabilities<WdioCaps.AppiumW3CCapabilities & OptionalNamespacedCaps>;
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
* All known capabilities derived from wdio's {@linkcode WdioCaps.Capabilities Capabilities} type and wdio's {@linkcode WdioCaps.AppiumW3Capabilities} type, accepting additional optional _namespaced_ caps, in W3C-compatible format (`alwaysMatch`/`firstMatch`).
|
|
42
44
|
* In practice, the properties `appium:platformName` and `appium:automationName` are required by Appium _somewhere_ in this object; this cannot be expressed in TypeScript.
|
|
43
45
|
*/
|
|
44
|
-
export type W3CCapabilities<
|
|
45
|
-
OptionalNamespacedCaps extends NamespacedRecord = NamespacedRecord,
|
|
46
|
-
> = {
|
|
46
|
+
export type W3CCapabilities<OptionalNamespacedCaps extends NamespacedRecord = NamespacedRecord> = {
|
|
47
47
|
alwaysMatch: AppiumW3CCapabilities<OptionalNamespacedCaps>;
|
|
48
48
|
firstMatch: AppiumW3CCapabilities<OptionalNamespacedCaps>[];
|
|
49
49
|
};
|
|
@@ -55,6 +55,5 @@ export type AppiumAndroidCapabilities = WdioCaps.AppiumAndroidCapabilities;
|
|
|
55
55
|
export type AppiumIOSCapabilities = WdioCaps.AppiumIOSCapabilities;
|
|
56
56
|
export type AppiumXCUICommandTimeouts = WdioCaps.AppiumXCUICommandTimeouts;
|
|
57
57
|
export type AppiumXCUIProcessArguments = WdioCaps.AppiumXCUIProcessArguments;
|
|
58
|
-
export type AppiumXCUISafariGlobalPreferences =
|
|
59
|
-
WdioCaps.AppiumXCUISafariGlobalPreferences;
|
|
58
|
+
export type AppiumXCUISafariGlobalPreferences = WdioCaps.AppiumXCUISafariGlobalPreferences;
|
|
60
59
|
export type AppiumXCUITestCapabilities = WdioCaps.AppiumXCUITestCapabilities;
|
package/lib/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type {AppiumConfigJsonSchema} from '@appium/schema';
|
|
2
|
+
import {AppiumConfiguration, ServerConfig} from './appium-config';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The Appium configuration as it would be in a user-provided configuration file.
|
|
@@ -9,8 +9,7 @@ export type AppiumConfig = Partial<AppiumConfiguration>;
|
|
|
9
9
|
/**
|
|
10
10
|
* Derive the "constant" type of the server properties from the schema.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
typeof AppiumConfigJsonSchema['properties']['server']['properties'];
|
|
12
|
+
type AppiumServerJsonSchema = typeof AppiumConfigJsonSchema['properties']['server']['properties'];
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* This type associates the types generated from the schema ({@linkcode AppiumConfiguration})
|
|
@@ -67,35 +66,34 @@ export type ServerArgs = {
|
|
|
67
66
|
/**
|
|
68
67
|
* Converts a kebab-cased string into a camel-cased string.
|
|
69
68
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
: Lowercase<S>;
|
|
69
|
+
type KebabToCamel<S extends string> = S extends `${infer P1}-${infer P2}${infer P3}`
|
|
70
|
+
? `${Lowercase<P1>}${Uppercase<P2>}${KebabToCamel<P3>}`
|
|
71
|
+
: Lowercase<S>;
|
|
74
72
|
|
|
75
73
|
/**
|
|
76
|
-
* Converts an object with kebab-cased keys into camel-cased keys.
|
|
77
|
-
*/
|
|
74
|
+
* Converts an object with kebab-cased keys into camel-cased keys.
|
|
75
|
+
*/
|
|
78
76
|
type ObjectToCamel<T> = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
[K in keyof T as KebabToCamel<string & K>]: T[K] extends Record<string, any>
|
|
78
|
+
? KeysToCamelCase<T[K]>
|
|
79
|
+
: T[K];
|
|
82
80
|
};
|
|
83
81
|
|
|
84
82
|
/**
|
|
85
|
-
* Converts an object or array to have camel-cased keys.
|
|
86
|
-
*/
|
|
83
|
+
* Converts an object or array to have camel-cased keys.
|
|
84
|
+
*/
|
|
87
85
|
type KeysToCamelCase<T> = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
[K in keyof T as KebabToCamel<string & K>]: T[K] extends Array<any>
|
|
87
|
+
? KeysToCamelCase<T[K][number]>[]
|
|
88
|
+
: ObjectToCamel<T[K]>;
|
|
91
89
|
};
|
|
92
90
|
|
|
93
91
|
/**
|
|
94
|
-
* Object `B` has all the keys as object `A` (even if those keys in `A` are otherwise optional).
|
|
92
|
+
* Object `B` has all the keys as object `A` (even if those keys in `A` are otherwise optional).
|
|
95
93
|
*/
|
|
96
|
-
type Associated<A extends object, B extends {
|
|
94
|
+
type Associated<A extends object, B extends {[key in keyof Required<A>]: unknown}> = {
|
|
97
95
|
[Prop in keyof Required<A>]: B[Prop];
|
|
98
|
-
}
|
|
96
|
+
};
|
|
99
97
|
|
|
100
98
|
// end utils
|
|
101
99
|
|
|
@@ -109,7 +107,7 @@ type Associated<A extends object, B extends { [key in keyof Required<A>]: unknow
|
|
|
109
107
|
*
|
|
110
108
|
* See `appium/lib/schema/keywords` for definition of `appiumCliDest`.
|
|
111
109
|
*/
|
|
112
|
-
|
|
110
|
+
interface WithDest {
|
|
113
111
|
appiumCliDest: string;
|
|
114
112
|
}
|
|
115
113
|
|
|
@@ -125,4 +123,3 @@ interface WithDefault<T = any> {
|
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
// end conditionals
|
|
128
|
-
|