Skip to content

Commit b3d79f8

Browse files
chore: add detailed logging
1 parent d54c407 commit b3d79f8

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

bin/accessibility-automation/helper.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,31 @@ const HttpsProxyAgent = require('https-proxy-agent');
1515
exports.checkAccessibilityPlatform = (user_config) => {
1616
let accessibility = false;
1717
try {
18+
console.debug('[A11Y][helper] Checking accessibility platform. Browsers:', user_config.browsers);
1819
user_config.browsers.forEach(browser => {
1920
if (browser.accessibility) {
2021
accessibility = true;
22+
console.debug(`[A11Y][helper] Accessibility enabled for browser:`, browser);
2123
}
2224
})
23-
} catch {}
24-
25+
} catch (err) {
26+
console.debug('[A11Y][helper] Error checking accessibility platform:', err);
27+
}
28+
console.debug(`[A11Y][helper] Accessibility platform result: ${accessibility}`);
2529
return accessibility;
2630
}
2731

2832
exports.setAccessibilityCypressCapabilities = async (user_config, accessibilityResponse) => {
2933
if (utils.isUndefined(user_config.run_settings.accessibilityOptions)) {
3034
user_config.run_settings.accessibilityOptions = {}
3135
}
36+
console.debug('[A11Y][helper] Setting Cypress capabilities for accessibility:', accessibilityResponse.data);
3237
user_config.run_settings.accessibilityOptions["authToken"] = accessibilityResponse.data.accessibilityToken;
3338
user_config.run_settings.accessibilityOptions["auth"] = accessibilityResponse.data.accessibilityToken;
3439
user_config.run_settings.accessibilityOptions["scannerVersion"] = accessibilityResponse.data.scannerVersion;
3540
user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_AUTH=${accessibilityResponse.data.accessibilityToken}`)
3641
user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_SCANNERVERSION=${accessibilityResponse.data.scannerVersion}`)
42+
console.debug('[A11Y][helper] Updated user_config.run_settings:', user_config.run_settings);
3743
}
3844

3945
exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => {
@@ -44,8 +50,9 @@ exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => {
4450
exports.createAccessibilityTestRun = async (user_config, framework) => {
4551

4652
try {
53+
console.debug('[A11Y][helper] Starting createAccessibilityTestRun');
4754
if (!this.isAccessibilitySupportedCypressVersion(user_config.run_settings.cypress_config_file) ){
48-
logger.warn(`Accessibility Testing is not supported on Cypress version 9 and below.`)
55+
logger.warn(`[A11Y][helper] Accessibility Testing is not supported on Cypress version 9 and below.`)
4956
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false';
5057
user_config.run_settings.accessibility = false;
5158
return;
@@ -59,6 +66,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
5966
projectName,
6067
buildDescription
6168
} = helper.getBuildDetails(user_config);
69+
console.debug('[A11Y][helper] Build details:', { buildName, projectName, buildDescription });
6270

6371
const data = {
6472
'projectName': projectName,
@@ -85,6 +93,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
8593
},
8694
'browserstackAutomation': process.env.BROWSERSTACK_AUTOMATION === 'true'
8795
};
96+
console.debug('[A11Y][helper] Test run payload:', data);
8897

8998
const config = {
9099
auth: {
@@ -95,35 +104,40 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
95104
'Content-Type': 'application/json'
96105
}
97106
};
107+
console.debug('[A11Y][helper] Test run config:', config);
98108

99109
const response = await nodeRequest(
100110
'POST', 'v2/test_runs', data, config, API_URL
101111
);
112+
console.debug('[A11Y][helper] Test run response:', response.data);
102113
if(!utils.isUndefined(response.data)) {
103114
process.env.BS_A11Y_JWT = response.data.data.accessibilityToken;
104115
process.env.BS_A11Y_TEST_RUN_ID = response.data.data.id;
116+
console.debug(`[A11Y][helper] Set BS_A11Y_JWT: ${process.env.BS_A11Y_JWT}, BS_A11Y_TEST_RUN_ID: ${process.env.BS_A11Y_TEST_RUN_ID}`);
105117
}
106118
if (process.env.BS_A11Y_JWT) {
107119
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true';
120+
console.debug('[A11Y][helper] Accessibility session enabled');
108121
}
109-
logger.debug(`BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`);
122+
logger.debug(`[A11Y][helper] BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`);
110123

111124
this.setAccessibilityCypressCapabilities(user_config, response.data);
112125
helper.setBrowserstackCypressCliDependency(user_config);
113126

114127
} catch (error) {
128+
console.debug('[A11Y][helper] Error in createAccessibilityTestRun:', error);
115129
if (error.response) {
116130
logger.error("Incorrect Cred")
117131
logger.error(
118-
`Exception while creating test run for BrowserStack Accessibility Automation: ${
132+
`[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${
119133
error.response.status
120134
} ${error.response.statusText} ${JSON.stringify(error.response.data)}`
121135
);
122136
} else {
123137
if(error.message === 'Invalid configuration passed.') {
124138
logger.error("Invalid configuration passed.")
125139
logger.error(
126-
`Exception while creating test run for BrowserStack Accessibility Automation: ${
140+
`[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${
127141
error.message || error.stack
128142
}`
129143
);
@@ -133,7 +147,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
133147

134148
} else {
135149
logger.error(
136-
`Exception while creating test run for BrowserStack Accessibility Automation: ${
150+
`[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${
137151
error.message || error.stack
138152
}`
139153
);

bin/accessibility-automation/plugin/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,42 @@ const utils = require('../../helpers/utils');
44

55
const browserstackAccessibility = (on, config) => {
66
let browser_validation = true;
7+
console.log('[A11Y][plugin] Initializing BrowserStack Accessibility plugin');
78
if (process.env.BROWSERSTACK_ACCESSIBILITY_DEBUG === 'true') {
89
config.env.BROWSERSTACK_LOGS = 'true';
910
process.env.BROWSERSTACK_LOGS = 'true';
11+
console.log('[A11Y][plugin] BROWSERSTACK_ACCESSIBILITY_DEBUG enabled, forcing BROWSERSTACK_LOGS to true');
1012
}
1113
on('task', {
1214
browserstack_log(message) {
13-
console.log(message)
14-
15+
console.log('[A11Y][plugin][browserstack_log]', message)
1516
return null
1617
},
1718
})
1819
on('before:browser:launch', (browser = {}, launchOptions) => {
1920
try {
21+
console.log(`[A11Y][plugin][before:browser:launch] Browser: ${browser.name}, Version: ${browser.majorVersion}, Headless: ${browser.isHeadless}`);
2022
if (process.env.ACCESSIBILITY_EXTENSION_PATH !== undefined) {
23+
console.log(`[A11Y][plugin] ACCESSIBILITY_EXTENSION_PATH: ${process.env.ACCESSIBILITY_EXTENSION_PATH}`);
2124
if (browser.name !== 'chrome') {
22-
console.log(`Accessibility Automation will run only on Chrome browsers.`);
25+
console.log(`[A11Y][plugin] Accessibility Automation will run only on Chrome browsers.`);
2326
browser_validation = false;
2427
}
2528
if (browser.name === 'chrome' && browser.majorVersion <= 94) {
26-
console.log(`Accessibility Automation will run only on Chrome browser version greater than 94.`);
29+
console.log(`[A11Y][plugin] Accessibility Automation will run only on Chrome browser version greater than 94.`);
2730
browser_validation = false;
2831
}
2932
if (browser.isHeadless === true) {
30-
console.log(`Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`);
33+
console.log(`[A11Y][plugin] Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`);
3134
browser_validation = false;
3235
}
3336
if (browser_validation) {
3437
const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH)
3538
const payload = decodeJWTToken(process.env.ACCESSIBILITY_AUTH);
39+
console.log(`[A11Y][plugin] Decoded JWT payload:`, payload);
3640
launchOptions.extensions.push(ally_path);
3741
if(!utils.isUndefined(payload) && !utils.isUndefined(payload.a11y_core_config) && payload.a11y_core_config.domForge === true) {
42+
console.log('[A11Y][plugin] domForge enabled, opening devtools for tabs');
3843
launchOptions.args.push("--auto-open-devtools-for-tabs");
3944
launchOptions.preferences.default["devtools"] = launchOptions.preferences.default["devtools"] || {};
4045
launchOptions.preferences.default["devtools"]["preferences"] = launchOptions.preferences.default["devtools"]["preferences"] || {};
@@ -45,8 +50,9 @@ const browserstackAccessibility = (on, config) => {
4550
return launchOptions
4651
}
4752
}
48-
} catch(err) {}
49-
53+
} catch(err) {
54+
console.log('[A11Y][plugin][before:browser:launch] Error:', err);
55+
}
5056
})
5157
config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH
5258
config.env.OS_VERSION = process.env.OS_VERSION
@@ -57,6 +63,7 @@ const browserstackAccessibility = (on, config) => {
5763
config.env.INCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE
5864
config.env.EXCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE
5965

66+
console.log('[A11Y][plugin] Final config.env:', config.env);
6067
return config;
6168
}
6269

0 commit comments

Comments
 (0)