Skip to content

Commit 7e089c0

Browse files
committed
Merge branch 'master' into HST_1588_cyp_o11y_ats
2 parents 5476334 + 87c388c commit 7e089c0

38 files changed

+1697
-1556
lines changed

Diff for: bin/accessibility-automation/cypress/index.js

+274-276
Large diffs are not rendered by default.

Diff for: bin/accessibility-automation/helper.js

+41-27
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ const { API_URL } = require('./constants');
33
const utils = require('../helpers/utils');
44
const fs = require('fs');
55
const path = require('path');
6-
const request = require('request');
6+
const axios = require('axios');
77
const os = require('os');
88
const glob = require('glob');
99
const helper = require('../helpers/helper');
1010
const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require('../helpers/constants');
11+
const { consoleHolder } = require("../testObservability/helper/constants");
1112
const supportFileContentMap = {}
13+
const HttpsProxyAgent = require('https-proxy-agent');
1214

1315
exports.checkAccessibilityPlatform = (user_config) => {
1416
let accessibility = false;
@@ -86,8 +88,8 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
8688

8789
const config = {
8890
auth: {
89-
user: userName,
90-
pass: accessKey
91+
username: userName,
92+
password: accessKey
9193
},
9294
headers: {
9395
'Content-Type': 'application/json'
@@ -105,19 +107,21 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
105107
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true';
106108
}
107109
logger.debug(`BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`);
108-
110+
109111
this.setAccessibilityCypressCapabilities(user_config, response.data);
110112
helper.setBrowserstackCypressCliDependency(user_config);
111113

112114
} catch (error) {
113115
if (error.response) {
116+
logger.error("Incorrect Cred")
114117
logger.error(
115118
`Exception while creating test run for BrowserStack Accessibility Automation: ${
116119
error.response.status
117120
} ${error.response.statusText} ${JSON.stringify(error.response.data)}`
118121
);
119122
} else {
120123
if(error.message === 'Invalid configuration passed.') {
124+
logger.error("Invalid configuration passed.")
121125
logger.error(
122126
`Exception while creating test run for BrowserStack Accessibility Automation: ${
123127
error.message || error.stack
@@ -126,7 +130,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
126130
for(const errorkey of error.errors){
127131
logger.error(errorkey.message);
128132
}
129-
133+
130134
} else {
131135
logger.error(
132136
`Exception while creating test run for BrowserStack Accessibility Automation: ${
@@ -143,33 +147,43 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
143147

144148
const nodeRequest = (type, url, data, config) => {
145149
return new Promise(async (resolve, reject) => {
146-
const options = {...config,...{
150+
const options = {
151+
...config,
147152
method: type,
148153
url: `${API_URL}/${url}`,
149-
body: data,
150-
json: config.headers['Content-Type'] === 'application/json',
151-
}};
154+
data: data
155+
};
152156

153-
request(options, function callback(error, response, body) {
154-
if(error) {
155-
logger.info("error in nodeRequest", error);
156-
reject(error);
157-
} else if(!(response.statusCode == 201 || response.statusCode == 200)) {
158-
logger.info("response.statusCode in nodeRequest", response.statusCode);
159-
reject(response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`);
157+
if(process.env.HTTP_PROXY){
158+
options.proxy = false
159+
options.httpsAgent = new HttpsProxyAgent(process.env.HTTP_PROXY);
160+
161+
} else if (process.env.HTTPS_PROXY){
162+
options.proxy = false
163+
options.httpsAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY);
164+
}
165+
166+
axios(options).then(response => {
167+
if(!(response.status == 201 || response.status == 200)) {
168+
logger.info("response.status in nodeRequest", response.status);
169+
reject(response && response.data ? response.data : `Received response from BrowserStack Server with status : ${response.status}`);
160170
} else {
161-
try {
162-
if(typeof(body) !== 'object') body = JSON.parse(body);
163-
} catch(e) {
164-
if(!url.includes('/stop')) {
165-
reject('Not a JSON response from BrowserStack Server');
171+
try {
172+
if(typeof(response.data) !== 'object') body = JSON.parse(response.data);
173+
} catch(e) {
174+
if(!url.includes('/stop')) {
175+
reject('Not a JSON response from BrowserStack Server');
176+
}
166177
}
167-
}
168-
resolve({
169-
data: body
170-
});
178+
resolve({
179+
data: response.data
180+
});
171181
}
172-
});
182+
}).catch(error => {
183+
184+
logger.info("error in nodeRequest", error);
185+
reject(error);
186+
})
173187
});
174188
}
175189

@@ -211,7 +225,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => {
211225
try {
212226
if(!file.includes('commands.js') && !file.includes('commands.ts')) {
213227
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
214-
228+
215229
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
216230
if(!defaultFileContent.includes(cypressCommandEventListener)) {
217231
let newFileContent = defaultFileContent +

Diff for: bin/accessibility-automation/plugin/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const path = require("node:path");
32

43
const browserstackAccessibility = (on, config) => {
@@ -10,7 +9,7 @@ const browserstackAccessibility = (on, config) => {
109
on('task', {
1110
browserstack_log(message) {
1211
console.log(message)
13-
12+
1413
return null
1514
},
1615
})
@@ -36,7 +35,7 @@ const browserstackAccessibility = (on, config) => {
3635
}
3736
}
3837
} catch(err) {}
39-
38+
4039
})
4140
config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH
4241
config.env.OS_VERSION = process.env.OS_VERSION

Diff for: bin/commands/generateReport.js

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ module.exports = function generateReport(args, rawArgs) {
3131
let messageType = Constants.messageTypes.INFO;
3232
let errorCode = null;
3333
let buildId = args._[1];
34-
3534
reportGenerator(bsConfig, buildId, args, rawArgs, buildReportData);
3635
utils.sendUsageReport(bsConfig, args, 'generate-report called', messageType, errorCode, buildReportData, rawArgs);
3736
} catch(err) {

Diff for: bin/commands/info.js

+39-38
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use strict';
2-
const request = require('request');
3-
2+
const axios = require('axios').default;
43
const config = require("../helpers/config"),
54
logger = require("../helpers/logger").winstonLogger,
65
Constants = require("../helpers/constants"),
76
utils = require("../helpers/utils"),
87
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails;
98

9+
const { setAxiosProxy } = require('../helpers/helper');
10+
1011
module.exports = function info(args, rawArgs) {
1112
let bsConfigPath = utils.getConfigPath(args.cf);
1213

@@ -19,7 +20,7 @@ module.exports = function info(args, rawArgs) {
1920
// accept the access key from command line if provided
2021
utils.setAccessKey(bsConfig, args);
2122

22-
getInitialDetails(bsConfig, args, rawArgs).then((buildReportData) => {
23+
getInitialDetails(bsConfig, args, rawArgs).then(async (buildReportData) => {
2324

2425
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
2526

@@ -43,65 +44,65 @@ module.exports = function info(args, rawArgs) {
4344
options.url = `${config.turboScaleBuildsUrl}/${buildId}`;
4445
}
4546

46-
request.get(options, function (err, resp, body) {
47-
let message = null;
48-
let messageType = null;
49-
let errorCode = null;
50-
51-
if (err) {
52-
message = Constants.userMessages.BUILD_INFO_FAILED;
53-
messageType = Constants.messageTypes.ERROR;
54-
errorCode = 'api_failed_build_info';
55-
56-
logger.info(message);
57-
logger.error(utils.formatRequest(err, resp, body));
58-
} else {
59-
let build = null;
47+
let message = null;
48+
let messageType = null;
49+
let errorCode = null;
50+
51+
options.config = {
52+
auth: {
53+
username: bsConfig.auth.username,
54+
password: bsConfig.auth.access_key
55+
},
56+
headers: options.headers
57+
};
58+
setAxiosProxy(options.config);
59+
60+
try {
61+
const response = await axios.get(options.url, options.config);
62+
let build = null;
6063
try {
61-
build = JSON.parse(body);
64+
build = response.data;
6265
} catch (error) {
6366
build = null;
6467
}
65-
66-
if (resp.statusCode == 299) {
68+
if (response.status == 299) {
6769
messageType = Constants.messageTypes.INFO;
6870
errorCode = 'api_deprecated';
69-
70-
if (build) {
71-
message = build.message;
72-
logger.info(message);
73-
} else {
74-
message = Constants.userMessages.API_DEPRECATED;
75-
logger.info(message);
76-
}
77-
logger.info(utils.formatRequest(err, resp, body));
78-
} else if (resp.statusCode != 200) {
71+
message = build ? build.message : Constants.userMessages.API_DEPRECATED;
72+
logger.info(utils.formatRequest(response.statusText, response, response.data));
73+
} else if (response.status != 200) {
74+
message = Constants.userMessages.BUILD_INFO_FAILED;
7975
messageType = Constants.messageTypes.ERROR;
8076
errorCode = 'api_failed_build_info';
81-
8277
if (build) {
8378
message = `${
8479
Constants.userMessages.BUILD_INFO_FAILED
8580
} with error: \n${JSON.stringify(build, null, 2)}`;
86-
logger.error(message);
8781
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
8882
} else {
8983
message = Constants.userMessages.BUILD_INFO_FAILED;
90-
logger.error(message);
9184
}
92-
logger.error(utils.formatRequest(err, resp, body));
85+
logger.error(message);
86+
logger.error(utils.formatRequest(response.statusText, response, response.data));
9387
} else {
9488
messageType = Constants.messageTypes.SUCCESS;
9589
message = `Build info for build id: \n ${JSON.stringify(
9690
build,
9791
null,
9892
2
9993
)}`;
100-
logger.info(message);
10194
}
102-
}
103-
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
104-
});
95+
logger.info(message);
96+
} catch (error) {
97+
message = `${
98+
Constants.userMessages.BUILD_INFO_FAILED
99+
} with error: \n${error.response.data.message}`;
100+
messageType = Constants.messageTypes.ERROR;
101+
errorCode = 'api_failed_build_info';
102+
logger.info(message);
103+
logger.error(utils.formatRequest(error.response.statusText, error.response, error.response.data));
104+
}
105+
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
105106
}).catch((err) => {
106107
logger.warn(err);
107108
});

Diff for: bin/commands/runs.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const {
3030
printBuildLink
3131
} = require('../testObservability/helper/helper');
3232

33-
3433
const {
3534
createAccessibilityTestRun,
3635
setAccessibilityEventListeners,
@@ -39,6 +38,7 @@ const {
3938
} = require('../accessibility-automation/helper');
4039
const { isTurboScaleSession, getTurboScaleGridDetails, patchCypressConfigFileContent, atsFileCleanup } = require('../helpers/atsHelper');
4140

41+
4242
module.exports = function run(args, rawArgs) {
4343

4444
markBlockStart('preBuild');
@@ -64,15 +64,14 @@ module.exports = function run(args, rawArgs) {
6464

6565
// set cypress config filename
6666
utils.setCypressConfigFilename(bsConfig, args);
67-
68-
/*
69-
Set testObservability & browserstackAutomation flags
70-
*/
67+
68+
/* Set testObservability & browserstackAutomation flags */
7169
const [isTestObservabilitySession, isBrowserstackInfra] = setTestObservabilityFlags(bsConfig);
7270
const checkAccessibility = checkAccessibilityPlatform(bsConfig);
7371
const isAccessibilitySession = bsConfig.run_settings.accessibility || checkAccessibility;
7472
const turboScaleSession = isTurboScaleSession(bsConfig);
7573
Constants.turboScaleObj.enabled = turboScaleSession;
74+
7675

7776
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
7877

@@ -102,6 +101,7 @@ module.exports = function run(args, rawArgs) {
102101
// set spec timeout
103102
utils.setSpecTimeout(bsConfig, args);
104103
}
104+
105105

106106
// accept the specs list from command line if provided
107107
utils.setUserSpecs(bsConfig, args);
@@ -112,9 +112,7 @@ module.exports = function run(args, rawArgs) {
112112
// set build tag caps
113113
utils.setBuildTags(bsConfig, args);
114114

115-
/*
116-
Send build start to Observability
117-
*/
115+
// Send build start to Observability
118116
if(isTestObservabilitySession) {
119117
await launchTestSession(bsConfig, bsConfigPath);
120118
utils.setO11yProcessHooks(null, bsConfig, args, null, buildReportData);
@@ -379,7 +377,7 @@ module.exports = function run(args, rawArgs) {
379377
});
380378
} else if(!turboScaleSession){
381379
let stacktraceUrl = getStackTraceUrl();
382-
downloadBuildStacktrace(stacktraceUrl).then((message) => {
380+
downloadBuildStacktrace(stacktraceUrl, bsConfig).then((message) => {
383381
utils.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
384382
}).catch((err) => {
385383
let message = `Downloading build stacktrace failed with statuscode: ${err}. Please visit ${data.dashboard_url} for additional details.`;

Diff for: bin/commands/stop.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
const request = require('request');
32

43
const config = require("../helpers/config"),
54
logger = require("../helpers/logger").winstonLogger,

0 commit comments

Comments
 (0)