1 | ;
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.inspectObject = inspectObject;
|
9 | exports.parseCapsForInnerDriver = parseCapsForInnerDriver;
|
10 | exports.insertAppiumPrefixes = insertAppiumPrefixes;
|
11 | exports.getPackageVersion = getPackageVersion;
|
12 | exports.pullSettings = pullSettings;
|
13 | exports.rootDir = void 0;
|
14 |
|
15 | require("source-map-support/register");
|
16 |
|
17 | var _lodash = _interopRequireDefault(require("lodash"));
|
18 |
|
19 | var _logger = _interopRequireDefault(require("./logger"));
|
20 |
|
21 | var _appiumBaseDriver = require("appium-base-driver");
|
22 |
|
23 | var _findRoot = _interopRequireDefault(require("find-root"));
|
24 |
|
25 | const W3C_APPIUM_PREFIX = 'appium';
|
26 |
|
27 | function inspectObject(args) {
|
28 | function getValueArray(obj, indent = ' ') {
|
29 | if (!_lodash.default.isObject(obj)) {
|
30 | return [obj];
|
31 | }
|
32 |
|
33 | let strArr = ['{'];
|
34 |
|
35 | for (let [arg, value] of _lodash.default.toPairs(obj)) {
|
36 | if (!_lodash.default.isObject(value)) {
|
37 | strArr.push(`${indent} ${arg}: ${value}`);
|
38 | } else {
|
39 | value = getValueArray(value, `${indent} `);
|
40 | strArr.push(`${indent} ${arg}: ${value.shift()}`);
|
41 | strArr.push(...value);
|
42 | }
|
43 | }
|
44 |
|
45 | strArr.push(`${indent}}`);
|
46 | return strArr;
|
47 | }
|
48 |
|
49 | for (let [arg, value] of _lodash.default.toPairs(args)) {
|
50 | value = getValueArray(value);
|
51 |
|
52 | _logger.default.info(` ${arg}: ${value.shift()}`);
|
53 |
|
54 | for (let val of value) {
|
55 | _logger.default.info(val);
|
56 | }
|
57 | }
|
58 | }
|
59 |
|
60 | function parseCapsForInnerDriver(jsonwpCapabilities, w3cCapabilities, constraints = {}, defaultCapabilities = {}) {
|
61 | const hasW3CCaps = _lodash.default.isPlainObject(w3cCapabilities) && (_lodash.default.has(w3cCapabilities, 'alwaysMatch') || _lodash.default.has(w3cCapabilities, 'firstMatch'));
|
62 |
|
63 | const hasJSONWPCaps = _lodash.default.isPlainObject(jsonwpCapabilities);
|
64 |
|
65 | let protocol = null;
|
66 | let desiredCaps = {};
|
67 | let processedW3CCapabilities = null;
|
68 | let processedJsonwpCapabilities = null;
|
69 |
|
70 | if (!hasJSONWPCaps && !hasW3CCaps) {
|
71 | return {
|
72 | protocol: _appiumBaseDriver.PROTOCOLS.W3C,
|
73 | error: new Error('Either JSONWP or W3C capabilities should be provided')
|
74 | };
|
75 | }
|
76 |
|
77 | const {
|
78 | W3C,
|
79 | MJSONWP
|
80 | } = _appiumBaseDriver.PROTOCOLS;
|
81 | jsonwpCapabilities = _lodash.default.cloneDeep(jsonwpCapabilities);
|
82 | w3cCapabilities = _lodash.default.cloneDeep(w3cCapabilities);
|
83 | defaultCapabilities = _lodash.default.cloneDeep(defaultCapabilities);
|
84 |
|
85 | if (!_lodash.default.isEmpty(defaultCapabilities)) {
|
86 | if (hasW3CCaps) {
|
87 | for (const [defaultCapKey, defaultCapValue] of _lodash.default.toPairs(defaultCapabilities)) {
|
88 | let isCapAlreadySet = false;
|
89 |
|
90 | for (const firstMatchEntry of w3cCapabilities.firstMatch || []) {
|
91 | if (_lodash.default.isPlainObject(firstMatchEntry) && _lodash.default.has(removeW3CPrefixes(firstMatchEntry), removeW3CPrefix(defaultCapKey))) {
|
92 | isCapAlreadySet = true;
|
93 | break;
|
94 | }
|
95 | }
|
96 |
|
97 | isCapAlreadySet = isCapAlreadySet || _lodash.default.isPlainObject(w3cCapabilities.alwaysMatch) && _lodash.default.has(removeW3CPrefixes(w3cCapabilities.alwaysMatch), removeW3CPrefix(defaultCapKey));
|
98 |
|
99 | if (isCapAlreadySet) {
|
100 | continue;
|
101 | }
|
102 |
|
103 | if (_lodash.default.isEmpty(w3cCapabilities.firstMatch)) {
|
104 | w3cCapabilities.firstMatch = [{
|
105 | [defaultCapKey]: defaultCapValue
|
106 | }];
|
107 | } else {
|
108 | w3cCapabilities.firstMatch[0][defaultCapKey] = defaultCapValue;
|
109 | }
|
110 | }
|
111 | }
|
112 |
|
113 | if (hasJSONWPCaps) {
|
114 | jsonwpCapabilities = Object.assign({}, removeW3CPrefixes(defaultCapabilities), jsonwpCapabilities);
|
115 | }
|
116 | }
|
117 |
|
118 | if (hasJSONWPCaps) {
|
119 | protocol = MJSONWP;
|
120 | desiredCaps = jsonwpCapabilities;
|
121 | processedJsonwpCapabilities = removeW3CPrefixes({ ...desiredCaps
|
122 | });
|
123 | }
|
124 |
|
125 | if (hasW3CCaps) {
|
126 | protocol = W3C;
|
127 | let isFixingNeededForW3cCaps = false;
|
128 |
|
129 | try {
|
130 | desiredCaps = (0, _appiumBaseDriver.processCapabilities)(w3cCapabilities, constraints, true);
|
131 | } catch (error) {
|
132 | if (!hasJSONWPCaps) {
|
133 | return {
|
134 | desiredCaps,
|
135 | processedJsonwpCapabilities,
|
136 | processedW3CCapabilities,
|
137 | protocol,
|
138 | error
|
139 | };
|
140 | }
|
141 |
|
142 | _logger.default.info(`Could not parse W3C capabilities: ${error.message}`);
|
143 |
|
144 | isFixingNeededForW3cCaps = true;
|
145 | }
|
146 |
|
147 | if (hasJSONWPCaps && !isFixingNeededForW3cCaps) {
|
148 | const differingKeys = _lodash.default.difference(_lodash.default.keys(processedJsonwpCapabilities), _lodash.default.keys(removeW3CPrefixes(desiredCaps)));
|
149 |
|
150 | if (!_lodash.default.isEmpty(differingKeys)) {
|
151 | _logger.default.info(`The following capabilities were provided in the JSONWP desired capabilities that are missing ` + `in W3C capabilities: ${JSON.stringify(differingKeys)}`);
|
152 |
|
153 | isFixingNeededForW3cCaps = true;
|
154 | }
|
155 | }
|
156 |
|
157 | if (isFixingNeededForW3cCaps && hasJSONWPCaps) {
|
158 | _logger.default.info('Trying to fix W3C capabilities by merging them with JSONWP caps');
|
159 |
|
160 | w3cCapabilities = fixW3cCapabilities(w3cCapabilities, jsonwpCapabilities);
|
161 |
|
162 | try {
|
163 | desiredCaps = (0, _appiumBaseDriver.processCapabilities)(w3cCapabilities, constraints, true);
|
164 | } catch (error) {
|
165 | _logger.default.warn(`Could not parse fixed W3C capabilities: ${error.message}. Falling back to JSONWP protocol`);
|
166 |
|
167 | return {
|
168 | desiredCaps: processedJsonwpCapabilities,
|
169 | processedJsonwpCapabilities,
|
170 | processedW3CCapabilities: null,
|
171 | protocol: MJSONWP
|
172 | };
|
173 | }
|
174 | }
|
175 |
|
176 | processedW3CCapabilities = {
|
177 | alwaysMatch: { ...insertAppiumPrefixes(desiredCaps)
|
178 | },
|
179 | firstMatch: [{}]
|
180 | };
|
181 | }
|
182 |
|
183 | return {
|
184 | desiredCaps,
|
185 | processedJsonwpCapabilities,
|
186 | processedW3CCapabilities,
|
187 | protocol
|
188 | };
|
189 | }
|
190 |
|
191 | function fixW3cCapabilities(w3cCaps, jsonwpCaps) {
|
192 | const result = {
|
193 | firstMatch: w3cCaps.firstMatch || [],
|
194 | alwaysMatch: w3cCaps.alwaysMatch || {}
|
195 | };
|
196 |
|
197 | const keysToInsert = _lodash.default.keys(jsonwpCaps);
|
198 |
|
199 | const removeMatchingKeys = match => {
|
200 | _lodash.default.pull(keysToInsert, match);
|
201 |
|
202 | const colonIndex = match.indexOf(':');
|
203 |
|
204 | if (colonIndex >= 0 && match.length > colonIndex) {
|
205 | _lodash.default.pull(keysToInsert, match.substring(colonIndex + 1));
|
206 | }
|
207 |
|
208 | if (keysToInsert.includes(`${W3C_APPIUM_PREFIX}:${match}`)) {
|
209 | _lodash.default.pull(keysToInsert, `${W3C_APPIUM_PREFIX}:${match}`);
|
210 | }
|
211 | };
|
212 |
|
213 | for (const firstMatchEntry of result.firstMatch) {
|
214 | for (const pair of _lodash.default.toPairs(firstMatchEntry)) {
|
215 | removeMatchingKeys(pair[0]);
|
216 | }
|
217 | }
|
218 |
|
219 | for (const pair of _lodash.default.toPairs(result.alwaysMatch)) {
|
220 | removeMatchingKeys(pair[0]);
|
221 | }
|
222 |
|
223 | for (const key of keysToInsert) {
|
224 | result.alwaysMatch[key] = jsonwpCaps[key];
|
225 | }
|
226 |
|
227 | return result;
|
228 | }
|
229 |
|
230 | function insertAppiumPrefixes(caps) {
|
231 | const STANDARD_CAPS = ['browserName', 'browserVersion', 'platformName', 'acceptInsecureCerts', 'pageLoadStrategy', 'proxy', 'setWindowRect', 'timeouts', 'unhandledPromptBehavior'];
|
232 | let prefixedCaps = {};
|
233 |
|
234 | for (let [name, value] of _lodash.default.toPairs(caps)) {
|
235 | if (STANDARD_CAPS.includes(name) || name.includes(':')) {
|
236 | prefixedCaps[name] = value;
|
237 | } else {
|
238 | prefixedCaps[`${W3C_APPIUM_PREFIX}:${name}`] = value;
|
239 | }
|
240 | }
|
241 |
|
242 | return prefixedCaps;
|
243 | }
|
244 |
|
245 | function removeW3CPrefixes(caps) {
|
246 | if (!_lodash.default.isPlainObject(caps)) {
|
247 | return caps;
|
248 | }
|
249 |
|
250 | const fixedCaps = {};
|
251 |
|
252 | for (let [name, value] of _lodash.default.toPairs(caps)) {
|
253 | fixedCaps[removeW3CPrefix(name)] = value;
|
254 | }
|
255 |
|
256 | return fixedCaps;
|
257 | }
|
258 |
|
259 | function removeW3CPrefix(key) {
|
260 | const colonPos = key.indexOf(':');
|
261 | return colonPos > 0 && key.length > colonPos ? key.substring(colonPos + 1) : key;
|
262 | }
|
263 |
|
264 | function getPackageVersion(pkgName) {
|
265 | const pkgInfo = require(`${pkgName}/package.json`) || {};
|
266 | return pkgInfo.version;
|
267 | }
|
268 |
|
269 | function pullSettings(caps) {
|
270 | if (!_lodash.default.isPlainObject(caps) || _lodash.default.isEmpty(caps)) {
|
271 | return {};
|
272 | }
|
273 |
|
274 | const result = {};
|
275 |
|
276 | for (const [key, value] of _lodash.default.toPairs(caps)) {
|
277 | const match = /\bsettings\[(\S+)\]$/.exec(key);
|
278 |
|
279 | if (!match) {
|
280 | continue;
|
281 | }
|
282 |
|
283 | result[match[1]] = value;
|
284 | delete caps[key];
|
285 | }
|
286 |
|
287 | return result;
|
288 | }
|
289 |
|
290 | const rootDir = (0, _findRoot.default)(__dirname);
|
291 | exports.rootDir = rootDir;require('source-map-support').install();
|
292 |
|
293 |
|
294 | //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImxpYi91dGlscy5qcyJdLCJuYW1lcyI6WyJXM0NfQVBQSVVNX1BSRUZJWCIsImluc3BlY3RPYmplY3QiLCJhcmdzIiwiZ2V0VmFsdWVBcnJheSIsIm9iaiIsImluZGVudCIsIl8iLCJpc09iamVjdCIsInN0ckFyciIsImFyZyIsInZhbHVlIiwidG9QYWlycyIsInB1c2giLCJzaGlmdCIsImxvZ2dlciIsImluZm8iLCJ2YWwiLCJwYXJzZUNhcHNGb3JJbm5lckRyaXZlciIsImpzb253cENhcGFiaWxpdGllcyIsInczY0NhcGFiaWxpdGllcyIsImNvbnN0cmFpbnRzIiwiZGVmYXVsdENhcGFiaWxpdGllcyIsImhhc1czQ0NhcHMiLCJpc1BsYWluT2JqZWN0IiwiaGFzIiwiaGFzSlNPTldQQ2FwcyIsInByb3RvY29sIiwiZGVzaXJlZENhcHMiLCJwcm9jZXNzZWRXM0NDYXBhYmlsaXRpZXMiLCJwcm9jZXNzZWRKc29ud3BDYXBhYmlsaXRpZXMiLCJQUk9UT0NPTFMiLCJXM0MiLCJlcnJvciIsIkVycm9yIiwiTUpTT05XUCIsImNsb25lRGVlcCIsImlzRW1wdHkiLCJkZWZhdWx0Q2FwS2V5IiwiZGVmYXVsdENhcFZhbHVlIiwiaXNDYXBBbHJlYWR5U2V0IiwiZmlyc3RNYXRjaEVudHJ5IiwiZmlyc3RNYXRjaCIsInJlbW92ZVczQ1ByZWZpeGVzIiwicmVtb3ZlVzNDUHJlZml4IiwiYWx3YXlzTWF0Y2giLCJPYmplY3QiLCJhc3NpZ24iLCJpc0ZpeGluZ05lZWRlZEZvclczY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