appium-xcuitest-driver 7.21.1 → 7.22.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/lib/commands/context.d.ts.map +1 -1
  3. package/build/lib/commands/context.js +6 -3
  4. package/build/lib/commands/context.js.map +1 -1
  5. package/build/lib/commands/log.d.ts.map +1 -1
  6. package/build/lib/commands/log.js +30 -16
  7. package/build/lib/commands/log.js.map +1 -1
  8. package/build/lib/device-log/helpers.d.ts +4 -1
  9. package/build/lib/device-log/helpers.d.ts.map +1 -1
  10. package/build/lib/device-log/helpers.js +6 -2
  11. package/build/lib/device-log/helpers.js.map +1 -1
  12. package/build/lib/device-log/ios-crash-log.d.ts +0 -4
  13. package/build/lib/device-log/ios-crash-log.d.ts.map +1 -1
  14. package/build/lib/device-log/ios-crash-log.js +0 -8
  15. package/build/lib/device-log/ios-crash-log.js.map +1 -1
  16. package/build/lib/device-log/ios-device-log.d.ts +16 -10
  17. package/build/lib/device-log/ios-device-log.d.ts.map +1 -1
  18. package/build/lib/device-log/ios-device-log.js +9 -24
  19. package/build/lib/device-log/ios-device-log.js.map +1 -1
  20. package/build/lib/device-log/ios-log.d.ts +21 -44
  21. package/build/lib/device-log/ios-log.d.ts.map +1 -1
  22. package/build/lib/device-log/ios-log.js +16 -77
  23. package/build/lib/device-log/ios-log.js.map +1 -1
  24. package/build/lib/device-log/ios-performance-log.d.ts +14 -26
  25. package/build/lib/device-log/ios-performance-log.d.ts.map +1 -1
  26. package/build/lib/device-log/ios-performance-log.js +16 -42
  27. package/build/lib/device-log/ios-performance-log.js.map +1 -1
  28. package/build/lib/device-log/ios-simulator-log.d.ts +21 -24
  29. package/build/lib/device-log/ios-simulator-log.d.ts.map +1 -1
  30. package/build/lib/device-log/ios-simulator-log.js +18 -36
  31. package/build/lib/device-log/ios-simulator-log.js.map +1 -1
  32. package/build/lib/device-log/line-consuming-log.d.ts +9 -0
  33. package/build/lib/device-log/line-consuming-log.d.ts.map +1 -0
  34. package/build/lib/device-log/line-consuming-log.js +16 -0
  35. package/build/lib/device-log/line-consuming-log.js.map +1 -0
  36. package/build/lib/device-log/safari-console-log.d.ts +65 -6
  37. package/build/lib/device-log/safari-console-log.d.ts.map +1 -1
  38. package/build/lib/device-log/safari-console-log.js +61 -81
  39. package/build/lib/device-log/safari-console-log.js.map +1 -1
  40. package/build/lib/device-log/safari-network-log.d.ts +36 -8
  41. package/build/lib/device-log/safari-network-log.d.ts.map +1 -1
  42. package/build/lib/device-log/safari-network-log.js +28 -151
  43. package/build/lib/device-log/safari-network-log.js.map +1 -1
  44. package/lib/commands/context.js +6 -3
  45. package/lib/commands/log.js +35 -16
  46. package/lib/device-log/helpers.ts +6 -2
  47. package/lib/device-log/ios-crash-log.js +0 -9
  48. package/lib/device-log/ios-device-log.ts +52 -0
  49. package/lib/device-log/ios-log.ts +70 -0
  50. package/lib/device-log/ios-performance-log.ts +50 -0
  51. package/lib/device-log/{ios-simulator-log.js → ios-simulator-log.ts} +40 -43
  52. package/lib/device-log/line-consuming-log.ts +16 -0
  53. package/lib/device-log/safari-console-log.ts +112 -0
  54. package/lib/device-log/safari-network-log.ts +80 -0
  55. package/npm-shrinkwrap.json +69 -24
  56. package/package.json +2 -2
  57. package/build/lib/device-log/rotating-log.d.ts +0 -21
  58. package/build/lib/device-log/rotating-log.d.ts.map +0 -1
  59. package/build/lib/device-log/rotating-log.js +0 -61
  60. package/build/lib/device-log/rotating-log.js.map +0 -1
  61. package/lib/device-log/ios-device-log.js +0 -56
  62. package/lib/device-log/ios-log.js +0 -116
  63. package/lib/device-log/ios-performance-log.js +0 -68
  64. package/lib/device-log/rotating-log.js +0 -65
  65. package/lib/device-log/safari-console-log.js +0 -96
  66. package/lib/device-log/safari-network-log.js +0 -193
@@ -4,93 +4,73 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SafariConsoleLog = void 0;
7
- const rotating_log_1 = require("./rotating-log");
8
7
  const lodash_1 = __importDefault(require("lodash"));
9
- const support_1 = require("appium/support");
10
- class SafariConsoleLog extends rotating_log_1.RotatingLog {
11
- constructor(showLogs) {
12
- super(showLogs, 'SafariConsole');
13
- // js console has `warning` level, so map to `warn`
14
- this.log = new Proxy(this.log, {
15
- get(target, prop, receiver) {
16
- return Reflect.get(target, prop === 'warning' ? 'warn' : prop, receiver);
17
- },
8
+ const helpers_1 = require("./helpers");
9
+ const ios_log_1 = __importDefault(require("./ios-log"));
10
+ const LOG_LEVELS_MAP = {
11
+ error: 'SEVERE',
12
+ warning: 'WARNING',
13
+ log: 'FINE',
14
+ };
15
+ class SafariConsoleLog extends ios_log_1.default {
16
+ constructor(opts) {
17
+ super({
18
+ log: opts.log,
19
+ maxBufferSize: helpers_1.MAX_BUFFERED_EVENTS_COUNT,
18
20
  });
21
+ this._showLogs = opts.showLogs;
19
22
  }
20
- addLogLine(err, out) {
21
- if (this.isCapturing) {
22
- this.logs = this.logs || [];
23
- while (this.logs.length >= rotating_log_1.MAX_LOG_ENTRIES_COUNT) {
24
- this.logs.shift();
25
- if (this.logIdxSinceLastRequest > 0) {
26
- this.logIdxSinceLastRequest--;
27
- }
28
- }
29
- /*
30
- * The output will be like:
31
- * {
32
- * "source": "javascript",
33
- * "level":"error",
34
- * "text":"ReferenceError: Can't find variable: s_account",
35
- * "type":"log",
36
- * "line":2,
37
- * "column":21,
38
- * "url":"https://assets.adobedtm.com/b46e318d845250834eda10c5a20827c045a4d76f/scripts/satellite-57866f8b64746d53a8000104-staging.js",
39
- * "repeatCount":1,
40
- * "stackTrace":[{
41
- * "functionName":"global code",
42
- * "url":"https://assets.adobedtm.com/b46e318d845250834eda10c5a20827c045a4d76f/scripts/satellite-57866f8b64746d53a8000104-staging.js",
43
- * "scriptId":"6",
44
- * "lineNumber":2,
45
- * "columnNumber":21
46
- * }]
47
- * }
48
- *
49
- * we need, at least, `level` (in accordance with Java levels
50
- * (https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html)),
51
- * `timestamp`, and `message` to satisfy the java client. In order to
52
- * provide all the information to the client, `message` is the full
53
- * object, stringified.
54
- */
55
- const entry = {
56
- level: {
57
- error: 'SEVERE',
58
- warning: 'WARNING',
59
- log: 'FINE',
60
- }[out.level] || 'INFO',
61
- timestamp: Date.now(),
62
- message: JSON.stringify(out),
63
- };
64
- this.logs.push(entry);
65
- }
66
- if (lodash_1.default.has(out, 'count')) {
67
- // this is a notification of the previous message being repeated
68
- // this should _never_ be the first message, so the previous one ought to
69
- // be populated. If it is not, nothing will break, it will just look odd
70
- // in the output below (no url or line numbers)
71
- const count = out.count;
72
- out = this._previousOutput || {};
73
- out.text = `Previous message repeated ${support_1.util.pluralize('time', count, true)}`;
74
- }
75
- else {
76
- // save the most recent output
77
- this._previousOutput = out;
78
- }
79
- // format output like
80
- // SafariConsole [WARNING][http://appium.io 2:13] Log something to warn
81
- if (this.showLogs) {
82
- let level = 'debug';
83
- if (out.level === 'warning' || out.level === 'error') {
84
- level = out.level;
85
- }
86
- for (const line of out.text.split('\n')) {
87
- // url is optional, so get formatting here
88
- const url = out.url ? `${out.url} ` : '';
89
- this.log[level](`[${level.toUpperCase()}][${url}${out.line}:${out.column}] ${line}`);
90
- }
23
+ async startCapture() { }
24
+ async stopCapture() { }
25
+ get isCapturing() {
26
+ return true;
27
+ }
28
+ /**
29
+ *
30
+ * @param err
31
+ * @param entry The output will be like:
32
+ * {
33
+ * "source": "javascript",
34
+ * "level":"error",
35
+ * "text":"ReferenceError: Can't find variable: s_account",
36
+ * "type":"log",
37
+ * "line":2,
38
+ * "column":21,
39
+ * "url":"https://assets.adobedtm.com/b46e318d845250834eda10c5a20827c045a4d76f/scripts/satellite-57866f8b64746d53a8000104-staging.js",
40
+ * "repeatCount":1,
41
+ * "stackTrace":[{
42
+ * "functionName":"global code",
43
+ * "url":"https://assets.adobedtm.com/b46e318d845250834eda10c5a20827c045a4d76f/scripts/satellite-57866f8b64746d53a8000104-staging.js",
44
+ * "scriptId":"6",
45
+ * "lineNumber":2,
46
+ * "columnNumber":21
47
+ * }]
48
+ * }
49
+ *
50
+ * we need, at least, `level` (in accordance with Java levels
51
+ * (https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html)),
52
+ * `timestamp`, and `message` to satisfy the java client. In order to
53
+ * provide all the information to the client, `message` is the full
54
+ * object, stringified.
55
+ *
56
+ */
57
+ onConsoleLogEvent(err, entry) {
58
+ this.broadcast(entry);
59
+ if (this._showLogs) {
60
+ this.log.info(`[SafariConsole] ${lodash_1.default.truncate(JSON.stringify(entry), { length: helpers_1.MAX_JSON_LOG_LENGTH })}`);
91
61
  }
92
62
  }
63
+ _serializeEntry(value) {
64
+ return [value, Date.now()];
65
+ }
66
+ _deserializeEntry(value) {
67
+ const [entry, timestamp] = value;
68
+ return (0, helpers_1.toLogEntry)(JSON.stringify(entry), timestamp, mapLogLevel(entry.level));
69
+ }
93
70
  }
94
71
  exports.SafariConsoleLog = SafariConsoleLog;
72
+ function mapLogLevel(originalLevel) {
73
+ return LOG_LEVELS_MAP[originalLevel] ?? helpers_1.DEFAULT_LOG_LEVEL;
74
+ }
95
75
  exports.default = SafariConsoleLog;
96
76
  //# sourceMappingURL=safari-console-log.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"safari-console-log.js","sourceRoot":"","sources":["../../../lib/device-log/safari-console-log.js"],"names":[],"mappings":";;;;;;AAAA,iDAAkE;AAClE,oDAAuB;AACvB,4CAAoC;AAEpC,MAAM,gBAAiB,SAAQ,0BAAW;IACxC,YAAY,QAAQ;QAClB,KAAK,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QAEjC,mDAAmD;QACnD,IAAI,CAAC,GAAG,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YAC7B,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;gBACxB,OAAO,OAAO,CAAC,GAAG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E,mCAAyB;SACzC,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEQ,KAAK,CAAC,YAAY,KAAmB,CAAC;IACtC,KAAK,CAAC,WAAW,KAAmB,CAAC;IAC9C,IAAa,WAAW;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,iBAAiB,CAAC,GAAkB,EAAE,KAAyB;QAC7D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACtB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,gBAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,EAAC,MAAM,EAAE,6BAAmB,EAAC,CAAC,EAAE,CAAC,CAAC;QACvG,CAAC;IACH,CAAC;IAEkB,eAAe,CAAC,KAAyB;QAC1D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC7B,CAAC;IAEkB,iBAAiB,CAAC,KAAuB;QAC1D,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;QACjC,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAChF,CAAC;CACF;AA7DD,4CA6DC;AAED,SAAS,WAAW,CAAC,aAAqB;IACxC,OAAO,cAAc,CAAC,aAAa,CAAC,IAAI,2BAAiB,CAAC;AAC5D,CAAC;AAED,kBAAe,gBAAgB,CAAC"}
@@ -1,10 +1,38 @@
1
+ import { LineConsumingLog } from './line-consuming-log';
2
+ import type { AppiumLogger } from '@appium/types';
3
+ export interface SafariConsoleLogOptions {
4
+ showLogs: boolean;
5
+ log: AppiumLogger;
6
+ }
7
+ export interface SafariNetworkResponseTiming {
8
+ responseStart: number;
9
+ receiveHeadersEnd: number;
10
+ }
11
+ export interface SafariNetworkResponse {
12
+ url: string;
13
+ status: number;
14
+ timing: SafariNetworkResponseTiming;
15
+ source: string;
16
+ }
17
+ export interface SafariNetworkLogEntryMetrics {
18
+ responseBodyBytesReceived: number;
19
+ }
20
+ export interface SafariNetworkLogEntry {
21
+ requestId: string;
22
+ response?: SafariNetworkResponse;
23
+ type?: string;
24
+ initiator?: string;
25
+ metrics?: SafariNetworkLogEntryMetrics;
26
+ errorText?: string;
27
+ canceled?: boolean;
28
+ }
29
+ export declare class SafariNetworkLog extends LineConsumingLog {
30
+ private readonly _showLogs;
31
+ constructor(opts: SafariConsoleLogOptions);
32
+ startCapture(): Promise<void>;
33
+ stopCapture(): Promise<void>;
34
+ get isCapturing(): boolean;
35
+ onNetworkEvent(method: string, entry: SafariNetworkLogEntry): void;
36
+ }
1
37
  export default SafariNetworkLog;
2
- export class SafariNetworkLog extends RotatingLog {
3
- constructor(showLogs: any);
4
- getEntry(requestId: any): any;
5
- addLogLine(method: any, out: any): void;
6
- getLogDetails(outputEntry: any): any;
7
- printLogLine(outputEntry: any): void;
8
- }
9
- import { RotatingLog } from './rotating-log';
10
38
  //# sourceMappingURL=safari-network-log.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"safari-network-log.d.ts","sourceRoot":"","sources":["../../../lib/device-log/safari-network-log.js"],"names":[],"mappings":";AAKA;IACE,2BAEC;IAED,8BA6CC;IAED,wCAmCC;IAED,qCAsCC;IAED,qCAwCC;CAeF;4BA1LgD,gBAAgB"}
1
+ {"version":3,"file":"safari-network-log.d.ts","sourceRoot":"","sources":["../../../lib/device-log/safari-network-log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAYlD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,YAAY,CAAC;CACnB;AAED,MAAM,WAAW,2BAA2B;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,2BAA2B,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,4BAA4B;IAC3C,yBAAyB,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,OAAO,CAAC,EAAE,4BAA4B,CAAC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,gBAAiB,SAAQ,gBAAgB;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAU;gBAExB,IAAI,EAAE,uBAAuB;IAQ1B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAC7B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAC3C,IAAa,WAAW,IAAI,OAAO,CAElC;IAED,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,GAAG,IAAI;CAWnE;AAED,eAAe,gBAAgB,CAAC"}
@@ -5,163 +5,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SafariNetworkLog = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
- const url_1 = __importDefault(require("url"));
9
- const support_1 = require("appium/support");
10
- const rotating_log_1 = require("./rotating-log");
11
- class SafariNetworkLog extends rotating_log_1.RotatingLog {
12
- constructor(showLogs) {
13
- super(showLogs, 'SafariNetwork');
8
+ const line_consuming_log_1 = require("./line-consuming-log");
9
+ const helpers_1 = require("./helpers");
10
+ const EVENTS_TO_LOG = [
11
+ 'Network.loadingFinished',
12
+ 'Network.loadingFailed',
13
+ ];
14
+ const MONITORED_EVENTS = [
15
+ 'Network.requestWillBeSent',
16
+ 'Network.responseReceived',
17
+ ...EVENTS_TO_LOG,
18
+ ];
19
+ class SafariNetworkLog extends line_consuming_log_1.LineConsumingLog {
20
+ constructor(opts) {
21
+ super({
22
+ log: opts.log,
23
+ maxBufferSize: helpers_1.MAX_BUFFERED_EVENTS_COUNT,
24
+ });
25
+ this._showLogs = opts.showLogs;
14
26
  }
15
- getEntry(requestId) {
16
- let outputEntry;
17
- while (this.logs.length >= rotating_log_1.MAX_LOG_ENTRIES_COUNT) {
18
- // pull the first entry, which is the oldest
19
- const entry = this.logs.shift();
20
- if (entry && entry.requestId === requestId) {
21
- // we are adding to an existing entry, and it was almost removed
22
- // add to the end of the list and try again
23
- outputEntry = entry;
24
- this.logs.push(outputEntry);
25
- continue;
26
- }
27
- // we've removed an element, so the count is down one
28
- if (this.logIdxSinceLastRequest > 0) {
29
- this.logIdxSinceLastRequest--;
30
- }
31
- }
32
- if (!outputEntry) {
33
- // we do not yes have an entry to associate this bit of output with
34
- // most likely the entry will be at the end of the list, so start there
35
- for (let i = this.logs.length - 1; i >= 0; i--) {
36
- if (this.logs[i].requestId === requestId) {
37
- // found it!
38
- outputEntry = this.logs[i];
39
- // this is now the most current entry, so remove it from the list
40
- // to be added to the end below
41
- this.logs.splice(i, 1);
42
- break;
43
- }
44
- }
45
- // nothing has been found, so create a new entry
46
- if (!outputEntry) {
47
- outputEntry = {
48
- requestId,
49
- logs: [],
50
- };
51
- }
52
- // finally, add the entry to the end of the list
53
- this.logs.push(outputEntry);
54
- }
55
- return outputEntry;
27
+ async startCapture() { }
28
+ async stopCapture() { }
29
+ get isCapturing() {
30
+ return true;
56
31
  }
57
- addLogLine(method, out) {
58
- if (!this.isCapturing && !this.showLogs) {
59
- // neither capturing nor displaying, so do nothing
60
- return;
61
- }
62
- if (['Network.dataReceived'].includes(method)) {
63
- // status update, no need to handle
64
- return;
65
- }
66
- // events we care about:
67
- // Network.requestWillBeSent
68
- // Network.responseReceived
69
- // Network.loadingFinished
70
- // Network.loadingFailed
71
- const outputEntry = this.getEntry(out.requestId);
72
- if (this.isCapturing) {
73
- // now add the output we just received to the logs for this particular entry
74
- outputEntry.logs = outputEntry.logs || [];
75
- outputEntry.logs.push(out);
76
- }
77
- // if we are not displaying the logs,
78
- // or we are not finished getting events for this network call,
79
- // we are done
80
- if (!this.showLogs) {
32
+ onNetworkEvent(method, entry) {
33
+ if (!MONITORED_EVENTS.includes(method)) {
81
34
  return;
82
35
  }
83
- if (method === 'Network.loadingFinished' || method === 'Network.loadingFailed') {
84
- this.printLogLine(outputEntry);
36
+ const serializedEntry = JSON.stringify(entry);
37
+ this.broadcast(serializedEntry);
38
+ if (this._showLogs && EVENTS_TO_LOG.includes(method)) {
39
+ this.log.info(`[SafariNetwork] ${lodash_1.default.truncate(serializedEntry, { length: helpers_1.MAX_JSON_LOG_LENGTH })}`);
85
40
  }
86
41
  }
87
- getLogDetails(outputEntry) {
88
- // extract the data
89
- const record = outputEntry.logs.reduce(function getRecord(record, entry) {
90
- record.requestId = entry.requestId;
91
- if (entry.response) {
92
- const url = url_1.default.parse(entry.response.url);
93
- // get the last part of the url, along with the query string, if possible
94
- record.name =
95
- `${lodash_1.default.last(String(url.pathname).split('/'))}${url.search ? `?${url.search}` : ''}` ||
96
- url.host;
97
- record.status = entry.response.status;
98
- if (entry.response.timing) {
99
- record.time =
100
- entry.response.timing.receiveHeadersEnd || entry.response.timing.responseStart || 0;
101
- }
102
- record.source = entry.response.source;
103
- }
104
- if (entry.type) {
105
- record.type = entry.type;
106
- }
107
- if (entry.initiator) {
108
- record.initiator = entry.initiator;
109
- }
110
- if (entry.metrics) {
111
- // Safari has a `metrics` object on it's `Network.loadingFinished` event
112
- record.size = entry.metrics.responseBodyBytesReceived || 0;
113
- }
114
- if (entry.errorText) {
115
- record.errorText = entry.errorText;
116
- // When a network call is cancelled, Safari returns `cancelled` as error text
117
- // but has a boolean `canceled`. Normalize the two spellings in favor of
118
- // the text, which will also be displayed
119
- record.cancelled = entry.canceled;
120
- }
121
- return record;
122
- }, {});
123
- return record;
124
- }
125
- printLogLine(outputEntry) {
126
- const { requestId, name, status, type, initiator = {}, size = 0, time = 0, source, errorText, cancelled = false, } = this.getLogDetails(outputEntry);
127
- // print out the record, formatted appropriately
128
- this.log.debug(`Network event:`);
129
- this.log.debug(` Id: ${requestId}`);
130
- this.log.debug(` Name: ${name}`);
131
- this.log.debug(` Status: ${status}`);
132
- this.log.debug(` Type: ${type}`);
133
- this.log.debug(` Initiator: ${initiator.type}`);
134
- for (const line of initiator.stackTrace || []) {
135
- const functionName = line.functionName || '(anonymous)';
136
- const url = !line.url || line.url === '[native code]'
137
- ? ''
138
- : `@${lodash_1.default.last((url_1.default.parse(line.url).pathname || '').split('/'))}:${line.lineNumber}`;
139
- this.log.debug(` ${lodash_1.default.padEnd(lodash_1.default.truncate(functionName, { length: 20 }), 21)} ${url}`);
140
- }
141
- // get `memory-cache` or `disk-cache`, etc., right
142
- const sizeStr = source.includes('cache') ? ` (from ${source.replace('-', ' ')})` : `${size}B`;
143
- this.log.debug(` Size: ${sizeStr}`);
144
- this.log.debug(` Time: ${Math.round(time)}ms`);
145
- if (errorText) {
146
- this.log.debug(` Error: ${errorText}`);
147
- }
148
- if (support_1.util.hasValue(cancelled)) {
149
- this.log.debug(` Cancelled: ${cancelled}`);
150
- }
151
- }
152
- async getLogs() {
153
- const logs = await super.getLogs();
154
- // in order to satisfy certain clients, we need to have a basic structure
155
- // to the results, with `level`, `timestamp`, and `message`, which is
156
- // all the information stringified
157
- return logs.map(function adjustEntry(entry) {
158
- return Object.assign({}, entry, {
159
- level: 'INFO',
160
- timestamp: Date.now(),
161
- message: JSON.stringify(entry),
162
- });
163
- });
164
- }
165
42
  }
166
43
  exports.SafariNetworkLog = SafariNetworkLog;
167
44
  exports.default = SafariNetworkLog;
@@ -1 +1 @@
1
- {"version":3,"file":"safari-network-log.js","sourceRoot":"","sources":["../../../lib/device-log/safari-network-log.js"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,8CAAsB;AACtB,4CAAoC;AACpC,iDAAkE;AAElE,MAAM,gBAAiB,SAAQ,0BAAW;IACxC,YAAY,QAAQ;QAClB,KAAK,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,QAAQ,CAAC,SAAS;QAChB,IAAI,WAAW,CAAC;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,oCAAqB,EAAE,CAAC;YACjD,4CAA4C;YAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,KAAK,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC3C,gEAAgE;gBAChE,2CAA2C;gBAC3C,WAAW,GAAG,KAAK,CAAC;gBACpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC5B,SAAS;YACX,CAAC;YACD,qDAAqD;YACrD,IAAI,IAAI,CAAC,sBAAsB,GAAG,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAChC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,mEAAmE;YACnE,uEAAuE;YACvE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/C,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;oBACzC,YA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,gBAAgB,SAAS,EAAE,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QACnC,yEAAyE;QACzE,qEAAqE;QACrE,kCAAkC;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,WAAW,CAAC,KAAK;YACxC,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE;gBAC9B,KAAK,EAAE,MAAM;gBACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;gBACrB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;aAC/B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAEO,4CAAgB;AACxB,kBAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"safari-network-log.js","sourceRoot":"","sources":["../../../lib/device-log/safari-network-log.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,6DAAwD;AACxD,uCAA2E;AAG3E,MAAM,aAAa,GAAG;IACpB,yBAAyB;IACzB,uBAAuB;CACxB,CAAC;AACF,MAAM,gBAAgB,GAAG;IACvB,2BAA2B;IAC3B,0BAA0B;IAC1B,GAAG,aAAa;CACjB,CAAC;AAoCF,MAAa,gBAAiB,SAAQ,qCAAgB;IAGpD,YAAY,IAA6B;QACvC,KAAK,CAAC;YACJ,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,aAAa,EAAE,mCAAyB;SACzC,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEQ,KAAK,CAAC,YAAY,KAAmB,CAAC;IACtC,KAAK,CAAC,WAAW,KAAmB,CAAC;IAC9C,IAAa,WAAW;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,cAAc,CAAC,MAAc,EAAE,KAA4B;QACzD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACvC,OAAO;QACT,CAAC;QAED,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QAChC,IAAI,IAAI,CAAC,SAAS,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACrD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,gBAAC,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAC,MAAM,EAAE,6BAAmB,EAAC,CAAC,EAAE,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;CACF;AA5BD,4CA4BC;AAED,kBAAe,gBAAgB,CAAC"}
@@ -558,7 +558,10 @@ const commands = {
558
558
  // attempt to start performance logging, if requested
559
559
  if (this.opts.enablePerformanceLogging && this.remote) {
560
560
  this.log.debug(`Starting performance log on '${this.curContext}'`);
561
- this.logs.performance = new IOSPerformanceLog(this.remote);
561
+ this.logs.performance = new IOSPerformanceLog({
562
+ remoteDebugger: this.remote,
563
+ log: this.log,
564
+ });
562
565
  await this.logs.performance.startCapture();
563
566
  }
564
567
 
@@ -566,12 +569,12 @@ const commands = {
566
569
  if (name && name !== NATIVE_WIN && this.logs) {
567
570
  if (this.logs.safariConsole) {
568
571
  await this.remote.startConsole(
569
- this.logs.safariConsole.addLogLine.bind(this.logs.safariConsole),
572
+ this.logs.safariConsole.onConsoleLogEvent.bind(this.logs.safariConsole),
570
573
  );
571
574
  }
572
575
  if (this.logs.safariNetwork) {
573
576
  await this.remote.startNetwork(
574
- this.logs.safariNetwork.addLogLine.bind(this.logs.safariNetwork),
577
+ this.logs.safariNetwork.onNetworkEvent.bind(this.logs.safariNetwork),
575
578
  );
576
579
  }
577
580
  }
@@ -60,6 +60,12 @@ const SUPPORTED_LOG_TYPES = {
60
60
  },
61
61
  };
62
62
 
63
+ const LOG_NAMES_TO_CAPABILITY_NAMES_MAP = {
64
+ safariConsole: 'showSafariConsoleLog',
65
+ safariNetwork: 'showSafariNetworkLog',
66
+ enablePerformanceLogging: 'enablePerformanceLogging',
67
+ };
68
+
63
69
  export default {
64
70
  supportedLogTypes: SUPPORTED_LOG_TYPES,
65
71
  /**
@@ -77,11 +83,18 @@ export default {
77
83
 
78
84
  // If logs captured successfully send response with data, else send error
79
85
  const logObject = logsContainer[logType];
80
- const logs = logObject ? await logObject.getLogs() : null;
81
- if (logs) {
82
- return logs;
86
+ if (logObject) {
87
+ return await logObject.getLogs();
88
+ }
89
+ if (logType in LOG_NAMES_TO_CAPABILITY_NAMES_MAP) {
90
+ throw new Error(
91
+ `${logType} logs are not enabled. Make sure you've set a proper value ` +
92
+ `to the 'appium:${LOG_NAMES_TO_CAPABILITY_NAMES_MAP[logType]}' capability.`
93
+ );
83
94
  }
84
- throw new Error(`No logs of type '${String(logType)}' found.`);
95
+ throw new Error(
96
+ `No logs of type '${logType}' found. Supported log types are: ${_.keys(SUPPORTED_LOG_TYPES)}.`
97
+ );
85
98
  },
86
99
 
87
100
  /**
@@ -98,22 +111,30 @@ export default {
98
111
  sim: this.device,
99
112
  udid: this.isRealDevice() ? this.opts.udid : undefined,
100
113
  });
101
-
102
- if (this.isRealDevice()) {
103
- this.logs.syslog = new IOSDeviceLog({
114
+ this.logs.syslog = this.isRealDevice()
115
+ ? new IOSDeviceLog({
104
116
  udid: this.opts.udid,
105
117
  showLogs: this.opts.showIOSLog,
106
- });
107
- } else {
108
- this.logs.syslog = new IOSSimulatorLog({
109
- sim: this.device,
118
+ log: this.log,
119
+ })
120
+ : new IOSSimulatorLog({
121
+ sim: /** @type {import('appium-ios-simulator').Simulator} */ (this.device),
110
122
  showLogs: this.opts.showIOSLog,
111
- xcodeVersion: this.xcodeVersion,
112
123
  iosSimulatorLogsPredicate: this.opts.iosSimulatorLogsPredicate,
124
+ log: this.log,
125
+ });
126
+ if (_.isBoolean(this.opts.showSafariConsoleLog)) {
127
+ this.logs.safariConsole = new SafariConsoleLog({
128
+ showLogs: this.opts.showSafariConsoleLog,
129
+ log: this.log,
130
+ });
131
+ }
132
+ if (_.isBoolean(this.opts.showSafariNetworkLog)) {
133
+ this.logs.safariNetwork = new SafariNetworkLog({
134
+ showLogs: this.opts.showSafariNetworkLog,
135
+ log: this.log,
113
136
  });
114
137
  }
115
- this.logs.safariConsole = new SafariConsoleLog(!!this.opts.showSafariConsoleLog);
116
- this.logs.safariNetwork = new SafariNetworkLog(!!this.opts.showSafariNetworkLog);
117
138
  }
118
139
 
119
140
  let didStartSyslog = false;
@@ -129,8 +150,6 @@ export default {
129
150
  }
130
151
  })(),
131
152
  this.logs.crashlog.startCapture(),
132
- this.logs.safariConsole.startCapture(),
133
- this.logs.safariNetwork.startCapture(),
134
153
  ];
135
154
  await B.all(promises);
136
155
 
@@ -1,9 +1,13 @@
1
1
  import type { LogEntry } from '../commands/types';
2
2
 
3
- export function toLogEntry(message: string, timestamp: number): LogEntry {
3
+ export const DEFAULT_LOG_LEVEL = 'ALL';
4
+ export const MAX_JSON_LOG_LENGTH = 200;
5
+ export const MAX_BUFFERED_EVENTS_COUNT = 5000;
6
+
7
+ export function toLogEntry(message: string, timestamp: number, level: string = DEFAULT_LOG_LEVEL): LogEntry {
4
8
  return {
5
9
  timestamp,
6
- level: 'ALL',
10
+ level,
7
11
  message,
8
12
  };
9
13
  }
@@ -105,15 +105,6 @@ class IOSCrashLog {
105
105
  return await this.filesToJSON(diff);
106
106
  }
107
107
 
108
- /**
109
- * @returns {Promise<import('../commands/types').LogEntry[]>}
110
- */
111
- async getAllLogs() {
112
- let crashFiles = await this.getCrashes();
113
- let logFiles = _.difference(crashFiles, this.prevLogs);
114
- return await this.filesToJSON(logFiles);
115
- }
116
-
117
108
  /**
118
109
  * @param {string[]} paths
119
110
  * @returns {Promise<import('../commands/types').LogEntry[]>}
@@ -0,0 +1,52 @@
1
+ import {services} from 'appium-ios-device';
2
+ import { LineConsumingLog } from './line-consuming-log';
3
+ import type { AppiumLogger } from '@appium/types';
4
+
5
+ export interface IOSDeviceLogOpts {
6
+ udid: string;
7
+ showLogs?: boolean;
8
+ log: AppiumLogger;
9
+ }
10
+
11
+ export class IOSDeviceLog extends LineConsumingLog {
12
+ private readonly udid: string;
13
+ private readonly showLogs: boolean;
14
+ private service: any | null;
15
+
16
+ constructor(opts: IOSDeviceLogOpts) {
17
+ super({log: opts.log});
18
+ this.udid = opts.udid;
19
+ this.showLogs = !!opts.showLogs;
20
+ this.service = null;
21
+ }
22
+
23
+ override async startCapture(): Promise<void> {
24
+ if (this.service) {
25
+ return;
26
+ }
27
+ this.service = await services.startSyslogService(this.udid);
28
+ this.service.start(this.onLog.bind(this));
29
+ }
30
+
31
+ override get isCapturing(): boolean {
32
+ return !!this.service;
33
+ }
34
+
35
+ // eslint-disable-next-line require-await
36
+ override async stopCapture(): Promise<void> {
37
+ if (!this.service) {
38
+ return;
39
+ }
40
+ this.service.close();
41
+ this.service = null;
42
+ }
43
+
44
+ private onLog(logLine: string): void {
45
+ this.broadcast(logLine);
46
+ if (this.showLogs) {
47
+ this.log.info(`[IOS_SYSLOG_ROW] ${logLine}`);
48
+ }
49
+ }
50
+ }
51
+
52
+ export default IOSDeviceLog;