@appium/base-plugin 3.0.6 → 3.1.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/LICENSE +201 -0
- package/build/lib/index.d.ts +2 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +14 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/plugin.d.ts +16 -62
- package/build/lib/plugin.d.ts.map +1 -1
- package/build/lib/plugin.js +12 -66
- package/build/lib/plugin.js.map +1 -1
- package/lib/index.ts +6 -0
- package/lib/plugin.ts +81 -0
- package/package.json +12 -12
- package/tsconfig.json +3 -9
- package/index.js +0 -1
- package/lib/plugin.js +0 -107
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright OpenJS Foundation and other contributors, https://openjsf.org/
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,OAAO,EAAC,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = exports.BasePlugin = void 0;
|
|
7
|
+
var plugin_1 = require("./plugin");
|
|
8
|
+
Object.defineProperty(exports, "BasePlugin", { enumerable: true, get: function () { return plugin_1.BasePlugin; } });
|
|
9
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(plugin_1).default; } });
|
|
10
|
+
// Handle smoke test flag
|
|
11
|
+
if (require.main === module && process.argv[2] === '--smoke-test') {
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA6C;AAArC,oGAAA,UAAU,OAAA;AAAE,kHAAA,OAAO,OAAA;AAE3B,yBAAyB;AACzB,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,cAAc,EAAE,CAAC;IAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/build/lib/plugin.d.ts
CHANGED
|
@@ -1,71 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type NextPluginCallback = import("@appium/types").NextPluginCallback;
|
|
4
|
-
export type Constraints = import("@appium/types").Constraints;
|
|
5
|
-
export type Driver<C extends Constraints> = import("@appium/types").Driver<C>;
|
|
1
|
+
import { ExtensionCore } from '@appium/base-driver';
|
|
2
|
+
import type { AppiumLogger, Constraints, Driver, ExecuteMethodMap, MethodMap, NextPluginCallback, Plugin, StringRecord } from '@appium/types';
|
|
6
3
|
/**
|
|
7
|
-
*
|
|
4
|
+
* Base plugin class for Appium plugins.
|
|
5
|
+
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>` for
|
|
6
|
+
* `newMethodMap` and `ExecuteMethodMap<SubclassName>` for `executeMethodMap`.
|
|
8
7
|
*/
|
|
9
|
-
export class BasePlugin extends ExtensionCore implements Plugin {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* This will verify that the commands in the `newMethodMap` property are
|
|
14
|
-
* valid. It is impossible to use a generic type param here; the type of this should really
|
|
15
|
-
* be something like `MethodMap<T extends BasePlugin>` but that isn't a thing TS does.
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* static newMethodMap = {
|
|
19
|
-
* '/session/:sessionId/fake_data': {
|
|
20
|
-
* GET: {command: 'getFakeSessionData', neverProxy: true},
|
|
21
|
-
* }
|
|
22
|
-
* } as const;
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
static newMethodMap: {};
|
|
26
|
-
/**
|
|
27
|
-
* Subclasses should use type `import('@appium/types').ExecuteMethodMap<SubclassName>`.
|
|
28
|
-
*
|
|
29
|
-
* Building up this map allows the use of the convenience function `executeMethod`, which
|
|
30
|
-
* basically does verification of names and parameters for execute methods implemented by this
|
|
31
|
-
* plugin.
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* static executeMethodMap = {
|
|
35
|
-
* 'foo: bar': {
|
|
36
|
-
* command: 'commandName',
|
|
37
|
-
* params: {required: ['thing1', 'thing2'], optional: ['thing3']},
|
|
38
|
-
* },
|
|
39
|
-
* } as const;
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
static executeMethodMap: {};
|
|
43
|
-
/**
|
|
44
|
-
* @param {string} name
|
|
45
|
-
* @param {Record<string,unknown>} [cliArgs]
|
|
46
|
-
* @param {string|null} driverId
|
|
47
|
-
*/
|
|
48
|
-
constructor(name: string, cliArgs?: Record<string, unknown>, driverId?: string | null);
|
|
8
|
+
export declare class BasePlugin extends ExtensionCore implements Plugin {
|
|
9
|
+
name: string;
|
|
10
|
+
cliArgs: Record<string, unknown>;
|
|
49
11
|
/**
|
|
50
12
|
* @deprecated Use this.log instead of this.logger
|
|
51
|
-
* @type {import('@appium/types').AppiumLogger}
|
|
52
13
|
*/
|
|
53
|
-
logger:
|
|
54
|
-
|
|
55
|
-
|
|
14
|
+
logger: AppiumLogger;
|
|
15
|
+
static newMethodMap: MethodMap<BasePlugin>;
|
|
16
|
+
static executeMethodMap: ExecuteMethodMap<BasePlugin>;
|
|
17
|
+
constructor(name: string, cliArgs?: Record<string, unknown>, driverId?: string | null);
|
|
56
18
|
/**
|
|
57
|
-
* A convenience method
|
|
58
|
-
*
|
|
59
|
-
* `next` and `driver` objects since naturally we'd want to make sure to trigger the driver's own
|
|
60
|
-
* `executeMethod` call if an execute method is not found on the plugin itself.
|
|
61
|
-
*
|
|
62
|
-
* @template {Constraints} C
|
|
63
|
-
* @param {NextPluginCallback} next
|
|
64
|
-
* @param {Driver<C>} driver
|
|
65
|
-
* @param {string} script
|
|
66
|
-
* @param {readonly [import('@appium/types').StringRecord<unknown>] | readonly any[]} protoArgs
|
|
19
|
+
* A convenience method for plugins that implement their own `executeMethodMap`.
|
|
20
|
+
* Pass through to the driver's execute method if the plugin does not handle the script.
|
|
67
21
|
*/
|
|
68
|
-
executeMethod<C extends Constraints>(next: NextPluginCallback, driver: Driver<C>, script: string, protoArgs: readonly [
|
|
22
|
+
executeMethod<C extends Constraints>(next: NextPluginCallback, driver: Driver<C>, script: string, protoArgs: readonly [StringRecord<unknown>] | readonly unknown[]): Promise<unknown>;
|
|
69
23
|
}
|
|
70
|
-
|
|
24
|
+
export default BasePlugin;
|
|
71
25
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAGd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,MAAM,EAEN,YAAY,EACb,MAAM,eAAe,CAAC;AAEvB;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,aAAc,YAAW,MAAM;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjC;;OAEG;IACK,MAAM,EAAE,YAAY,CAAC;IAE7B,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,UAAU,CAAC,CAAM;IAEhD,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAM;gBAGzD,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACrC,QAAQ,GAAE,MAAM,GAAG,IAAW;IAWhC;;;OAGG;IACG,aAAa,CAAC,CAAC,SAAS,WAAW,EACvC,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,OAAO,EAAE,GAC/D,OAAO,CAAC,OAAO,CAAC;CAoBpB;AAED,eAAe,UAAU,CAAC"}
|
package/build/lib/plugin.js
CHANGED
|
@@ -3,52 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BasePlugin = void 0;
|
|
4
4
|
const base_driver_1 = require("@appium/base-driver");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Base plugin class for Appium plugins.
|
|
7
|
+
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>` for
|
|
8
|
+
* `newMethodMap` and `ExecuteMethodMap<SubclassName>` for `executeMethodMap`.
|
|
7
9
|
*/
|
|
8
10
|
class BasePlugin extends base_driver_1.ExtensionCore {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @type {import('@appium/types').AppiumLogger}
|
|
12
|
-
*/
|
|
13
|
-
logger;
|
|
14
|
-
/**
|
|
15
|
-
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>`.
|
|
16
|
-
*
|
|
17
|
-
* This will verify that the commands in the `newMethodMap` property are
|
|
18
|
-
* valid. It is impossible to use a generic type param here; the type of this should really
|
|
19
|
-
* be something like `MethodMap<T extends BasePlugin>` but that isn't a thing TS does.
|
|
20
|
-
*
|
|
21
|
-
* ```ts
|
|
22
|
-
* static newMethodMap = {
|
|
23
|
-
* '/session/:sessionId/fake_data': {
|
|
24
|
-
* GET: {command: 'getFakeSessionData', neverProxy: true},
|
|
25
|
-
* }
|
|
26
|
-
* } as const;
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
11
|
+
name;
|
|
12
|
+
cliArgs;
|
|
29
13
|
static newMethodMap = {};
|
|
30
|
-
/**
|
|
31
|
-
* Subclasses should use type `import('@appium/types').ExecuteMethodMap<SubclassName>`.
|
|
32
|
-
*
|
|
33
|
-
* Building up this map allows the use of the convenience function `executeMethod`, which
|
|
34
|
-
* basically does verification of names and parameters for execute methods implemented by this
|
|
35
|
-
* plugin.
|
|
36
|
-
*
|
|
37
|
-
* ```ts
|
|
38
|
-
* static executeMethodMap = {
|
|
39
|
-
* 'foo: bar': {
|
|
40
|
-
* command: 'commandName',
|
|
41
|
-
* params: {required: ['thing1', 'thing2'], optional: ['thing3']},
|
|
42
|
-
* },
|
|
43
|
-
* } as const;
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
14
|
static executeMethodMap = {};
|
|
47
|
-
/**
|
|
48
|
-
* @param {string} name
|
|
49
|
-
* @param {Record<string,unknown>} [cliArgs]
|
|
50
|
-
* @param {string|null} driverId
|
|
51
|
-
*/
|
|
52
15
|
constructor(name, cliArgs = {}, driverId = null) {
|
|
53
16
|
super();
|
|
54
17
|
if (driverId) {
|
|
@@ -59,38 +22,21 @@ class BasePlugin extends base_driver_1.ExtensionCore {
|
|
|
59
22
|
this.logger = this.log;
|
|
60
23
|
}
|
|
61
24
|
/**
|
|
62
|
-
* A convenience method
|
|
63
|
-
*
|
|
64
|
-
* `next` and `driver` objects since naturally we'd want to make sure to trigger the driver's own
|
|
65
|
-
* `executeMethod` call if an execute method is not found on the plugin itself.
|
|
66
|
-
*
|
|
67
|
-
* @template {Constraints} C
|
|
68
|
-
* @param {NextPluginCallback} next
|
|
69
|
-
* @param {Driver<C>} driver
|
|
70
|
-
* @param {string} script
|
|
71
|
-
* @param {readonly [import('@appium/types').StringRecord<unknown>] | readonly any[]} protoArgs
|
|
25
|
+
* A convenience method for plugins that implement their own `executeMethodMap`.
|
|
26
|
+
* Pass through to the driver's execute method if the plugin does not handle the script.
|
|
72
27
|
*/
|
|
73
28
|
async executeMethod(next, driver, script, protoArgs) {
|
|
74
|
-
const
|
|
75
|
-
const commandMetadata = { ...
|
|
29
|
+
const PluginClass = this.constructor;
|
|
30
|
+
const commandMetadata = { ...PluginClass.executeMethodMap?.[script] };
|
|
76
31
|
if (!commandMetadata.command || !(commandMetadata.command in this)) {
|
|
77
|
-
this.
|
|
32
|
+
this.log.info(`Plugin did not know how to handle method '${script}'. Passing control to next`);
|
|
78
33
|
return await next();
|
|
79
34
|
}
|
|
80
|
-
const command =
|
|
81
|
-
const args = (0, base_driver_1.validateExecuteMethodParams)(
|
|
35
|
+
const command = this[commandMetadata.command];
|
|
36
|
+
const args = (0, base_driver_1.validateExecuteMethodParams)(protoArgs, commandMetadata.params);
|
|
82
37
|
return await command.call(this, next, driver, ...args);
|
|
83
38
|
}
|
|
84
39
|
}
|
|
85
40
|
exports.BasePlugin = BasePlugin;
|
|
86
41
|
exports.default = BasePlugin;
|
|
87
|
-
/**
|
|
88
|
-
* @typedef {import('@appium/types').Plugin} Plugin
|
|
89
|
-
* @typedef {import('@appium/types').NextPluginCallback} NextPluginCallback
|
|
90
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
91
|
-
*/
|
|
92
|
-
/**
|
|
93
|
-
* @template {Constraints} C
|
|
94
|
-
* @typedef {import('@appium/types').Driver<C>} Driver
|
|
95
|
-
*/
|
|
96
42
|
//# sourceMappingURL=plugin.js.map
|
package/build/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":";;;AAAA,qDAI6B;AAa7B;;;;GAIG;AACH,MAAa,UAAW,SAAQ,2BAAa;IAC3C,IAAI,CAAS;IACb,OAAO,CAA0B;IAOjC,MAAM,CAAC,YAAY,GAA0B,EAAE,CAAC;IAEhD,MAAM,CAAC,gBAAgB,GAAiC,EAAE,CAAC;IAE3D,YACE,IAAY,EACZ,UAAmC,EAAE,EACrC,WAA0B,IAAI;QAE9B,KAAK,EAAE,CAAC;QACR,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,eAAe,CAAC,GAAG,IAAA,qCAAuB,EAAC,IAAI,CAAC,KAAK,QAAQ,GAAG,CAAC,CAAC;QACzE,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,aAAa,CACjB,IAAwB,EACxB,MAAiB,EACjB,MAAc,EACd,SAAgE;QAEhE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAgC,CAAC;QAC1D,MAAM,eAAe,GAAG,EAAC,GAAG,WAAW,CAAC,gBAAgB,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC;QAEpE,IAAI,CAAC,eAAe,CAAC,OAAO,IAAI,CAAC,CAAC,eAAe,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC;YACnE,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,6CAA6C,MAAM,4BAA4B,CAChF,CAAC;YACF,OAAO,MAAM,IAAI,EAAE,CAAC;QACtB,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAClB,eAAe,CAAC,OAAqB,CACV,CAAC;QAC9B,MAAM,IAAI,GAAG,IAAA,yCAA2B,EACtC,SAAsB,EACtB,eAAe,CAAC,MAAM,CACvB,CAAC;QACF,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IACzD,CAAC;;AAvDH,gCAwDC;AAED,kBAAe,UAAU,CAAC"}
|
package/lib/index.ts
ADDED
package/lib/plugin.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ExtensionCore,
|
|
3
|
+
generateDriverLogPrefix,
|
|
4
|
+
validateExecuteMethodParams,
|
|
5
|
+
} from '@appium/base-driver';
|
|
6
|
+
import type {
|
|
7
|
+
AppiumLogger,
|
|
8
|
+
Constraints,
|
|
9
|
+
Driver,
|
|
10
|
+
ExecuteMethodMap,
|
|
11
|
+
MethodMap,
|
|
12
|
+
NextPluginCallback,
|
|
13
|
+
Plugin,
|
|
14
|
+
PluginCommand,
|
|
15
|
+
StringRecord,
|
|
16
|
+
} from '@appium/types';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Base plugin class for Appium plugins.
|
|
20
|
+
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>` for
|
|
21
|
+
* `newMethodMap` and `ExecuteMethodMap<SubclassName>` for `executeMethodMap`.
|
|
22
|
+
*/
|
|
23
|
+
export class BasePlugin extends ExtensionCore implements Plugin {
|
|
24
|
+
name: string;
|
|
25
|
+
cliArgs: Record<string, unknown>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use this.log instead of this.logger
|
|
29
|
+
*/
|
|
30
|
+
declare logger: AppiumLogger;
|
|
31
|
+
|
|
32
|
+
static newMethodMap: MethodMap<BasePlugin> = {};
|
|
33
|
+
|
|
34
|
+
static executeMethodMap: ExecuteMethodMap<BasePlugin> = {};
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
name: string,
|
|
38
|
+
cliArgs: Record<string, unknown> = {},
|
|
39
|
+
driverId: string | null = null
|
|
40
|
+
) {
|
|
41
|
+
super();
|
|
42
|
+
if (driverId) {
|
|
43
|
+
this.updateLogPrefix(`${generateDriverLogPrefix(this)} <${driverId}>`);
|
|
44
|
+
}
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.cliArgs = cliArgs;
|
|
47
|
+
this.logger = this.log;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A convenience method for plugins that implement their own `executeMethodMap`.
|
|
52
|
+
* Pass through to the driver's execute method if the plugin does not handle the script.
|
|
53
|
+
*/
|
|
54
|
+
async executeMethod<C extends Constraints>(
|
|
55
|
+
next: NextPluginCallback,
|
|
56
|
+
driver: Driver<C>,
|
|
57
|
+
script: string,
|
|
58
|
+
protoArgs: readonly [StringRecord<unknown>] | readonly unknown[]
|
|
59
|
+
): Promise<unknown> {
|
|
60
|
+
const PluginClass = this.constructor as typeof BasePlugin;
|
|
61
|
+
const commandMetadata = {...PluginClass.executeMethodMap?.[script]};
|
|
62
|
+
|
|
63
|
+
if (!commandMetadata.command || !(commandMetadata.command in this)) {
|
|
64
|
+
this.log.info(
|
|
65
|
+
`Plugin did not know how to handle method '${script}'. Passing control to next`
|
|
66
|
+
);
|
|
67
|
+
return await next();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const command = this[
|
|
71
|
+
commandMetadata.command as keyof this
|
|
72
|
+
] as PluginCommand<Driver<C>>;
|
|
73
|
+
const args = validateExecuteMethodParams(
|
|
74
|
+
protoArgs as unknown[],
|
|
75
|
+
commandMetadata.params
|
|
76
|
+
);
|
|
77
|
+
return await command.call(this, next, driver, ...args);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default BasePlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/base-plugin",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "The base plugin used to create Appium plugins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -23,26 +23,26 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"author": "https://github.com/appium",
|
|
26
|
-
"
|
|
26
|
+
"main": "./build/lib/index.js",
|
|
27
|
+
"types": "./build/lib/index.d.ts",
|
|
27
28
|
"directories": {
|
|
28
29
|
"lib": "./lib"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
32
|
+
"build/lib",
|
|
31
33
|
"lib",
|
|
32
|
-
"
|
|
33
|
-
"index.js",
|
|
34
|
-
"tsconfig.json",
|
|
35
|
-
"!build/tsconfig.tsbuildinfo",
|
|
36
|
-
"!build/test"
|
|
34
|
+
"tsconfig.json"
|
|
37
35
|
],
|
|
38
36
|
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
39
38
|
"test": "npm run test:unit",
|
|
40
|
-
"test:smoke": "node ./index.js",
|
|
41
|
-
"test:unit": "mocha \"./test/unit/**/*.spec
|
|
39
|
+
"test:smoke": "node ./build/lib/index.js --smoke-test",
|
|
40
|
+
"test:unit": "mocha \"./test/unit/**/*.spec.*ts\""
|
|
42
41
|
},
|
|
43
42
|
"dependencies": {
|
|
44
|
-
"@appium/base-driver": "^10.2.
|
|
45
|
-
"@appium/support": "^7.0.
|
|
43
|
+
"@appium/base-driver": "^10.2.1",
|
|
44
|
+
"@appium/support": "^7.0.6",
|
|
45
|
+
"@appium/types": "^1.2.1"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": "^20.19.0 || ^22.12.0 || >=24.0.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "980a121804ae006db879fb6860f627ac36174c15",
|
|
55
55
|
"tags": [
|
|
56
56
|
"appium"
|
|
57
57
|
]
|
package/tsconfig.json
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "@appium/tsconfig/tsconfig.json",
|
|
3
2
|
"compilerOptions": {
|
|
4
3
|
"outDir": "build",
|
|
5
|
-
"
|
|
6
|
-
"strict": true,
|
|
7
|
-
"paths": {
|
|
8
|
-
"@appium/support": ["../support"],
|
|
9
|
-
"@appium/types": ["../types"]
|
|
10
|
-
}
|
|
4
|
+
"types": ["mocha", "chai"]
|
|
11
5
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
6
|
+
"extends": "@appium/tsconfig/tsconfig.plugin.json",
|
|
7
|
+
"include": ["lib", "test"]
|
|
14
8
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./build/lib/plugin');
|
package/lib/plugin.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import {ExtensionCore, generateDriverLogPrefix, validateExecuteMethodParams} from '@appium/base-driver';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @implements {Plugin}
|
|
5
|
-
*/
|
|
6
|
-
class BasePlugin extends ExtensionCore {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated Use this.log instead of this.logger
|
|
10
|
-
* @type {import('@appium/types').AppiumLogger}
|
|
11
|
-
*/
|
|
12
|
-
logger;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>`.
|
|
16
|
-
*
|
|
17
|
-
* This will verify that the commands in the `newMethodMap` property are
|
|
18
|
-
* valid. It is impossible to use a generic type param here; the type of this should really
|
|
19
|
-
* be something like `MethodMap<T extends BasePlugin>` but that isn't a thing TS does.
|
|
20
|
-
*
|
|
21
|
-
* ```ts
|
|
22
|
-
* static newMethodMap = {
|
|
23
|
-
* '/session/:sessionId/fake_data': {
|
|
24
|
-
* GET: {command: 'getFakeSessionData', neverProxy: true},
|
|
25
|
-
* }
|
|
26
|
-
* } as const;
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
static newMethodMap = {};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Subclasses should use type `import('@appium/types').ExecuteMethodMap<SubclassName>`.
|
|
33
|
-
*
|
|
34
|
-
* Building up this map allows the use of the convenience function `executeMethod`, which
|
|
35
|
-
* basically does verification of names and parameters for execute methods implemented by this
|
|
36
|
-
* plugin.
|
|
37
|
-
*
|
|
38
|
-
* ```ts
|
|
39
|
-
* static executeMethodMap = {
|
|
40
|
-
* 'foo: bar': {
|
|
41
|
-
* command: 'commandName',
|
|
42
|
-
* params: {required: ['thing1', 'thing2'], optional: ['thing3']},
|
|
43
|
-
* },
|
|
44
|
-
* } as const;
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
static executeMethodMap = {};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @param {string} name
|
|
51
|
-
* @param {Record<string,unknown>} [cliArgs]
|
|
52
|
-
* @param {string|null} driverId
|
|
53
|
-
*/
|
|
54
|
-
constructor(name, cliArgs = {}, driverId = null) {
|
|
55
|
-
super();
|
|
56
|
-
if (driverId) {
|
|
57
|
-
this.updateLogPrefix(`${generateDriverLogPrefix(this)} <${driverId}>`);
|
|
58
|
-
}
|
|
59
|
-
this.name = name;
|
|
60
|
-
this.cliArgs = cliArgs;
|
|
61
|
-
this.logger = this.log;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* A convenience method that can be called by plugins who implement their own `executeMethodMap`.
|
|
66
|
-
* Only useful if your plugin has defined `executeMethodMap`. This helper requires passing in the
|
|
67
|
-
* `next` and `driver` objects since naturally we'd want to make sure to trigger the driver's own
|
|
68
|
-
* `executeMethod` call if an execute method is not found on the plugin itself.
|
|
69
|
-
*
|
|
70
|
-
* @template {Constraints} C
|
|
71
|
-
* @param {NextPluginCallback} next
|
|
72
|
-
* @param {Driver<C>} driver
|
|
73
|
-
* @param {string} script
|
|
74
|
-
* @param {readonly [import('@appium/types').StringRecord<unknown>] | readonly any[]} protoArgs
|
|
75
|
-
*/
|
|
76
|
-
async executeMethod(next, driver, script, protoArgs) {
|
|
77
|
-
const Plugin = /** @type {import('@appium/types').PluginClass<Plugin>} */ (this.constructor);
|
|
78
|
-
const commandMetadata = {...Plugin.executeMethodMap?.[script]};
|
|
79
|
-
|
|
80
|
-
if (!commandMetadata.command || !(commandMetadata.command in this)) {
|
|
81
|
-
this.logger.info(
|
|
82
|
-
`Plugin did not know how to handle method '${script}'. Passing control to next`
|
|
83
|
-
);
|
|
84
|
-
return await next();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const command = /** @type {import('@appium/types').PluginCommand<Driver<C>>} */ (
|
|
88
|
-
this[commandMetadata.command]
|
|
89
|
-
);
|
|
90
|
-
const args = validateExecuteMethodParams(/** @type {any[]} */ (protoArgs), commandMetadata.params);
|
|
91
|
-
return await command.call(this, next, driver, ...args);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export default BasePlugin;
|
|
96
|
-
export {BasePlugin};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @typedef {import('@appium/types').Plugin} Plugin
|
|
100
|
-
* @typedef {import('@appium/types').NextPluginCallback} NextPluginCallback
|
|
101
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @template {Constraints} C
|
|
106
|
-
* @typedef {import('@appium/types').Driver<C>} Driver
|
|
107
|
-
*/
|