-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathapp-automate.ts
More file actions
128 lines (112 loc) · 3.36 KB
/
Copy pathapp-automate.ts
File metadata and controls
128 lines (112 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import config from "../../config.js";
import { filterLinesByKeywords, validateLogResponse } from "./utils.js";
import { DOMAINS } from "../../lib/domains.js";
const auth = Buffer.from(
`${config.browserstackUsername}:${config.browserstackAccessKey}`,
).toString("base64");
// DEVICE LOGS
export async function retrieveDeviceLogs(
sessionId: string,
buildId: string,
): Promise<string> {
const url = `${DOMAINS.API}/app-automate/builds/${buildId}/sessions/${sessionId}/deviceLogs`;
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${auth}`,
},
});
const validationError = validateLogResponse(response, "device logs");
if (validationError) return validationError.message!;
const logText = await response.text();
const logs = filterDeviceFailures(logText);
return logs.length > 0
? `Device Failures (${logs.length} found):\n${JSON.stringify(logs, null, 2)}`
: "No device failures found";
}
// APPIUM LOGS
export async function retrieveAppiumLogs(
sessionId: string,
buildId: string,
): Promise<string> {
const url = `${DOMAINS.API}/app-automate/builds/${buildId}/sessions/${sessionId}/appiumlogs`;
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${auth}`,
},
});
const validationError = validateLogResponse(response, "Appium logs");
if (validationError) return validationError.message!;
const logText = await response.text();
const logs = filterAppiumFailures(logText);
return logs.length > 0
? `Appium Failures (${logs.length} found):\n${JSON.stringify(logs, null, 2)}`
: "No Appium failures found";
}
// CRASH LOGS
export async function retrieveCrashLogs(
sessionId: string,
buildId: string,
): Promise<string> {
const url = `${DOMAINS.API}/app-automate/builds/${buildId}/sessions/${sessionId}/crashlogs`;
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${auth}`,
},
});
const validationError = validateLogResponse(response, "crash logs");
if (validationError) return validationError.message!;
const logText = await response.text();
const logs = filterCrashFailures(logText);
return logs.length > 0
? `Crash Failures (${logs.length} found):\n${JSON.stringify(logs, null, 2)}`
: "No crash failures found";
}
// FILTER HELPERS
export function filterDeviceFailures(logText: string): string[] {
const keywords = [
"error",
"exception",
"fatal",
"anr",
"not responding",
"process crashed",
"crash",
"force close",
"signal",
"java.lang.",
"unable to",
];
return filterLinesByKeywords(logText, keywords);
}
export function filterAppiumFailures(logText: string): string[] {
const keywords = [
"error",
"fail",
"exception",
"not found",
"no such element",
"unable to",
"stacktrace",
"appium exited",
"command failed",
"invalid selector",
];
return filterLinesByKeywords(logText, keywords);
}
export function filterCrashFailures(logText: string): string[] {
const keywords = [
"fatal exception",
"crash",
"signal",
"java.lang.",
"caused by:",
"native crash",
"anr",
"abort message",
"application has stopped unexpectedly",
];
return filterLinesByKeywords(logText, keywords);
}