appium 2.0.0-beta.4 → 2.0.0-beta.40

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.
Files changed (151) hide show
  1. package/README.md +10 -11
  2. package/build/lib/appium.d.ts +204 -0
  3. package/build/lib/appium.d.ts.map +1 -0
  4. package/build/lib/appium.js +257 -131
  5. package/build/lib/cli/args.d.ts +20 -0
  6. package/build/lib/cli/args.d.ts.map +1 -0
  7. package/build/lib/cli/args.js +96 -282
  8. package/build/lib/cli/driver-command.d.ts +36 -0
  9. package/build/lib/cli/driver-command.d.ts.map +1 -0
  10. package/build/lib/cli/driver-command.js +25 -18
  11. package/build/lib/cli/extension-command.d.ts +372 -0
  12. package/build/lib/cli/extension-command.d.ts.map +1 -0
  13. package/build/lib/cli/extension-command.js +286 -156
  14. package/build/lib/cli/extension.d.ts +18 -0
  15. package/build/lib/cli/extension.d.ts.map +1 -0
  16. package/build/lib/cli/extension.js +30 -17
  17. package/build/lib/cli/parser.d.ts +80 -0
  18. package/build/lib/cli/parser.d.ts.map +1 -0
  19. package/build/lib/cli/parser.js +152 -95
  20. package/build/lib/cli/plugin-command.d.ts +33 -0
  21. package/build/lib/cli/plugin-command.d.ts.map +1 -0
  22. package/build/lib/cli/plugin-command.js +24 -19
  23. package/build/lib/cli/utils.d.ts +29 -0
  24. package/build/lib/cli/utils.d.ts.map +1 -0
  25. package/build/lib/cli/utils.js +27 -3
  26. package/build/lib/config-file.d.ts +100 -0
  27. package/build/lib/config-file.d.ts.map +1 -0
  28. package/build/lib/config-file.js +136 -0
  29. package/build/lib/config.d.ts +41 -0
  30. package/build/lib/config.d.ts.map +1 -0
  31. package/build/lib/config.js +92 -67
  32. package/build/lib/constants.d.ts +48 -0
  33. package/build/lib/constants.d.ts.map +1 -0
  34. package/build/lib/constants.js +60 -0
  35. package/build/lib/extension/driver-config.d.ts +81 -0
  36. package/build/lib/extension/driver-config.d.ts.map +1 -0
  37. package/build/lib/extension/driver-config.js +177 -0
  38. package/build/lib/extension/extension-config.d.ts +242 -0
  39. package/build/lib/extension/extension-config.d.ts.map +1 -0
  40. package/build/lib/extension/extension-config.js +436 -0
  41. package/build/lib/extension/index.d.ts +48 -0
  42. package/build/lib/extension/index.d.ts.map +1 -0
  43. package/build/lib/extension/index.js +74 -0
  44. package/build/lib/extension/manifest.d.ts +174 -0
  45. package/build/lib/extension/manifest.d.ts.map +1 -0
  46. package/build/lib/extension/manifest.js +256 -0
  47. package/build/lib/extension/package-changed.d.ts +11 -0
  48. package/build/lib/extension/package-changed.d.ts.map +1 -0
  49. package/build/lib/extension/package-changed.js +68 -0
  50. package/build/lib/extension/plugin-config.d.ts +57 -0
  51. package/build/lib/extension/plugin-config.d.ts.map +1 -0
  52. package/build/lib/extension/plugin-config.js +78 -0
  53. package/build/lib/grid-register.d.ts +10 -0
  54. package/build/lib/grid-register.d.ts.map +1 -0
  55. package/build/lib/grid-register.js +21 -25
  56. package/build/lib/logger.d.ts +3 -0
  57. package/build/lib/logger.d.ts.map +1 -0
  58. package/build/lib/logger.js +4 -6
  59. package/build/lib/logsink.d.ts +4 -0
  60. package/build/lib/logsink.d.ts.map +1 -0
  61. package/build/lib/logsink.js +14 -17
  62. package/build/lib/main.d.ts +55 -0
  63. package/build/lib/main.d.ts.map +1 -0
  64. package/build/lib/main.js +189 -90
  65. package/build/lib/schema/arg-spec.d.ts +143 -0
  66. package/build/lib/schema/arg-spec.d.ts.map +1 -0
  67. package/build/lib/schema/arg-spec.js +119 -0
  68. package/build/lib/schema/cli-args.d.ts +19 -0
  69. package/build/lib/schema/cli-args.d.ts.map +1 -0
  70. package/build/lib/schema/cli-args.js +180 -0
  71. package/build/lib/schema/cli-transformers.d.ts +5 -0
  72. package/build/lib/schema/cli-transformers.d.ts.map +1 -0
  73. package/build/lib/schema/cli-transformers.js +74 -0
  74. package/build/lib/schema/index.d.ts +3 -0
  75. package/build/lib/schema/index.d.ts.map +1 -0
  76. package/build/lib/schema/index.js +34 -0
  77. package/build/lib/schema/keywords.d.ts +24 -0
  78. package/build/lib/schema/keywords.d.ts.map +1 -0
  79. package/build/lib/schema/keywords.js +70 -0
  80. package/build/lib/schema/schema.d.ts +259 -0
  81. package/build/lib/schema/schema.d.ts.map +1 -0
  82. package/build/lib/schema/schema.js +452 -0
  83. package/build/lib/utils.d.ts +66 -0
  84. package/build/lib/utils.d.ts.map +1 -0
  85. package/build/lib/utils.js +35 -139
  86. package/build/tsconfig.tsbuildinfo +1 -0
  87. package/build/types/appium-manifest.d.ts +59 -0
  88. package/build/types/appium-manifest.d.ts.map +1 -0
  89. package/build/types/cli.d.ts +112 -0
  90. package/build/types/cli.d.ts.map +1 -0
  91. package/build/types/extension-manifest.d.ts +55 -0
  92. package/build/types/extension-manifest.d.ts.map +1 -0
  93. package/build/types/index.d.ts +16 -0
  94. package/build/types/index.d.ts.map +1 -0
  95. package/driver.d.ts +1 -0
  96. package/driver.js +14 -0
  97. package/index.js +11 -0
  98. package/lib/appium.js +517 -186
  99. package/lib/cli/args.js +269 -422
  100. package/lib/cli/driver-command.js +58 -23
  101. package/lib/cli/extension-command.js +612 -260
  102. package/lib/cli/extension.js +34 -16
  103. package/lib/cli/parser.js +241 -83
  104. package/lib/cli/plugin-command.js +48 -20
  105. package/lib/cli/utils.js +24 -10
  106. package/lib/config-file.js +219 -0
  107. package/lib/config.js +210 -91
  108. package/lib/constants.js +69 -0
  109. package/lib/extension/driver-config.js +249 -0
  110. package/lib/extension/extension-config.js +679 -0
  111. package/lib/extension/index.js +116 -0
  112. package/lib/extension/manifest.js +475 -0
  113. package/lib/extension/package-changed.js +64 -0
  114. package/lib/extension/plugin-config.js +113 -0
  115. package/lib/grid-register.js +49 -35
  116. package/lib/logger.js +1 -2
  117. package/lib/logsink.js +38 -33
  118. package/lib/main.js +303 -100
  119. package/lib/schema/arg-spec.js +229 -0
  120. package/lib/schema/cli-args.js +238 -0
  121. package/lib/schema/cli-transformers.js +115 -0
  122. package/lib/schema/index.js +2 -0
  123. package/lib/schema/keywords.js +136 -0
  124. package/lib/schema/schema.js +717 -0
  125. package/lib/utils.js +121 -140
  126. package/package.json +75 -85
  127. package/plugin.d.ts +1 -0
  128. package/plugin.js +13 -0
  129. package/scripts/autoinstall-extensions.js +177 -0
  130. package/support.d.ts +1 -0
  131. package/support.js +13 -0
  132. package/types/appium-manifest.ts +73 -0
  133. package/types/cli.ts +146 -0
  134. package/types/extension-manifest.ts +64 -0
  135. package/types/index.ts +21 -0
  136. package/CHANGELOG.md +0 -3515
  137. package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
  138. package/build/lib/cli/npm.js +0 -206
  139. package/build/lib/cli/parser-helpers.js +0 -82
  140. package/build/lib/driver-config.js +0 -77
  141. package/build/lib/drivers.js +0 -96
  142. package/build/lib/extension-config.js +0 -253
  143. package/build/lib/plugin-config.js +0 -59
  144. package/build/lib/plugins.js +0 -14
  145. package/lib/cli/npm.js +0 -183
  146. package/lib/cli/parser-helpers.js +0 -79
  147. package/lib/driver-config.js +0 -46
  148. package/lib/drivers.js +0 -81
  149. package/lib/extension-config.js +0 -209
  150. package/lib/plugin-config.js +0 -34
  151. package/lib/plugins.js +0 -10
@@ -0,0 +1,249 @@
1
+ import _ from 'lodash';
2
+ import {DRIVER_TYPE} from '../constants';
3
+ import log from '../logger';
4
+ import {ExtensionConfig} from './extension-config';
5
+
6
+ /**
7
+ * @extends {ExtensionConfig<DriverType>}
8
+ */
9
+ export class DriverConfig extends ExtensionConfig {
10
+ /**
11
+ * A set of unique automation names used by drivers.
12
+ * @type {Set<string>}
13
+ */
14
+ knownAutomationNames;
15
+
16
+ /**
17
+ * A mapping of {@link Manifest} instances to {@link DriverConfig} instances.
18
+ *
19
+ * `Manifest` and `ExtensionConfig` have a one-to-many relationship; each `Manifest` should be associated with a `DriverConfig` and a `PluginConfig`; no more, no less.
20
+ *
21
+ * This variable tracks the `Manifest`-to-`DriverConfig` portion.
22
+ *
23
+ * @type {WeakMap<Manifest,DriverConfig>}
24
+ * @private
25
+ */
26
+ static _instances = new WeakMap();
27
+
28
+ /**
29
+ * Call {@link DriverConfig.create} instead.
30
+ * @private
31
+ * @param {import('./manifest').Manifest} manifest - Manifest instance
32
+ */
33
+ constructor(manifest) {
34
+ super(DRIVER_TYPE, manifest);
35
+
36
+ this.knownAutomationNames = new Set();
37
+ }
38
+
39
+ /**
40
+ * Creates a new {@link DriverConfig} instance for a {@link Manifest} instance.
41
+ *
42
+ * @param {Manifest} manifest
43
+ * @throws If `manifest` already associated with a `DriverConfig`
44
+ * @returns {DriverConfig}
45
+ */
46
+ static create(manifest) {
47
+ const instance = new DriverConfig(manifest);
48
+ if (DriverConfig.getInstance(manifest)) {
49
+ throw new Error(
50
+ `Manifest with APPIUM_HOME ${manifest.appiumHome} already has a DriverConfig; use DriverConfig.getInstance() to retrieve it.`
51
+ );
52
+ }
53
+ DriverConfig._instances.set(manifest, instance);
54
+ return instance;
55
+ }
56
+
57
+ /**
58
+ * Returns a DriverConfig associated with a Manifest
59
+ * @param {Manifest} manifest
60
+ * @returns {DriverConfig|undefined}
61
+ */
62
+ static getInstance(manifest) {
63
+ return DriverConfig._instances.get(manifest);
64
+ }
65
+
66
+ /**
67
+ * Checks extensions for problems
68
+ */
69
+ async validate() {
70
+ this.knownAutomationNames.clear();
71
+ return await super._validate(this.manifest.getExtensionData(DRIVER_TYPE));
72
+ }
73
+
74
+ /**
75
+ * @param {ExtManifest<DriverType>} extData
76
+ * @returns {import('./extension-config').ExtManifestProblem[]}
77
+ */
78
+ getConfigProblems(extData) {
79
+ const problems = [];
80
+ const {platformNames, automationName} = extData;
81
+
82
+ if (!_.isArray(platformNames)) {
83
+ problems.push({
84
+ err: 'Missing or incorrect supported platformNames list.',
85
+ val: platformNames,
86
+ });
87
+ } else {
88
+ if (_.isEmpty(platformNames)) {
89
+ problems.push({
90
+ err: 'Empty platformNames list.',
91
+ val: platformNames,
92
+ });
93
+ } else {
94
+ for (const pName of platformNames) {
95
+ if (!_.isString(pName)) {
96
+ problems.push({
97
+ err: 'Incorrectly formatted platformName.',
98
+ val: pName,
99
+ });
100
+ }
101
+ }
102
+ }
103
+ }
104
+
105
+ if (!_.isString(automationName)) {
106
+ problems.push({
107
+ err: 'Missing or incorrect automationName',
108
+ val: automationName,
109
+ });
110
+ }
111
+
112
+ if (this.knownAutomationNames.has(automationName)) {
113
+ problems.push({
114
+ err: 'Multiple drivers claim support for the same automationName',
115
+ val: automationName,
116
+ });
117
+ }
118
+
119
+ // should we retain the name at the end of this function, once we've checked there are no problems?
120
+ this.knownAutomationNames.add(automationName);
121
+
122
+ return problems;
123
+ }
124
+
125
+ /**
126
+ * @param {ExtName<DriverType>} driverName
127
+ * @param {ExtManifest<DriverType>} extData
128
+ * @returns {string}
129
+ */
130
+ extensionDesc(driverName, {version, automationName}) {
131
+ return `${driverName}@${version} (automationName '${automationName}')`;
132
+ }
133
+
134
+ /**
135
+ * Given capabilities, find a matching driver within the config. Load its class and return it along with version and driver name.
136
+ * @param {Capabilities} caps
137
+ * @returns {MatchedDriver}
138
+ */
139
+ findMatchingDriver({automationName, platformName}) {
140
+ if (!_.isString(platformName)) {
141
+ throw new Error('You must include a platformName capability');
142
+ }
143
+
144
+ if (!_.isString(automationName)) {
145
+ throw new Error('You must include an automationName capability');
146
+ }
147
+
148
+ log.info(
149
+ `Attempting to find matching driver for automationName ` +
150
+ `'${automationName}' and platformName '${platformName}'`
151
+ );
152
+
153
+ try {
154
+ const {driverName, mainClass, version} = this._getDriverBySupport(
155
+ automationName,
156
+ platformName
157
+ );
158
+ log.info(`The '${driverName}' driver was installed and matched caps.`);
159
+ log.info(`Will require it at ${this.getInstallPath(driverName)}`);
160
+ const driver = this.require(driverName);
161
+ if (!driver) {
162
+ throw new Error(
163
+ `Driver '${driverName}' did not export a class with name '${mainClass}'. Contact the author of the driver!`
164
+ );
165
+ }
166
+ return {driver, version, driverName};
167
+ } catch (err) {
168
+ const msg =
169
+ `Could not find a driver for automationName ` +
170
+ `'${automationName}' and platformName ${platformName}'. ` +
171
+ `Have you installed a driver that supports those ` +
172
+ `capabilities? Run 'appium driver list --installed' to see. ` +
173
+ `(Lower-level error: ${err.message})`;
174
+ throw new Error(msg);
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Given an automation name and platform name, find a suitable driver and return its extension data.
180
+ * @param {string} matchAutomationName
181
+ * @param {string} matchPlatformName
182
+ * @returns {ExtMetadata<DriverType> & import('appium/types').InternalMetadata & import('appium/types').CommonExtMetadata}
183
+ */
184
+ _getDriverBySupport(matchAutomationName, matchPlatformName) {
185
+ const drivers = this.installedExtensions;
186
+ for (const [driverName, driverData] of _.toPairs(drivers)) {
187
+ const {automationName, platformNames} = driverData;
188
+ const aNameMatches = automationName.toLowerCase() === matchAutomationName.toLowerCase();
189
+ const pNameMatches = _.includes(
190
+ platformNames.map(_.toLower),
191
+ matchPlatformName.toLowerCase()
192
+ );
193
+
194
+ if (aNameMatches && pNameMatches) {
195
+ return {driverName, ...driverData};
196
+ }
197
+
198
+ if (aNameMatches) {
199
+ throw new Error(
200
+ `Driver '${driverName}' supports automationName ` +
201
+ `'${automationName}', but Appium could not find ` +
202
+ `support for platformName '${matchPlatformName}'. Supported ` +
203
+ `platformNames are: ` +
204
+ JSON.stringify(platformNames)
205
+ );
206
+ }
207
+ }
208
+
209
+ throw new Error(`Could not find installed driver to support given caps`);
210
+ }
211
+ }
212
+
213
+ /**
214
+ * @template T
215
+ * @typedef {import('appium/types').ExtMetadata<T>} ExtMetadata
216
+ */
217
+
218
+ /**
219
+ * @template T
220
+ * @typedef {import('appium/types').ExtManifest<T>} ExtManifest
221
+ */
222
+
223
+ /**
224
+ * @typedef {import('appium/types').ManifestData} ManifestData
225
+ * @typedef {import('@appium/types').DriverType} DriverType
226
+ * @typedef {import('./manifest').Manifest} Manifest
227
+ */
228
+
229
+ /**
230
+ * @template T
231
+ * @typedef {import('appium/types').ExtRecord<T>} ExtRecord
232
+ */
233
+
234
+ /**
235
+ * @template T
236
+ * @typedef {import('appium/types').ExtName<T>} ExtName
237
+ */
238
+
239
+ /**
240
+ * Return value of {@linkcode DriverConfig.findMatchingDriver}
241
+ * @typedef MatchedDriver
242
+ * @property {import('@appium/types').DriverClass} driver
243
+ * @property {string} version
244
+ * @property {string} driverName
245
+ */
246
+
247
+ /**
248
+ * @typedef {import('@appium/types').Capabilities} Capabilities
249
+ */