browserstack-cypress-cli 1.23.1 → 1.24.2
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/CODEOWNERS +1 -0
- package/bin/commands/runs.js +74 -41
- package/bin/helpers/buildArtifacts.js +8 -6
- package/bin/helpers/reporterHTML.js +9 -8
- package/bin/helpers/utils.js +34 -3
- package/bin/testObservability/crashReporter/index.js +139 -0
- package/bin/testObservability/cypress/index.js +158 -0
- package/bin/testObservability/helper/constants.js +30 -0
- package/bin/testObservability/helper/helper.js +996 -0
- package/bin/testObservability/helper/requestQueueHandler.js +88 -0
- package/bin/testObservability/plugin/index.js +40 -0
- package/bin/testObservability/plugin/ipcClient.js +16 -0
- package/bin/testObservability/plugin/ipcServer.js +34 -0
- package/bin/testObservability/reporter/index.js +699 -0
- package/package.json +10 -4
package/CODEOWNERS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @browserstack/afd-dev
|
package/bin/commands/runs.js
CHANGED
|
@@ -23,6 +23,13 @@ const archiver = require("../helpers/archiver"),
|
|
|
23
23
|
packageDiff = require('../helpers/package-diff');
|
|
24
24
|
const { getStackTraceUrl } = require('../helpers/sync/syncSpecsLogs');
|
|
25
25
|
|
|
26
|
+
const {
|
|
27
|
+
launchTestSession,
|
|
28
|
+
setTestObservabilityFlags,
|
|
29
|
+
runCypressTestsLocally,
|
|
30
|
+
printBuildLink
|
|
31
|
+
} = require('../testObservability/helper/helper');
|
|
32
|
+
|
|
26
33
|
module.exports = function run(args, rawArgs) {
|
|
27
34
|
|
|
28
35
|
markBlockStart('preBuild');
|
|
@@ -45,6 +52,12 @@ module.exports = function run(args, rawArgs) {
|
|
|
45
52
|
logger.debug('Completed browserstack.json validation');
|
|
46
53
|
markBlockStart('setConfig');
|
|
47
54
|
logger.debug('Started setting the configs');
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
Set testObservability & browserstackAutomation flags
|
|
58
|
+
*/
|
|
59
|
+
const [isTestObservabilitySession, isBrowserstackInfra] = setTestObservabilityFlags(bsConfig);
|
|
60
|
+
|
|
48
61
|
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
|
|
49
62
|
|
|
50
63
|
utils.setDefaults(bsConfig, args);
|
|
@@ -55,80 +68,97 @@ module.exports = function run(args, rawArgs) {
|
|
|
55
68
|
// accept the access key from command line or env variable if provided
|
|
56
69
|
utils.setAccessKey(bsConfig, args);
|
|
57
70
|
|
|
58
|
-
let buildReportData = await getInitialDetails(bsConfig, args, rawArgs);
|
|
71
|
+
let buildReportData = !isBrowserstackInfra ? null : await getInitialDetails(bsConfig, args, rawArgs);
|
|
59
72
|
|
|
60
73
|
// accept the build name from command line if provided
|
|
61
74
|
utils.setBuildName(bsConfig, args);
|
|
62
75
|
|
|
63
76
|
// set cypress config filename
|
|
64
77
|
utils.setCypressConfigFilename(bsConfig, args);
|
|
78
|
+
|
|
79
|
+
if(isBrowserstackInfra) {
|
|
80
|
+
// set cypress test suite type
|
|
81
|
+
utils.setCypressTestSuiteType(bsConfig);
|
|
65
82
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// set cypress geo location
|
|
70
|
-
utils.setGeolocation(bsConfig, args);
|
|
71
|
-
|
|
72
|
-
// set timezone
|
|
73
|
-
utils.setTimezone(bsConfig, args);
|
|
83
|
+
// set cypress geo location
|
|
84
|
+
utils.setGeolocation(bsConfig, args);
|
|
74
85
|
|
|
75
|
-
|
|
76
|
-
|
|
86
|
+
// set timezone
|
|
87
|
+
utils.setTimezone(bsConfig, args);
|
|
77
88
|
|
|
89
|
+
// set spec timeout
|
|
90
|
+
utils.setSpecTimeout(bsConfig, args);
|
|
91
|
+
}
|
|
92
|
+
|
|
78
93
|
// accept the specs list from command line if provided
|
|
79
94
|
utils.setUserSpecs(bsConfig, args);
|
|
80
95
|
|
|
81
96
|
// accept the env list from command line and set it
|
|
82
97
|
utils.setTestEnvs(bsConfig, args);
|
|
83
98
|
|
|
99
|
+
// set build tag caps
|
|
100
|
+
utils.setBuildTags(bsConfig, args);
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
Send build start to Observability
|
|
104
|
+
*/
|
|
105
|
+
if(isTestObservabilitySession) await launchTestSession(bsConfig, bsConfigPath);
|
|
106
|
+
|
|
84
107
|
// accept the system env list from bsconf and set it
|
|
85
108
|
utils.setSystemEnvs(bsConfig);
|
|
86
109
|
|
|
87
|
-
|
|
88
|
-
|
|
110
|
+
if(isBrowserstackInfra) {
|
|
111
|
+
//accept the local from env variable if provided
|
|
112
|
+
utils.setLocal(bsConfig, args);
|
|
89
113
|
|
|
90
|
-
|
|
91
|
-
|
|
114
|
+
//set network logs
|
|
115
|
+
utils.setNetworkLogs(bsConfig);
|
|
92
116
|
|
|
93
|
-
|
|
94
|
-
|
|
117
|
+
// set Local Mode (on-demand/ always-on)
|
|
118
|
+
utils.setLocalMode(bsConfig, args);
|
|
95
119
|
|
|
96
|
-
|
|
97
|
-
|
|
120
|
+
//accept the local identifier from env variable if provided
|
|
121
|
+
utils.setLocalIdentifier(bsConfig, args);
|
|
98
122
|
|
|
99
|
-
|
|
100
|
-
|
|
123
|
+
// set Local Config File
|
|
124
|
+
utils.setLocalConfigFile(bsConfig, args);
|
|
101
125
|
|
|
102
|
-
|
|
103
|
-
|
|
126
|
+
// run test in headed mode
|
|
127
|
+
utils.setHeaded(bsConfig, args);
|
|
104
128
|
|
|
105
|
-
|
|
106
|
-
|
|
129
|
+
// set the no-wrap
|
|
130
|
+
utils.setNoWrap(bsConfig, args);
|
|
107
131
|
|
|
108
|
-
|
|
109
|
-
|
|
132
|
+
// add cypress dependency if missing
|
|
133
|
+
utils.setCypressNpmDependency(bsConfig);
|
|
134
|
+
}
|
|
110
135
|
|
|
111
|
-
const { packagesInstalled } = await packageInstaller.packageSetupAndInstaller(bsConfig, config.packageDirName, {markBlockStart, markBlockEnd});
|
|
136
|
+
const { packagesInstalled } = !isBrowserstackInfra ? false : await packageInstaller.packageSetupAndInstaller(bsConfig, config.packageDirName, {markBlockStart, markBlockEnd});
|
|
112
137
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
138
|
+
if(isBrowserstackInfra) {
|
|
139
|
+
// set node version
|
|
140
|
+
utils.setNodeVersion(bsConfig, args);
|
|
141
|
+
|
|
142
|
+
//set browsers
|
|
143
|
+
await utils.setBrowsers(bsConfig, args);
|
|
117
144
|
|
|
118
|
-
|
|
119
|
-
|
|
145
|
+
//set config (--config)
|
|
146
|
+
utils.setConfig(bsConfig, args);
|
|
120
147
|
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
// set sync/async mode (--async/--sync)
|
|
149
|
+
utils.setCLIMode(bsConfig, args);
|
|
123
150
|
|
|
124
|
-
|
|
125
|
-
|
|
151
|
+
// set other cypress configs e.g. reporter and reporter-options
|
|
152
|
+
utils.setOtherConfigs(bsConfig, args);
|
|
153
|
+
}
|
|
126
154
|
|
|
127
|
-
// set other cypress configs e.g. reporter and reporter-options
|
|
128
|
-
utils.setOtherConfigs(bsConfig, args);
|
|
129
155
|
markBlockEnd('setConfig');
|
|
130
156
|
logger.debug("Completed setting the configs");
|
|
131
157
|
|
|
158
|
+
if(!isBrowserstackInfra) {
|
|
159
|
+
return runCypressTestsLocally(bsConfig, args, rawArgs);
|
|
160
|
+
}
|
|
161
|
+
|
|
132
162
|
// Validate browserstack.json values and parallels specified via arguments
|
|
133
163
|
markBlockStart('validateConfig');
|
|
134
164
|
logger.debug("Started configs validation");
|
|
@@ -287,7 +317,10 @@ module.exports = function run(args, rawArgs) {
|
|
|
287
317
|
|
|
288
318
|
logger.info(message);
|
|
289
319
|
logger.info(dashboardLink);
|
|
290
|
-
if(!args.sync)
|
|
320
|
+
if(!args.sync) {
|
|
321
|
+
logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
|
|
322
|
+
printBuildLink(false);
|
|
323
|
+
}
|
|
291
324
|
let dataToSend = {
|
|
292
325
|
time_components: getTimeComponents(),
|
|
293
326
|
unique_id: utils.generateUniqueHash(),
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
const fs = require('fs'),
|
|
4
4
|
path = require('path');
|
|
5
5
|
|
|
6
|
-
const unzipper = require('unzipper');
|
|
7
|
-
|
|
8
6
|
const logger = require('./logger').winstonLogger,
|
|
9
7
|
utils = require("./utils"),
|
|
10
8
|
Constants = require("./constants"),
|
|
11
9
|
config = require("./config");
|
|
12
10
|
|
|
13
11
|
const request = require('request');
|
|
12
|
+
const decompress = require('decompress');
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
|
|
@@ -127,10 +126,13 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
|
|
|
127
126
|
|
|
128
127
|
const unzipFile = async (filePath, fileName) => {
|
|
129
128
|
return new Promise( async (resolve, reject) => {
|
|
130
|
-
await
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
await decompress(path.join(filePath, fileName), filePath)
|
|
130
|
+
.then((files) => {
|
|
131
|
+
resolve();
|
|
132
|
+
})
|
|
133
|
+
.catch((error) => {
|
|
134
|
+
reject(error);
|
|
135
|
+
});
|
|
134
136
|
});
|
|
135
137
|
}
|
|
136
138
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const fs = require('fs'),
|
|
2
2
|
path = require('path'),
|
|
3
3
|
request = require('request'),
|
|
4
|
-
unzipper = require('unzipper'),
|
|
5
4
|
logger = require('./logger').winstonLogger,
|
|
6
5
|
utils = require("./utils"),
|
|
7
6
|
Constants = require('./constants'),
|
|
8
|
-
config = require("./config")
|
|
7
|
+
config = require("./config"),
|
|
8
|
+
decompress = require('decompress');
|
|
9
9
|
|
|
10
10
|
let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) => {
|
|
11
11
|
let options = {
|
|
@@ -150,14 +150,15 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {
|
|
|
150
150
|
|
|
151
151
|
const unzipFile = async (filePath, fileName) => {
|
|
152
152
|
return new Promise( async (resolve, reject) => {
|
|
153
|
-
await
|
|
154
|
-
|
|
155
|
-
.catch((err) => {
|
|
156
|
-
reject(err);
|
|
157
|
-
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
158
|
-
});
|
|
153
|
+
await decompress(path.join(filePath, fileName), filePath)
|
|
154
|
+
.then((files) => {
|
|
159
155
|
let message = "Unzipped the json and html successfully."
|
|
160
156
|
resolve(message);
|
|
157
|
+
})
|
|
158
|
+
.catch((error) => {
|
|
159
|
+
reject(error);
|
|
160
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
161
|
+
});
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
164
|
|
package/bin/helpers/utils.js
CHANGED
|
@@ -21,7 +21,9 @@ const usageReporting = require("./usageReporting"),
|
|
|
21
21
|
fileHelpers = require("./fileHelpers"),
|
|
22
22
|
config = require("../helpers/config"),
|
|
23
23
|
pkg = require('../../package.json'),
|
|
24
|
-
transports = require('./logger').transports
|
|
24
|
+
transports = require('./logger').transports,
|
|
25
|
+
{ findGitConfig, printBuildLink, isTestObservabilitySession, isBrowserstackInfra, shouldReRunObservabilityTests } = require('../testObservability/helper/helper'),
|
|
26
|
+
{ OBSERVABILITY_ENV_VARS, TEST_OBSERVABILITY_REPORTER } = require('../testObservability/helper/constants');
|
|
25
27
|
|
|
26
28
|
const request = require('request');
|
|
27
29
|
|
|
@@ -226,7 +228,7 @@ exports.setDefaults = (bsConfig, args) => {
|
|
|
226
228
|
}
|
|
227
229
|
|
|
228
230
|
// setting cache_dependencies to true if not present
|
|
229
|
-
if (this.isUndefined(bsConfig.run_settings.cache_dependencies)) {
|
|
231
|
+
if (bsConfig.run_settings && this.isUndefined(bsConfig.run_settings.cache_dependencies)) {
|
|
230
232
|
bsConfig.run_settings.cache_dependencies = true;
|
|
231
233
|
}
|
|
232
234
|
|
|
@@ -478,6 +480,11 @@ exports.setNodeVersion = (bsConfig, args) => {
|
|
|
478
480
|
// specs can be passed via command line args as a string
|
|
479
481
|
// command line args takes precedence over config
|
|
480
482
|
exports.setUserSpecs = (bsConfig, args) => {
|
|
483
|
+
if(isBrowserstackInfra() && isTestObservabilitySession() && shouldReRunObservabilityTests()) {
|
|
484
|
+
bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS;
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
|
|
481
488
|
let bsConfigSpecs = bsConfig.run_settings.specs;
|
|
482
489
|
|
|
483
490
|
if (!this.isUndefined(args.specs)) {
|
|
@@ -551,6 +558,19 @@ exports.setSystemEnvs = (bsConfig) => {
|
|
|
551
558
|
});
|
|
552
559
|
}
|
|
553
560
|
|
|
561
|
+
try {
|
|
562
|
+
OBSERVABILITY_ENV_VARS.forEach(key => {
|
|
563
|
+
envKeys[key] = process.env[key];
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
let gitConfigPath = findGitConfig(process.cwd());
|
|
567
|
+
if(!isBrowserstackInfra()) process.env.OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath;
|
|
568
|
+
if(gitConfigPath) {
|
|
569
|
+
const relativePathFromGitConfig = path.relative(gitConfigPath, process.cwd());
|
|
570
|
+
envKeys["OBSERVABILITY_GIT_CONFIG_PATH"] = relativePathFromGitConfig ? relativePathFromGitConfig : 'DEFAULT';
|
|
571
|
+
}
|
|
572
|
+
} catch(e){}
|
|
573
|
+
|
|
554
574
|
if (Object.keys(envKeys).length === 0) {
|
|
555
575
|
bsConfig.run_settings.system_env_vars = null;
|
|
556
576
|
} else {
|
|
@@ -1123,7 +1143,11 @@ exports.handleSyncExit = (exitCode, dashboard_url) => {
|
|
|
1123
1143
|
syncCliLogger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
|
|
1124
1144
|
syncCliLogger.info(dashboard_url);
|
|
1125
1145
|
}
|
|
1126
|
-
|
|
1146
|
+
if(isTestObservabilitySession()) {
|
|
1147
|
+
printBuildLink(true, exitCode);
|
|
1148
|
+
} else {
|
|
1149
|
+
process.exit(exitCode);
|
|
1150
|
+
}
|
|
1127
1151
|
}
|
|
1128
1152
|
|
|
1129
1153
|
exports.getNetworkErrorMessage = (dashboard_url) => {
|
|
@@ -1223,6 +1247,12 @@ exports.setConfig = (bsConfig, args) => {
|
|
|
1223
1247
|
|
|
1224
1248
|
// blindly send other passed configs with run_settings and handle at backend
|
|
1225
1249
|
exports.setOtherConfigs = (bsConfig, args) => {
|
|
1250
|
+
if(isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) {
|
|
1251
|
+
bsConfig["run_settings"]["reporter"] = TEST_OBSERVABILITY_REPORTER;
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
/* Non Observability use-case */
|
|
1226
1256
|
if (!this.isUndefined(args.reporter)) {
|
|
1227
1257
|
bsConfig["run_settings"]["reporter"] = args.reporter;
|
|
1228
1258
|
logger.debug(`reporter set to ${args.reporter}`);
|
|
@@ -1382,6 +1412,7 @@ async function processExitHandler(exitData){
|
|
|
1382
1412
|
logger.warn(Constants.userMessages.PROCESS_KILL_MESSAGE);
|
|
1383
1413
|
await this.stopBrowserStackBuild(exitData.bsConfig, exitData.args, exitData.buildId, null, exitData.buildReportData);
|
|
1384
1414
|
await this.stopLocalBinary(exitData.bsConfig, exitData.bsLocalInstance, exitData.args, null, exitData.buildReportData);
|
|
1415
|
+
await printBuildLink(true);
|
|
1385
1416
|
process.exit(0);
|
|
1386
1417
|
}
|
|
1387
1418
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const request = require('request');
|
|
4
|
+
const http = require('http');
|
|
5
|
+
const https = require('https');
|
|
6
|
+
|
|
7
|
+
const logger = require("../../helpers/logger").winstonLogger;
|
|
8
|
+
|
|
9
|
+
const { API_URL, consoleHolder } = require('../helper/constants');
|
|
10
|
+
|
|
11
|
+
/* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */
|
|
12
|
+
const httpsKeepAliveAgent = new https.Agent({
|
|
13
|
+
keepAlive: true,
|
|
14
|
+
timeout: 60000,
|
|
15
|
+
maxSockets: 2,
|
|
16
|
+
maxTotalSockets: 2
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const debug = (text) => {
|
|
20
|
+
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
|
|
21
|
+
logger.info(`[ OBSERVABILITY ] ${text}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let packages = {};
|
|
26
|
+
|
|
27
|
+
exports.requireModule = (module, internal = false) => {
|
|
28
|
+
let local_path = "";
|
|
29
|
+
if(process.env["browserStackCwd"]){
|
|
30
|
+
local_path = path.join(process.env["browserStackCwd"], 'node_modules', module);
|
|
31
|
+
} else if(internal) {
|
|
32
|
+
local_path = path.join(process.cwd(), 'node_modules', 'browserstack-cypress-cli', 'node_modules', module);
|
|
33
|
+
} else {
|
|
34
|
+
local_path = path.join(process.cwd(), 'node_modules', module);
|
|
35
|
+
}
|
|
36
|
+
if(!fs.existsSync(local_path)) {
|
|
37
|
+
let global_path;
|
|
38
|
+
if(['jest-runner', 'jest-runtime'].includes(module))
|
|
39
|
+
global_path = path.join(GLOBAL_MODULE_PATH, 'jest', 'node_modules', module);
|
|
40
|
+
else
|
|
41
|
+
global_path = path.join(GLOBAL_MODULE_PATH, module);
|
|
42
|
+
if(!fs.existsSync(global_path)) {
|
|
43
|
+
throw new Error(`${module} doesn't exist.`);
|
|
44
|
+
}
|
|
45
|
+
return require(global_path);
|
|
46
|
+
}
|
|
47
|
+
return require(local_path);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getPackageVersion = (package_) => {
|
|
51
|
+
if(packages[package_]) return packages[package_];
|
|
52
|
+
return packages[package_] = this.requireModule(`${package_}/package.json`).version;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getAgentVersion = () => {
|
|
56
|
+
let _path = path.join(__dirname, '../../../package.json');
|
|
57
|
+
if(fs.existsSync(_path))
|
|
58
|
+
return require(_path).version;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class CrashReporter {
|
|
62
|
+
static instance;
|
|
63
|
+
|
|
64
|
+
constructor() {
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static getInstance() {
|
|
68
|
+
if (!CrashReporter.instance) {
|
|
69
|
+
CrashReporter.instance = new CrashReporter();
|
|
70
|
+
}
|
|
71
|
+
return CrashReporter.instance;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setCredentialsForCrashReportUpload(credentialsStr) {
|
|
75
|
+
/* User credentials used for reporting crashes */
|
|
76
|
+
this.credentialsForCrashReportUpload = JSON.parse(credentialsStr);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setConfigDetails(credentialsStr, browserstackConfigFile, cypressConfigFile) {
|
|
80
|
+
/* User test config for build run */
|
|
81
|
+
this.userConfigForReporting = {
|
|
82
|
+
framework: 'Cypress',
|
|
83
|
+
browserstackConfigFile: browserstackConfigFile,
|
|
84
|
+
cypressConfigFile: cypressConfigFile
|
|
85
|
+
};
|
|
86
|
+
this.setCredentialsForCrashReportUpload(credentialsStr);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
uploadCrashReport(exception, stacktrace) {
|
|
90
|
+
try {
|
|
91
|
+
if (!this.credentialsForCrashReportUpload.username || !this.credentialsForCrashReportUpload.password) {
|
|
92
|
+
return debug('[Crash_Report_Upload] Failed to parse user credentials while reporting crash')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const data = {
|
|
96
|
+
hashed_id: process.env.BS_TESTOPS_BUILD_HASHED_ID,
|
|
97
|
+
observability_version: {
|
|
98
|
+
frameworkName: 'Cypress',
|
|
99
|
+
frameworkVersion: getPackageVersion('cypress'),
|
|
100
|
+
sdkVersion: getAgentVersion()
|
|
101
|
+
},
|
|
102
|
+
exception: {
|
|
103
|
+
error: exception.toString(),
|
|
104
|
+
stackTrace: stacktrace
|
|
105
|
+
},
|
|
106
|
+
config: this.userConfigForReporting
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const options = {
|
|
110
|
+
auth: {
|
|
111
|
+
...this.credentialsForCrashReportUpload
|
|
112
|
+
},
|
|
113
|
+
headers: {
|
|
114
|
+
'Content-Type': 'application/json',
|
|
115
|
+
'X-BSTACK-TESTOPS': 'true'
|
|
116
|
+
},
|
|
117
|
+
method: 'POST',
|
|
118
|
+
url: `${API_URL}/api/v1/analytics`,
|
|
119
|
+
body: data,
|
|
120
|
+
json: true,
|
|
121
|
+
agent: httpsKeepAliveAgent
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
request(options, function callback(error, response, body) {
|
|
125
|
+
if(error) {
|
|
126
|
+
debug(`[Crash_Report_Upload] Failed due to ${error}`);
|
|
127
|
+
} else if(response.statusCode != 200) {
|
|
128
|
+
debug(`[Crash_Report_Upload] Failed due to ${response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`}`);
|
|
129
|
+
} else {
|
|
130
|
+
debug(`[Crash_Report_Upload] Success response: ${JSON.stringify({status: response.status, body: response.body})}`)
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
} catch(e) {
|
|
134
|
+
debug(`[Crash_Report_Upload] Processing failed due to ${e && e.stack}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = CrashReporter;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/* Event listeners + custom commands for Cypress */
|
|
2
|
+
|
|
3
|
+
/* Used to detect Gherkin steps */
|
|
4
|
+
Cypress.on('log:added', (log) => {
|
|
5
|
+
cy.now('task', 'test_observability_step', {
|
|
6
|
+
log
|
|
7
|
+
}, {log: false}).then((res) => {
|
|
8
|
+
}).catch((err) => {
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
Cypress.on('command:start', (command) => {
|
|
13
|
+
if(!command || !command.attributes) return;
|
|
14
|
+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
/* Send command details */
|
|
18
|
+
cy.now('task', 'test_observability_command', {
|
|
19
|
+
type: 'COMMAND_START',
|
|
20
|
+
command: {
|
|
21
|
+
attributes: {
|
|
22
|
+
id: command.attributes.id,
|
|
23
|
+
name: command.attributes.name,
|
|
24
|
+
args: command.attributes.args
|
|
25
|
+
},
|
|
26
|
+
state: 'pending'
|
|
27
|
+
}
|
|
28
|
+
}, {log: false}).then((res) => {
|
|
29
|
+
}).catch((err) => {
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/* Send platform details */
|
|
33
|
+
cy.now('task', 'test_observability_platform_details', {
|
|
34
|
+
testTitle: Cypress.currentTest.title,
|
|
35
|
+
browser: Cypress.browser,
|
|
36
|
+
platform: Cypress.platform,
|
|
37
|
+
cypressVersion: Cypress.version
|
|
38
|
+
}, {log: false}).then((res) => {
|
|
39
|
+
}).catch((err) => {
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
Cypress.on('command:retry', (command) => {
|
|
44
|
+
if(!command || !command.attributes) return;
|
|
45
|
+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
cy.now('task', 'test_observability_command', {
|
|
49
|
+
type: 'COMMAND_RETRY',
|
|
50
|
+
command: {
|
|
51
|
+
_log: command._log,
|
|
52
|
+
error: {
|
|
53
|
+
message: command && command.error ? command.error.message : null,
|
|
54
|
+
isDefaultAssertionErr: command && command.error ? command.error.isDefaultAssertionErr : null
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, {log: false}).then((res) => {
|
|
58
|
+
}).catch((err) => {
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
Cypress.on('command:end', (command) => {
|
|
63
|
+
if(!command || !command.attributes) return;
|
|
64
|
+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
cy.now('task', 'test_observability_command', {
|
|
68
|
+
'type': 'COMMAND_END',
|
|
69
|
+
'command': {
|
|
70
|
+
'attributes': {
|
|
71
|
+
'id': command.attributes.id,
|
|
72
|
+
'name': command.attributes.name,
|
|
73
|
+
'args': command.attributes.args
|
|
74
|
+
},
|
|
75
|
+
'state': command.state
|
|
76
|
+
}
|
|
77
|
+
}, {log: false}).then((res) => {
|
|
78
|
+
}).catch((err) => {
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
Cypress.Commands.overwrite('log', (originalFn, ...args) => {
|
|
83
|
+
if(args.includes('test_observability_log') || args.includes('test_observability_command')) return;
|
|
84
|
+
const message = args.reduce((result, logItem) => {
|
|
85
|
+
if (typeof logItem === 'object') {
|
|
86
|
+
return [result, JSON.stringify(logItem)].join(' ');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return [result, logItem ? logItem.toString() : ''].join(' ');
|
|
90
|
+
}, '');
|
|
91
|
+
cy.now('task', 'test_observability_log', {
|
|
92
|
+
'level': 'info',
|
|
93
|
+
message,
|
|
94
|
+
}, {log: false}).then((res) => {
|
|
95
|
+
}).catch((err) => {
|
|
96
|
+
});
|
|
97
|
+
originalFn(...args);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
Cypress.Commands.add('trace', (message, file) => {
|
|
101
|
+
cy.now('task', 'test_observability_log', {
|
|
102
|
+
level: 'trace',
|
|
103
|
+
message,
|
|
104
|
+
file,
|
|
105
|
+
}).then((res) => {
|
|
106
|
+
}).catch((err) => {
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
Cypress.Commands.add('logDebug', (message, file) => {
|
|
111
|
+
cy.now('task', 'test_observability_log', {
|
|
112
|
+
level: 'debug',
|
|
113
|
+
message,
|
|
114
|
+
file,
|
|
115
|
+
}).then((res) => {
|
|
116
|
+
}).catch((err) => {
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
Cypress.Commands.add('info', (message, file) => {
|
|
121
|
+
cy.now('task', 'test_observability_log', {
|
|
122
|
+
level: 'info',
|
|
123
|
+
message,
|
|
124
|
+
file,
|
|
125
|
+
}).then((res) => {
|
|
126
|
+
}).catch((err) => {
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
Cypress.Commands.add('warn', (message, file) => {
|
|
131
|
+
cy.now('task', 'test_observability_log', {
|
|
132
|
+
level: 'warn',
|
|
133
|
+
message,
|
|
134
|
+
file,
|
|
135
|
+
}).then((res) => {
|
|
136
|
+
}).catch((err) => {
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
Cypress.Commands.add('error', (message, file) => {
|
|
141
|
+
cy.now('task', 'test_observability_log', {
|
|
142
|
+
level: 'error',
|
|
143
|
+
message,
|
|
144
|
+
file,
|
|
145
|
+
}).then((res) => {
|
|
146
|
+
}).catch((err) => {
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
Cypress.Commands.add('fatal', (message, file) => {
|
|
151
|
+
cy.now('task', 'test_observability_log', {
|
|
152
|
+
level: 'fatal',
|
|
153
|
+
message,
|
|
154
|
+
file,
|
|
155
|
+
}).then((res) => {
|
|
156
|
+
}).catch((err) => {
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
exports.consoleHolder = Object.assign({},console);
|
|
2
|
+
exports.BATCH_SIZE = 1000;
|
|
3
|
+
exports.BATCH_INTERVAL = 2000;
|
|
4
|
+
exports.API_URL = 'https://collector-observability.browserstack.com';
|
|
5
|
+
|
|
6
|
+
exports.IPC_EVENTS = {
|
|
7
|
+
LOG: 'testObservability:cypressLog',
|
|
8
|
+
CONFIG: 'testObservability:cypressConfig',
|
|
9
|
+
SCREENSHOT: 'testObservability:cypressScreenshot',
|
|
10
|
+
COMMAND: 'testObservability:cypressCommand',
|
|
11
|
+
CUCUMBER: 'testObservability:cypressCucumberStep',
|
|
12
|
+
PLATFORM_DETAILS: 'testObservability:cypressPlatformDetails'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.OBSERVABILITY_ENV_VARS = [
|
|
16
|
+
"BROWSERSTACK_TEST_OBSERVABILITY",
|
|
17
|
+
"BROWSERSTACK_AUTOMATION",
|
|
18
|
+
"BS_TESTOPS_BUILD_COMPLETED",
|
|
19
|
+
"BS_TESTOPS_JWT",
|
|
20
|
+
"BS_TESTOPS_BUILD_HASHED_ID",
|
|
21
|
+
"BS_TESTOPS_ALLOW_SCREENSHOTS",
|
|
22
|
+
"OBSERVABILITY_LAUNCH_SDK_VERSION",
|
|
23
|
+
"BROWSERSTACK_OBSERVABILITY_DEBUG",
|
|
24
|
+
"OBS_CRASH_REPORTING_USERNAME",
|
|
25
|
+
"OBS_CRASH_REPORTING_ACCESS_KEY",
|
|
26
|
+
"OBS_CRASH_REPORTING_BS_CONFIG_PATH",
|
|
27
|
+
"OBS_CRASH_REPORTING_CYPRESS_CONFIG_PATH"
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservability/reporter';
|