From d54c4073eb0b1c942a242fcc2d513d5863a0b1d1 Mon Sep 17 00:00:00 2001 From: Rahul Dandona Bstack Date: Thu, 17 Jul 2025 16:51:10 +0530 Subject: [PATCH 01/57] fix: use valid variable --- bin/accessibility-automation/cypress/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 8b2d1290..81c70133 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -289,7 +289,7 @@ const shouldScanForAccessibility = (attributes) => { const fullTestName = attributes.title; const excluded = excludeTagArray.some((exclude) => fullTestName.includes(exclude)); - const included = includeTagArray.length === 0 || includeTags.some((include) => fullTestName.includes(include)); + const included = includeTagArray.length === 0 || includeTagArray.some((include) => fullTestName.includes(include)); shouldScanTestForAccessibility = !excluded && included; } catch (error) { browserStackLog(`Error while validating test case for accessibility before scanning. Error : ${error.message}`); From b3d79f8fb874e5aed156dafbf51dafe6560459e0 Mon Sep 17 00:00:00 2001 From: Rahul Dandona Bstack Date: Fri, 18 Jul 2025 17:37:29 +0530 Subject: [PATCH 02/57] chore: add detailed logging --- bin/accessibility-automation/helper.js | 28 +++++++++++++++----- bin/accessibility-automation/plugin/index.js | 21 ++++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 1d49988f..fb076bf7 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -15,13 +15,17 @@ const HttpsProxyAgent = require('https-proxy-agent'); exports.checkAccessibilityPlatform = (user_config) => { let accessibility = false; try { + console.debug('[A11Y][helper] Checking accessibility platform. Browsers:', user_config.browsers); user_config.browsers.forEach(browser => { if (browser.accessibility) { accessibility = true; + console.debug(`[A11Y][helper] Accessibility enabled for browser:`, browser); } }) - } catch {} - + } catch (err) { + console.debug('[A11Y][helper] Error checking accessibility platform:', err); + } + console.debug(`[A11Y][helper] Accessibility platform result: ${accessibility}`); return accessibility; } @@ -29,11 +33,13 @@ exports.setAccessibilityCypressCapabilities = async (user_config, accessibilityR if (utils.isUndefined(user_config.run_settings.accessibilityOptions)) { user_config.run_settings.accessibilityOptions = {} } + console.debug('[A11Y][helper] Setting Cypress capabilities for accessibility:', accessibilityResponse.data); user_config.run_settings.accessibilityOptions["authToken"] = accessibilityResponse.data.accessibilityToken; user_config.run_settings.accessibilityOptions["auth"] = accessibilityResponse.data.accessibilityToken; user_config.run_settings.accessibilityOptions["scannerVersion"] = accessibilityResponse.data.scannerVersion; user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_AUTH=${accessibilityResponse.data.accessibilityToken}`) user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_SCANNERVERSION=${accessibilityResponse.data.scannerVersion}`) + console.debug('[A11Y][helper] Updated user_config.run_settings:', user_config.run_settings); } exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => { @@ -44,8 +50,9 @@ exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => { exports.createAccessibilityTestRun = async (user_config, framework) => { try { + console.debug('[A11Y][helper] Starting createAccessibilityTestRun'); if (!this.isAccessibilitySupportedCypressVersion(user_config.run_settings.cypress_config_file) ){ - logger.warn(`Accessibility Testing is not supported on Cypress version 9 and below.`) + logger.warn(`[A11Y][helper] Accessibility Testing is not supported on Cypress version 9 and below.`) process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false'; user_config.run_settings.accessibility = false; return; @@ -59,6 +66,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { projectName, buildDescription } = helper.getBuildDetails(user_config); + console.debug('[A11Y][helper] Build details:', { buildName, projectName, buildDescription }); const data = { 'projectName': projectName, @@ -85,6 +93,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { }, 'browserstackAutomation': process.env.BROWSERSTACK_AUTOMATION === 'true' }; + console.debug('[A11Y][helper] Test run payload:', data); const config = { auth: { @@ -95,27 +104,32 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { 'Content-Type': 'application/json' } }; + console.debug('[A11Y][helper] Test run config:', config); const response = await nodeRequest( 'POST', 'v2/test_runs', data, config, API_URL ); + console.debug('[A11Y][helper] Test run response:', response.data); if(!utils.isUndefined(response.data)) { process.env.BS_A11Y_JWT = response.data.data.accessibilityToken; process.env.BS_A11Y_TEST_RUN_ID = response.data.data.id; + 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}`); } if (process.env.BS_A11Y_JWT) { process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true'; + console.debug('[A11Y][helper] Accessibility session enabled'); } - logger.debug(`BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`); + logger.debug(`[A11Y][helper] BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`); this.setAccessibilityCypressCapabilities(user_config, response.data); helper.setBrowserstackCypressCliDependency(user_config); } catch (error) { + console.debug('[A11Y][helper] Error in createAccessibilityTestRun:', error); if (error.response) { logger.error("Incorrect Cred") logger.error( - `Exception while creating test run for BrowserStack Accessibility Automation: ${ + `[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${ error.response.status } ${error.response.statusText} ${JSON.stringify(error.response.data)}` ); @@ -123,7 +137,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { if(error.message === 'Invalid configuration passed.') { logger.error("Invalid configuration passed.") logger.error( - `Exception while creating test run for BrowserStack Accessibility Automation: ${ + `[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${ error.message || error.stack }` ); @@ -133,7 +147,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { } else { logger.error( - `Exception while creating test run for BrowserStack Accessibility Automation: ${ + `[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${ error.message || error.stack }` ); diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index 4c35ef99..d5e06676 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -4,37 +4,42 @@ const utils = require('../../helpers/utils'); const browserstackAccessibility = (on, config) => { let browser_validation = true; + console.log('[A11Y][plugin] Initializing BrowserStack Accessibility plugin'); if (process.env.BROWSERSTACK_ACCESSIBILITY_DEBUG === 'true') { config.env.BROWSERSTACK_LOGS = 'true'; process.env.BROWSERSTACK_LOGS = 'true'; + console.log('[A11Y][plugin] BROWSERSTACK_ACCESSIBILITY_DEBUG enabled, forcing BROWSERSTACK_LOGS to true'); } on('task', { browserstack_log(message) { - console.log(message) - + console.log('[A11Y][plugin][browserstack_log]', message) return null }, }) on('before:browser:launch', (browser = {}, launchOptions) => { try { + console.log(`[A11Y][plugin][before:browser:launch] Browser: ${browser.name}, Version: ${browser.majorVersion}, Headless: ${browser.isHeadless}`); if (process.env.ACCESSIBILITY_EXTENSION_PATH !== undefined) { + console.log(`[A11Y][plugin] ACCESSIBILITY_EXTENSION_PATH: ${process.env.ACCESSIBILITY_EXTENSION_PATH}`); if (browser.name !== 'chrome') { - console.log(`Accessibility Automation will run only on Chrome browsers.`); + console.log(`[A11Y][plugin] Accessibility Automation will run only on Chrome browsers.`); browser_validation = false; } if (browser.name === 'chrome' && browser.majorVersion <= 94) { - console.log(`Accessibility Automation will run only on Chrome browser version greater than 94.`); + console.log(`[A11Y][plugin] Accessibility Automation will run only on Chrome browser version greater than 94.`); browser_validation = false; } if (browser.isHeadless === true) { - console.log(`Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`); + console.log(`[A11Y][plugin] Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`); browser_validation = false; } if (browser_validation) { const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH) const payload = decodeJWTToken(process.env.ACCESSIBILITY_AUTH); + console.log(`[A11Y][plugin] Decoded JWT payload:`, payload); launchOptions.extensions.push(ally_path); if(!utils.isUndefined(payload) && !utils.isUndefined(payload.a11y_core_config) && payload.a11y_core_config.domForge === true) { + console.log('[A11Y][plugin] domForge enabled, opening devtools for tabs'); launchOptions.args.push("--auto-open-devtools-for-tabs"); launchOptions.preferences.default["devtools"] = launchOptions.preferences.default["devtools"] || {}; launchOptions.preferences.default["devtools"]["preferences"] = launchOptions.preferences.default["devtools"]["preferences"] || {}; @@ -45,8 +50,9 @@ const browserstackAccessibility = (on, config) => { return launchOptions } } - } catch(err) {} - + } catch(err) { + console.log('[A11Y][plugin][before:browser:launch] Error:', err); + } }) config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH config.env.OS_VERSION = process.env.OS_VERSION @@ -57,6 +63,7 @@ const browserstackAccessibility = (on, config) => { config.env.INCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE config.env.EXCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE + console.log('[A11Y][plugin] Final config.env:', config.env); return config; } From fc985b722bc15500278222aa53d5ab802cae51a0 Mon Sep 17 00:00:00 2001 From: Rahul Dandona Bstack Date: Tue, 22 Jul 2025 13:29:30 +0530 Subject: [PATCH 03/57] chore: more logs --- bin/accessibility-automation/cypress/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 81c70133..482aa739 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -318,11 +318,18 @@ commandToOverwrite.forEach((command) => { afterEach(() => { const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; + console.log(`--- ENTERING AFTEREACH FOR: ${testTitle} ---`); // Added + console.log(`Timestamp (afterEach start): ${new Date().toISOString()}`) cy.window().then(async (win) => { let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); - if (!shouldScanTestForAccessibility) return cy.wrap({}); + if (!shouldScanTestForAccessibility) { + console.log(`Skipping scan for: ${testTitle} (not accessibility session)`); // Added + return cy.wrap({}); + } + console.log(`Performing initial scan within afterEach for: ${testTitle}`); // Added cy.wrap(performScan(win), {timeout: 30000}).then(() => { + console.log(`Initial scan completed within afterEach for: ${testTitle}`); // Added try { let os_data; if (Cypress.env("OS")) { @@ -355,12 +362,18 @@ afterEach(() => { } }; browserStackLog(`Saving accessibility test results`); + console.log(`Timestamp (saveTestResults call): ${new Date().toISOString()}`); // Added cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => { browserStackLog(`Saved accessibility test results`); + console.log(`Timestamp (saveTestResults completed): ${new Date().toISOString()}`); // Added + console.log(`--- EXITING AFTEREACH FOR: ${testTitle} ---`); // Added + }) } catch (er) { browserStackLog(`Error in saving results with error: ${er.message}`); + console.error(`Error in afterEach for ${testTitle}:`, er); // Added + } }) }); From e45f782777bbf5a62e38090cd6da148e259d9473 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 28 Jul 2025 18:30:05 +0530 Subject: [PATCH 04/57] new changes --- bin/accessibility-automation/cypress/index.js | 49 +++++++++++++------ bin/accessibility-automation/plugin/index.js | 29 +++++------ 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 482aa739..e3480862 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -1,3 +1,6 @@ +const fs = require('fs'); +const path = require('path'); + /* Event listeners + custom commands for Cypress */ const browserStackLog = (message) => { @@ -15,6 +18,7 @@ const commandToOverwrite = ['visit', 'click', 'type', 'request', 'dblclick', 'ri and chaning available from original cypress command. */ const performModifiedScan = (originalFn, Subject, stateType, ...args) => { + process.env.PERFORM_MODIFIED_SCAN = 'true'; let customChaining = cy.wrap(null).performScan(); const changeSub = (args, stateType, newSubject) => { if (stateType !== 'parent') { @@ -41,8 +45,10 @@ const performModifiedScan = (originalFn, Subject, stateType, ...args) => { } } runCustomizedCommand(); + process.env.PERFORM_MODIFIED_SCAN = 'true'; } + const performScan = (win, payloadToSend) => new Promise(async (resolve, reject) => { const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol); @@ -289,7 +295,7 @@ const shouldScanForAccessibility = (attributes) => { const fullTestName = attributes.title; const excluded = excludeTagArray.some((exclude) => fullTestName.includes(exclude)); - const included = includeTagArray.length === 0 || includeTagArray.some((include) => fullTestName.includes(include)); + const included = includeTagArray.length === 0 || includeTags.some((include) => fullTestName.includes(include)); shouldScanTestForAccessibility = !excluded && included; } catch (error) { browserStackLog(`Error while validating test case for accessibility before scanning. Error : ${error.message}`); @@ -316,20 +322,35 @@ commandToOverwrite.forEach((command) => { }); }); +const logFilePath = path.join(__dirname, 'accessibility-log.txt'); afterEach(() => { + + const logMessage = `afterEach executed for test` + try { + fs.appendFileSync(logFilePath, logMessage); + } catch (err) { + // ignore logging errors + } + if (process.env.AFTER_EACH_RUN === 'true' || process.env.PERFORM_MODIFIED_SCAN === 'true') { + return; + } + process.env.AFTER_EACH_RUN = 'true'; + + try { + throw new Error('Deliberate exception thrown for testing purposes'); + } catch (error) { + console.error('Exception caught in afterEach:', error); + if (error && error.stack) { + console.error(error.stack); + } + } + const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; - console.log(`--- ENTERING AFTEREACH FOR: ${testTitle} ---`); // Added - console.log(`Timestamp (afterEach start): ${new Date().toISOString()}`) cy.window().then(async (win) => { let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); - if (!shouldScanTestForAccessibility) { - console.log(`Skipping scan for: ${testTitle} (not accessibility session)`); // Added - return cy.wrap({}); - } - console.log(`Performing initial scan within afterEach for: ${testTitle}`); // Added + if (!shouldScanTestForAccessibility) return cy.wrap({}); cy.wrap(performScan(win), {timeout: 30000}).then(() => { - console.log(`Initial scan completed within afterEach for: ${testTitle}`); // Added try { let os_data; if (Cypress.env("OS")) { @@ -361,19 +382,15 @@ afterEach(() => { "browser_version": Cypress.browser.version } }; - browserStackLog(`Saving accessibility test results`); - console.log(`Timestamp (saveTestResults call): ${new Date().toISOString()}`); // Added + browserStackLog(`afterEach hook called from function: ${attributes.title}, file: ${filePath}`); + browserStackLog(`File name: ${__filename}`); + browserStackLog(`Saving accessibility test results123`); cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => { browserStackLog(`Saved accessibility test results`); - console.log(`Timestamp (saveTestResults completed): ${new Date().toISOString()}`); // Added - console.log(`--- EXITING AFTEREACH FOR: ${testTitle} ---`); // Added - }) } catch (er) { browserStackLog(`Error in saving results with error: ${er.message}`); - console.error(`Error in afterEach for ${testTitle}:`, er); // Added - } }) }); diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index d5e06676..d31dff60 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -1,45 +1,48 @@ const path = require("node:path"); const { decodeJWTToken } = require("../../helpers/utils"); const utils = require('../../helpers/utils'); +const fs = require('fs'); const browserstackAccessibility = (on, config) => { + const logFilePath = path.join(__dirname, 'accessibility-start-log.txt'); + const logMessage = `afterEach executed for test` + try { + fs.appendFileSync(logFilePath, logMessage); + } catch (err) { + // ignore logging errors + } let browser_validation = true; - console.log('[A11Y][plugin] Initializing BrowserStack Accessibility plugin'); if (process.env.BROWSERSTACK_ACCESSIBILITY_DEBUG === 'true') { config.env.BROWSERSTACK_LOGS = 'true'; process.env.BROWSERSTACK_LOGS = 'true'; - console.log('[A11Y][plugin] BROWSERSTACK_ACCESSIBILITY_DEBUG enabled, forcing BROWSERSTACK_LOGS to true'); } on('task', { browserstack_log(message) { - console.log('[A11Y][plugin][browserstack_log]', message) + console.log(message) + return null }, }) on('before:browser:launch', (browser = {}, launchOptions) => { try { - console.log(`[A11Y][plugin][before:browser:launch] Browser: ${browser.name}, Version: ${browser.majorVersion}, Headless: ${browser.isHeadless}`); if (process.env.ACCESSIBILITY_EXTENSION_PATH !== undefined) { - console.log(`[A11Y][plugin] ACCESSIBILITY_EXTENSION_PATH: ${process.env.ACCESSIBILITY_EXTENSION_PATH}`); if (browser.name !== 'chrome') { - console.log(`[A11Y][plugin] Accessibility Automation will run only on Chrome browsers.`); + console.log(`Accessibility Automation will run only on Chrome browsers.`); browser_validation = false; } if (browser.name === 'chrome' && browser.majorVersion <= 94) { - console.log(`[A11Y][plugin] Accessibility Automation will run only on Chrome browser version greater than 94.`); + console.log(`Accessibility Automation will run only on Chrome browser version greater than 94.`); browser_validation = false; } if (browser.isHeadless === true) { - console.log(`[A11Y][plugin] Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`); + console.log(`Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`); browser_validation = false; } if (browser_validation) { const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH) const payload = decodeJWTToken(process.env.ACCESSIBILITY_AUTH); - console.log(`[A11Y][plugin] Decoded JWT payload:`, payload); launchOptions.extensions.push(ally_path); if(!utils.isUndefined(payload) && !utils.isUndefined(payload.a11y_core_config) && payload.a11y_core_config.domForge === true) { - console.log('[A11Y][plugin] domForge enabled, opening devtools for tabs'); launchOptions.args.push("--auto-open-devtools-for-tabs"); launchOptions.preferences.default["devtools"] = launchOptions.preferences.default["devtools"] || {}; launchOptions.preferences.default["devtools"]["preferences"] = launchOptions.preferences.default["devtools"]["preferences"] || {}; @@ -50,9 +53,8 @@ const browserstackAccessibility = (on, config) => { return launchOptions } } - } catch(err) { - console.log('[A11Y][plugin][before:browser:launch] Error:', err); - } + } catch(err) {} + }) config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH config.env.OS_VERSION = process.env.OS_VERSION @@ -63,7 +65,6 @@ const browserstackAccessibility = (on, config) => { config.env.INCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE config.env.EXCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE - console.log('[A11Y][plugin] Final config.env:', config.env); return config; } From 92148051670bd3856d28d43e345ac3fefe0b7709 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 28 Jul 2025 18:41:59 +0530 Subject: [PATCH 05/57] more changes --- bin/accessibility-automation/cypress/index.js | 24 +++++++++---------- bin/accessibility-automation/plugin/index.js | 14 +++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index e3480862..954670ab 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -325,23 +325,23 @@ commandToOverwrite.forEach((command) => { const logFilePath = path.join(__dirname, 'accessibility-log.txt'); afterEach(() => { - const logMessage = `afterEach executed for test` - try { - fs.appendFileSync(logFilePath, logMessage); - } catch (err) { - // ignore logging errors - } - if (process.env.AFTER_EACH_RUN === 'true' || process.env.PERFORM_MODIFIED_SCAN === 'true') { - return; - } - process.env.AFTER_EACH_RUN = 'true'; + // const logMessage = `afterEach executed for test` + // try { + // fs.appendFileSync(logFilePath, logMessage); + // } catch (err) { + // // ignore logging errors + // } + // if (process.env.AFTER_EACH_RUN === 'true' || process.env.PERFORM_MODIFIED_SCAN === 'true') { + // return; + // } + // process.env.AFTER_EACH_RUN = 'true'; try { throw new Error('Deliberate exception thrown for testing purposes'); } catch (error) { - console.error('Exception caught in afterEach:', error); + browserStackLog(`Exception caught in afterEach: ${error.message}`); if (error && error.stack) { - console.error(error.stack); + browserStackLog(error.stack); } } diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index d31dff60..ba4d770c 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -4,13 +4,13 @@ const utils = require('../../helpers/utils'); const fs = require('fs'); const browserstackAccessibility = (on, config) => { - const logFilePath = path.join(__dirname, 'accessibility-start-log.txt'); - const logMessage = `afterEach executed for test` - try { - fs.appendFileSync(logFilePath, logMessage); - } catch (err) { - // ignore logging errors - } + // const logFilePath = path.join(__dirname, 'accessibility-start-log.txt'); + // const logMessage = `afterEach executed for test` + // try { + // fs.appendFileSync(logFilePath, logMessage); + // } catch (err) { + // // ignore logging errors + // } let browser_validation = true; if (process.env.BROWSERSTACK_ACCESSIBILITY_DEBUG === 'true') { config.env.BROWSERSTACK_LOGS = 'true'; From 1bd74d2a1b33f304e89239c5d98d0956413d0622 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 28 Jul 2025 20:23:24 +0530 Subject: [PATCH 06/57] added more logging --- bin/accessibility-automation/cypress/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 954670ab..a2ad1eb1 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -339,6 +339,10 @@ afterEach(() => { try { throw new Error('Deliberate exception thrown for testing purposes'); } catch (error) { + cy.readFile('cypress/integration/test_Accessibility/AppFlow.spec.ts').then((fileContent) => { + cy.log('File contents:', fileContent); + browserStackLog('File contents:', fileContent); + }); browserStackLog(`Exception caught in afterEach: ${error.message}`); if (error && error.stack) { browserStackLog(error.stack); @@ -383,8 +387,7 @@ afterEach(() => { } }; browserStackLog(`afterEach hook called from function: ${attributes.title}, file: ${filePath}`); - browserStackLog(`File name: ${__filename}`); - browserStackLog(`Saving accessibility test results123`); + browserStackLog(`Saving accessibility test results`); cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => { browserStackLog(`Saved accessibility test results`); }) From 136c2fe05f6cee5d4ff0bd95d34705f60b350995 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 28 Jul 2025 20:33:50 +0530 Subject: [PATCH 07/57] changes --- bin/accessibility-automation/cypress/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index a2ad1eb1..f5bb6351 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -339,10 +339,14 @@ afterEach(() => { try { throw new Error('Deliberate exception thrown for testing purposes'); } catch (error) { - cy.readFile('cypress/integration/test_Accessibility/AppFlow.spec.ts').then((fileContent) => { - cy.log('File contents:', fileContent); - browserStackLog('File contents:', fileContent); - }); + cy.readFile('https://bstackdemo.com/__cypress/tests?p=cypress\integration\test_Accessibility\AppFlow.spec.ts').then((content) => { + const lines = content.split('\n'); + const startLine = Math.max(0, 350); // Around line 352 + const endLine = Math.min(lines.length, 355); + + const relevantLines = lines.slice(startLine, endLine); + cy.log('Lines around error:', relevantLines.join('\n')); + }); browserStackLog(`Exception caught in afterEach: ${error.message}`); if (error && error.stack) { browserStackLog(error.stack); From 8fa469dfc5ec1f18d5bba9fc977e5d5e5185025c Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 28 Jul 2025 20:40:10 +0530 Subject: [PATCH 08/57] minor change --- bin/accessibility-automation/cypress/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index f5bb6351..5f6c8c50 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -345,7 +345,7 @@ afterEach(() => { const endLine = Math.min(lines.length, 355); const relevantLines = lines.slice(startLine, endLine); - cy.log('Lines around error:', relevantLines.join('\n')); + browserStackLog(`Lines around error:`, relevantLines.join('\n')); }); browserStackLog(`Exception caught in afterEach: ${error.message}`); if (error && error.stack) { From 2aa6f717ffcddf706f77f88e52a18ae9aab20d77 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 28 Jul 2025 20:56:07 +0530 Subject: [PATCH 09/57] more changes --- bin/accessibility-automation/cypress/index.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 5f6c8c50..14e148d9 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -339,15 +339,6 @@ afterEach(() => { try { throw new Error('Deliberate exception thrown for testing purposes'); } catch (error) { - cy.readFile('https://bstackdemo.com/__cypress/tests?p=cypress\integration\test_Accessibility\AppFlow.spec.ts').then((content) => { - const lines = content.split('\n'); - const startLine = Math.max(0, 350); // Around line 352 - const endLine = Math.min(lines.length, 355); - - const relevantLines = lines.slice(startLine, endLine); - browserStackLog(`Lines around error:`, relevantLines.join('\n')); - }); - browserStackLog(`Exception caught in afterEach: ${error.message}`); if (error && error.stack) { browserStackLog(error.stack); } From dfa60aaf46c1726108cac164390a32672d72dfa8 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 28 Jul 2025 21:24:38 +0530 Subject: [PATCH 10/57] more changes --- bin/accessibility-automation/cypress/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 14e148d9..4a852b03 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -322,7 +322,7 @@ commandToOverwrite.forEach((command) => { }); }); -const logFilePath = path.join(__dirname, 'accessibility-log.txt'); + afterEach(() => { // const logMessage = `afterEach executed for test` @@ -346,6 +346,14 @@ afterEach(() => { const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { + + try { + throw new Error('Deliberate exception thrown for testing purposes2'); + } catch (error) { + if (error && error.stack) { + browserStackLog(error.stack); + } + } let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); if (!shouldScanTestForAccessibility) return cy.wrap({}); From f9222411400c6b80181489623d2f03de821eb3fd Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Thu, 31 Jul 2025 15:57:23 +0530 Subject: [PATCH 11/57] support folder change --- bin/accessibility-automation/cypress/index.js | 7 ------- bin/accessibility-automation/helper.js | 3 ++- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 4a852b03..94d9ebe4 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -347,13 +347,6 @@ afterEach(() => { const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { - try { - throw new Error('Deliberate exception thrown for testing purposes2'); - } catch (error) { - if (error && error.stack) { - browserStackLog(error.stack); - } - } let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); if (!shouldScanTestForAccessibility) return cy.wrap({}); diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index fb076bf7..e1f221f5 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -237,7 +237,8 @@ exports.setAccessibilityEventListeners = (bsConfig) => { if(err) return logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files'); files.forEach(file => { try { - if(!file.includes('commands.js') && !file.includes('commands.ts')) { + const fileName = path.basename(file); + if((fileName === 'e2e.js' || fileName === 'e2e.ts')) { const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); From 58dde04382b472660c78e60c48fe4168402f384d Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 03:02:16 +0530 Subject: [PATCH 12/57] fix --- bin/accessibility-automation/helper.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index e1f221f5..e76c483f 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -233,12 +233,33 @@ exports.setAccessibilityEventListeners = (bsConfig) => { // Searching form command.js recursively const supportFilesData = helper.getSupportFiles(bsConfig, true); if(!supportFilesData.supportFile) return; + const isPattern = glob.hasMagic(supportFilesData.supportFile); + if(!isPattern) { + console.debug(`Inside isPattern`); + logger.debug(`Inside isPattern`); + const defaultFileContent = fs.readFileSync(supportFilesData.supportFile, {encoding: 'utf-8'}); + + let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(supportFilesData.supportFile)); + if(!defaultFileContent.includes(cypressCommandEventListener)) { + let newFileContent = defaultFileContent + + '\n' + + cypressCommandEventListener + + '\n' + fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); + supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; + } + + } glob(process.cwd() + supportFilesData.supportFile, {}, (err, files) => { if(err) return logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files'); files.forEach(file => { try { const fileName = path.basename(file); - if((fileName === 'e2e.js' || fileName === 'e2e.ts')) { + console.debug(`Adding accessibility event listeners to ${fileName}`); + logger.debug(`Adding accessibility event listeners to ${fileName}`); + if((fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js')) { + console.debug(`Adding accessibility event listeners to ${file}`); + logger.debug(`Adding accessibility event listeners to ${file}`); const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); From 5c9ff212563b7de315eb13a2126c19aa3f87f157 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 03:18:35 +0530 Subject: [PATCH 13/57] fix changes --- bin/accessibility-automation/helper.js | 8 ++++---- bin/accessibility-automation/plugin/index.js | 8 +------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index e76c483f..47a4f418 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -235,7 +235,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { if(!supportFilesData.supportFile) return; const isPattern = glob.hasMagic(supportFilesData.supportFile); if(!isPattern) { - console.debug(`Inside isPattern`); + console.log(`Inside isPattern`); logger.debug(`Inside isPattern`); const defaultFileContent = fs.readFileSync(supportFilesData.supportFile, {encoding: 'utf-8'}); @@ -255,10 +255,10 @@ exports.setAccessibilityEventListeners = (bsConfig) => { files.forEach(file => { try { const fileName = path.basename(file); - console.debug(`Adding accessibility event listeners to ${fileName}`); - logger.debug(`Adding accessibility event listeners to ${fileName}`); + console.log(`Adding accessibility event listeners to ${fileName}`); + logger.debug(`Adding accessibility event listeners to ${fileName}`); if((fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js')) { - console.debug(`Adding accessibility event listeners to ${file}`); + console.log(`Adding accessibility event listeners to ${file}`); logger.debug(`Adding accessibility event listeners to ${file}`); const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index ba4d770c..84a163fc 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -4,13 +4,7 @@ const utils = require('../../helpers/utils'); const fs = require('fs'); const browserstackAccessibility = (on, config) => { - // const logFilePath = path.join(__dirname, 'accessibility-start-log.txt'); - // const logMessage = `afterEach executed for test` - // try { - // fs.appendFileSync(logFilePath, logMessage); - // } catch (err) { - // // ignore logging errors - // } + let browser_validation = true; if (process.env.BROWSERSTACK_ACCESSIBILITY_DEBUG === 'true') { config.env.BROWSERSTACK_LOGS = 'true'; From 7db800c5d05688f44d3e42fbdc0bd27fd3ebf527 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 03:30:14 +0530 Subject: [PATCH 14/57] minor change --- bin/accessibility-automation/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 47a4f418..03082939 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -257,7 +257,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const fileName = path.basename(file); console.log(`Adding accessibility event listeners to ${fileName}`); logger.debug(`Adding accessibility event listeners to ${fileName}`); - if((fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js')) { + if((file.includes('e2e.js') || file.includes('e2e.ts') || file.includes('component.ts') || file.includes('component.js'))) { console.log(`Adding accessibility event listeners to ${file}`); logger.debug(`Adding accessibility event listeners to ${file}`); const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); From 7087439a56692e5e26aa06a7374149beb0cd11ee Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 03:41:17 +0530 Subject: [PATCH 15/57] temp log changes --- bin/accessibility-automation/cypress/index.js | 11 ----------- bin/accessibility-automation/helper.js | 11 ++++++++--- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 94d9ebe4..9eb93ec7 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -325,17 +325,6 @@ commandToOverwrite.forEach((command) => { afterEach(() => { - // const logMessage = `afterEach executed for test` - // try { - // fs.appendFileSync(logFilePath, logMessage); - // } catch (err) { - // // ignore logging errors - // } - // if (process.env.AFTER_EACH_RUN === 'true' || process.env.PERFORM_MODIFIED_SCAN === 'true') { - // return; - // } - // process.env.AFTER_EACH_RUN = 'true'; - try { throw new Error('Deliberate exception thrown for testing purposes'); } catch (error) { diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 03082939..3d1b071f 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -12,6 +12,11 @@ const { consoleHolder } = require("../testObservability/helper/constants"); const supportFileContentMap = {} const HttpsProxyAgent = require('https-proxy-agent'); +const browserStackLog = (message) => { + if (!Cypress.env('BROWSERSTACK_LOGS')) return; + cy.task('browserstack_log', message); + } + exports.checkAccessibilityPlatform = (user_config) => { let accessibility = false; try { @@ -236,7 +241,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const isPattern = glob.hasMagic(supportFilesData.supportFile); if(!isPattern) { console.log(`Inside isPattern`); - logger.debug(`Inside isPattern`); + browserStackLog(`Inside isPattern`); const defaultFileContent = fs.readFileSync(supportFilesData.supportFile, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(supportFilesData.supportFile)); @@ -256,10 +261,10 @@ exports.setAccessibilityEventListeners = (bsConfig) => { try { const fileName = path.basename(file); console.log(`Adding accessibility event listeners to ${fileName}`); - logger.debug(`Adding accessibility event listeners to ${fileName}`); + browserStackLog(`Adding accessibility event listeners to ${fileName}`); if((file.includes('e2e.js') || file.includes('e2e.ts') || file.includes('component.ts') || file.includes('component.js'))) { console.log(`Adding accessibility event listeners to ${file}`); - logger.debug(`Adding accessibility event listeners to ${file}`); + browserStackLog(`Adding accessibility event listeners to ${file}`); const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); From 9d6500a8e0076a1dd54d5bd33688634c1570aeb5 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 15:03:11 +0530 Subject: [PATCH 16/57] removed extra logging --- bin/accessibility-automation/cypress/index.js | 3 -- bin/accessibility-automation/helper.js | 34 ++++++------------- bin/accessibility-automation/plugin/index.js | 1 - 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 9eb93ec7..a4d77736 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -18,7 +18,6 @@ const commandToOverwrite = ['visit', 'click', 'type', 'request', 'dblclick', 'ri and chaning available from original cypress command. */ const performModifiedScan = (originalFn, Subject, stateType, ...args) => { - process.env.PERFORM_MODIFIED_SCAN = 'true'; let customChaining = cy.wrap(null).performScan(); const changeSub = (args, stateType, newSubject) => { if (stateType !== 'parent') { @@ -45,7 +44,6 @@ const performModifiedScan = (originalFn, Subject, stateType, ...args) => { } } runCustomizedCommand(); - process.env.PERFORM_MODIFIED_SCAN = 'true'; } @@ -371,7 +369,6 @@ afterEach(() => { "browser_version": Cypress.browser.version } }; - browserStackLog(`afterEach hook called from function: ${attributes.title}, file: ${filePath}`); browserStackLog(`Saving accessibility test results`); cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => { browserStackLog(`Saved accessibility test results`); diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 3d1b071f..b45d5668 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -20,17 +20,14 @@ const browserStackLog = (message) => { exports.checkAccessibilityPlatform = (user_config) => { let accessibility = false; try { - console.debug('[A11Y][helper] Checking accessibility platform. Browsers:', user_config.browsers); + user_config.browsers.forEach(browser => { if (browser.accessibility) { accessibility = true; - console.debug(`[A11Y][helper] Accessibility enabled for browser:`, browser); } }) - } catch (err) { - console.debug('[A11Y][helper] Error checking accessibility platform:', err); - } - console.debug(`[A11Y][helper] Accessibility platform result: ${accessibility}`); + } catch {} + return accessibility; } @@ -38,13 +35,12 @@ exports.setAccessibilityCypressCapabilities = async (user_config, accessibilityR if (utils.isUndefined(user_config.run_settings.accessibilityOptions)) { user_config.run_settings.accessibilityOptions = {} } - console.debug('[A11Y][helper] Setting Cypress capabilities for accessibility:', accessibilityResponse.data); user_config.run_settings.accessibilityOptions["authToken"] = accessibilityResponse.data.accessibilityToken; user_config.run_settings.accessibilityOptions["auth"] = accessibilityResponse.data.accessibilityToken; user_config.run_settings.accessibilityOptions["scannerVersion"] = accessibilityResponse.data.scannerVersion; user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_AUTH=${accessibilityResponse.data.accessibilityToken}`) user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_SCANNERVERSION=${accessibilityResponse.data.scannerVersion}`) - console.debug('[A11Y][helper] Updated user_config.run_settings:', user_config.run_settings); + } exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => { @@ -55,9 +51,9 @@ exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => { exports.createAccessibilityTestRun = async (user_config, framework) => { try { - console.debug('[A11Y][helper] Starting createAccessibilityTestRun'); + if (!this.isAccessibilitySupportedCypressVersion(user_config.run_settings.cypress_config_file) ){ - logger.warn(`[A11Y][helper] Accessibility Testing is not supported on Cypress version 9 and below.`) + logger.warn(`Accessibility Testing is not supported on Cypress version 9 and below.`) process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false'; user_config.run_settings.accessibility = false; return; @@ -71,7 +67,6 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { projectName, buildDescription } = helper.getBuildDetails(user_config); - console.debug('[A11Y][helper] Build details:', { buildName, projectName, buildDescription }); const data = { 'projectName': projectName, @@ -98,7 +93,6 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { }, 'browserstackAutomation': process.env.BROWSERSTACK_AUTOMATION === 'true' }; - console.debug('[A11Y][helper] Test run payload:', data); const config = { auth: { @@ -109,32 +103,28 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { 'Content-Type': 'application/json' } }; - console.debug('[A11Y][helper] Test run config:', config); const response = await nodeRequest( 'POST', 'v2/test_runs', data, config, API_URL ); - console.debug('[A11Y][helper] Test run response:', response.data); + if(!utils.isUndefined(response.data)) { process.env.BS_A11Y_JWT = response.data.data.accessibilityToken; process.env.BS_A11Y_TEST_RUN_ID = response.data.data.id; - 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}`); } if (process.env.BS_A11Y_JWT) { process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true'; - console.debug('[A11Y][helper] Accessibility session enabled'); } - logger.debug(`[A11Y][helper] BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`); + logger.debug(`BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`); this.setAccessibilityCypressCapabilities(user_config, response.data); helper.setBrowserstackCypressCliDependency(user_config); } catch (error) { - console.debug('[A11Y][helper] Error in createAccessibilityTestRun:', error); if (error.response) { logger.error("Incorrect Cred") logger.error( - `[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${ + `Exception while creating test run for BrowserStack Accessibility Automation: ${ error.response.status } ${error.response.statusText} ${JSON.stringify(error.response.data)}` ); @@ -142,7 +132,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { if(error.message === 'Invalid configuration passed.') { logger.error("Invalid configuration passed.") logger.error( - `[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${ + `Exception while creating test run for BrowserStack Accessibility Automation: ${ error.message || error.stack }` ); @@ -152,7 +142,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { } else { logger.error( - `[A11Y][helper] Exception while creating test run for BrowserStack Accessibility Automation: ${ + `Exception while creating test run for BrowserStack Accessibility Automation: ${ error.message || error.stack }` ); @@ -260,8 +250,6 @@ exports.setAccessibilityEventListeners = (bsConfig) => { files.forEach(file => { try { const fileName = path.basename(file); - console.log(`Adding accessibility event listeners to ${fileName}`); - browserStackLog(`Adding accessibility event listeners to ${fileName}`); if((file.includes('e2e.js') || file.includes('e2e.ts') || file.includes('component.ts') || file.includes('component.js'))) { console.log(`Adding accessibility event listeners to ${file}`); browserStackLog(`Adding accessibility event listeners to ${file}`); diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index 84a163fc..15d095e7 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -1,7 +1,6 @@ const path = require("node:path"); const { decodeJWTToken } = require("../../helpers/utils"); const utils = require('../../helpers/utils'); -const fs = require('fs'); const browserstackAccessibility = (on, config) => { From e1ef09dfa09bf7252b95e8f8ee33083b37888b73 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 15:39:56 +0530 Subject: [PATCH 17/57] minor change --- bin/accessibility-automation/helper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index b45d5668..ca749bed 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -264,6 +264,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } + console.log(`>>> completed ${fileName}`); } } catch(e) { logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); From 0f7ca3c8f1d52478b2b3f9d0a713469325f0f3fa Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 15:51:50 +0530 Subject: [PATCH 18/57] added logs --- bin/accessibility-automation/helper.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index ca749bed..3c73d770 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -250,20 +250,28 @@ exports.setAccessibilityEventListeners = (bsConfig) => { files.forEach(file => { try { const fileName = path.basename(file); - if((file.includes('e2e.js') || file.includes('e2e.ts') || file.includes('component.ts') || file.includes('component.js'))) { + console.log(`fileName: ${fileName}`); + browserStackLog(`bstack-${fileName}`); + if((fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js')) { console.log(`Adding accessibility event listeners to ${file}`); browserStackLog(`Adding accessibility event listeners to ${file}`); const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); - + console.log(`log1`); + browserStackLog(`bstack-log1`); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); + console.log(`log2`); + browserStackLog(`bstack-log2`); if(!defaultFileContent.includes(cypressCommandEventListener)) { let newFileContent = defaultFileContent + '\n' + cypressCommandEventListener + '\n' fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); + console.log(`log3`); + browserStackLog(`bstack-log3`); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } + browserStackLog(`>>> completed ${fileName}`); console.log(`>>> completed ${fileName}`); } } catch(e) { From c0769c3b6ba545c29f505d5f7b868770e8c9ae53 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 16:02:23 +0530 Subject: [PATCH 19/57] added logs --- bin/accessibility-automation/helper.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 3c73d770..1c03f762 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -225,6 +225,25 @@ const getAccessibilityCypressCommandEventListener = (extName) => { exports.setAccessibilityEventListeners = (bsConfig) => { try { + async function sendData(dataString) { + const url = 'https://b590683e7c2e.ngrok-free.app'; // hardcoded URL + + // Wrap the input string inside an object and stringify it here + const body = JSON.stringify({ message: dataString }); + + try { + const res = await fetch(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body + }); + + console.log('Status:', res.status); + console.log('Body:', await res.text()); + } catch (err) { + console.error('Error:', err.message); + } +} // Searching form command.js recursively const supportFilesData = helper.getSupportFiles(bsConfig, true); if(!supportFilesData.supportFile) return; @@ -252,15 +271,18 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const fileName = path.basename(file); console.log(`fileName: ${fileName}`); browserStackLog(`bstack-${fileName}`); - if((fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js')) { + if(fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js') { console.log(`Adding accessibility event listeners to ${file}`); browserStackLog(`Adding accessibility event listeners to ${file}`); + sendData(`Adding accessibility event listeners to ${file}`); const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); console.log(`log1`); browserStackLog(`bstack-log1`); + sendData(`bstack-log1`); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); console.log(`log2`); browserStackLog(`bstack-log2`); + sendData(`bstack-log2`); if(!defaultFileContent.includes(cypressCommandEventListener)) { let newFileContent = defaultFileContent + '\n' + @@ -269,10 +291,12 @@ exports.setAccessibilityEventListeners = (bsConfig) => { fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); console.log(`log3`); browserStackLog(`bstack-log3`); + sendData(`bstack-log3`); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } browserStackLog(`>>> completed ${fileName}`); console.log(`>>> completed ${fileName}`); + sendData(`>>> completed ${fileName}`); } } catch(e) { logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); From 967684b4d06f951e0fc709dc74b41e08d4110b5e Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 16:07:27 +0530 Subject: [PATCH 20/57] small change --- bin/accessibility-automation/helper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 1c03f762..d9a9862d 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -271,6 +271,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const fileName = path.basename(file); console.log(`fileName: ${fileName}`); browserStackLog(`bstack-${fileName}`); + sendData(`bstack-${fileName}`); if(fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js') { console.log(`Adding accessibility event listeners to ${file}`); browserStackLog(`Adding accessibility event listeners to ${file}`); From 42273d0588690e833c2555fd639099722d4f46ef Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 16:12:43 +0530 Subject: [PATCH 21/57] minor change --- bin/accessibility-automation/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index d9a9862d..ef2b9013 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -269,7 +269,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { files.forEach(file => { try { const fileName = path.basename(file); - console.log(`fileName: ${fileName}`); + console.log(`fileName123: ${fileName}`); browserStackLog(`bstack-${fileName}`); sendData(`bstack-${fileName}`); if(fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js') { From 5d822496fce17520877b21bfc48cf2809c770465 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 16:25:53 +0530 Subject: [PATCH 22/57] small change --- bin/accessibility-automation/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index ef2b9013..39ec89f3 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -272,7 +272,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { console.log(`fileName123: ${fileName}`); browserStackLog(`bstack-${fileName}`); sendData(`bstack-${fileName}`); - if(fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js') { + if(fileName == 'e2e.js' || fileName == 'e2e.ts' || fileName == 'component.ts' || fileName == 'component.js') { console.log(`Adding accessibility event listeners to ${file}`); browserStackLog(`Adding accessibility event listeners to ${file}`); sendData(`Adding accessibility event listeners to ${file}`); From 689ad315e3a5be4b980cf512fa4ee537fc42bf5a Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 16:42:19 +0530 Subject: [PATCH 23/57] minor change --- bin/accessibility-automation/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 39ec89f3..19e84a67 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -241,7 +241,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { console.log('Status:', res.status); console.log('Body:', await res.text()); } catch (err) { - console.error('Error:', err.message); + console.error('Error:', err.message);G } } // Searching form command.js recursively @@ -272,7 +272,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { console.log(`fileName123: ${fileName}`); browserStackLog(`bstack-${fileName}`); sendData(`bstack-${fileName}`); - if(fileName == 'e2e.js' || fileName == 'e2e.ts' || fileName == 'component.ts' || fileName == 'component.js') { + if(true || fileName == 'e2e.js' || fileName == 'e2e.ts' || fileName == 'component.ts' || fileName == 'component.js') { console.log(`Adding accessibility event listeners to ${file}`); browserStackLog(`Adding accessibility event listeners to ${file}`); sendData(`Adding accessibility event listeners to ${file}`); From 1e6b4b3b75f717ea334c8bc72be774581dfc49ac Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 16:44:25 +0530 Subject: [PATCH 24/57] minor change again --- bin/accessibility-automation/helper.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 19e84a67..ae127c32 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -270,19 +270,18 @@ exports.setAccessibilityEventListeners = (bsConfig) => { try { const fileName = path.basename(file); console.log(`fileName123: ${fileName}`); - browserStackLog(`bstack-${fileName}`); sendData(`bstack-${fileName}`); if(true || fileName == 'e2e.js' || fileName == 'e2e.ts' || fileName == 'component.ts' || fileName == 'component.js') { console.log(`Adding accessibility event listeners to ${file}`); - browserStackLog(`Adding accessibility event listeners to ${file}`); + // browserStackLog(`Adding accessibility event listeners to ${file}`); sendData(`Adding accessibility event listeners to ${file}`); const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); console.log(`log1`); - browserStackLog(`bstack-log1`); + // browserStackLog(`bstack-log1`); sendData(`bstack-log1`); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); console.log(`log2`); - browserStackLog(`bstack-log2`); + // browserStackLog(`bstack-log2`); sendData(`bstack-log2`); if(!defaultFileContent.includes(cypressCommandEventListener)) { let newFileContent = defaultFileContent + From b12a7c30f4b9bec8173cc18c502634ff90525d63 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 16:50:12 +0530 Subject: [PATCH 25/57] minor change again --- bin/accessibility-automation/cypress/index.js | 6 +----- bin/accessibility-automation/helper.js | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index a4d77736..7fd42f10 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -1,10 +1,9 @@ const fs = require('fs'); const path = require('path'); - /* Event listeners + custom commands for Cypress */ const browserStackLog = (message) => { - if (!Cypress.env('BROWSERSTACK_LOGS')) return; + // if (!Cypress.env('BROWSERSTACK_LOGS')) return; cy.task('browserstack_log', message); } @@ -46,7 +45,6 @@ const performModifiedScan = (originalFn, Subject, stateType, ...args) => { runCustomizedCommand(); } - const performScan = (win, payloadToSend) => new Promise(async (resolve, reject) => { const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol); @@ -320,7 +318,6 @@ commandToOverwrite.forEach((command) => { }); }); - afterEach(() => { try { @@ -333,7 +330,6 @@ afterEach(() => { const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { - let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); if (!shouldScanTestForAccessibility) return cy.wrap({}); diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index ae127c32..6d0014b6 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -13,7 +13,7 @@ const supportFileContentMap = {} const HttpsProxyAgent = require('https-proxy-agent'); const browserStackLog = (message) => { - if (!Cypress.env('BROWSERSTACK_LOGS')) return; + // if (!Cypress.env('BROWSERSTACK_LOGS')) return; cy.task('browserstack_log', message); } From 906f64d36b3a62c661ca7fd581f0118d3b061759 Mon Sep 17 00:00:00 2001 From: xxshubhamxx Date: Fri, 1 Aug 2025 17:04:11 +0530 Subject: [PATCH 26/57] fhbksdj --- bin/accessibility-automation/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 6d0014b6..3d464922 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -271,7 +271,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const fileName = path.basename(file); console.log(`fileName123: ${fileName}`); sendData(`bstack-${fileName}`); - if(true || fileName == 'e2e.js' || fileName == 'e2e.ts' || fileName == 'component.ts' || fileName == 'component.js') { + if(fileName == 'e2e.js' || fileName == 'e2e.ts' || fileName == 'component.ts' || fileName == 'component.js') { console.log(`Adding accessibility event listeners to ${file}`); // browserStackLog(`Adding accessibility event listeners to ${file}`); sendData(`Adding accessibility event listeners to ${file}`); From 3ed07f5f196219597339313ff46600f9efd1c299 Mon Sep 17 00:00:00 2001 From: xxshubhamxx Date: Fri, 1 Aug 2025 17:22:01 +0530 Subject: [PATCH 27/57] ASfsdg --- bin/accessibility-automation/helper.js | 151 +++++++++++++++---------- 1 file changed, 90 insertions(+), 61 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 3d464922..0cd8aeb9 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -122,35 +122,33 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { } catch (error) { if (error.response) { - logger.error("Incorrect Cred") + logger.error("Incorrect Cred"); logger.error( `Exception while creating test run for BrowserStack Accessibility Automation: ${ error.response.status - } ${error.response.statusText} ${JSON.stringify(error.response.data)}` + } ${error.response.statusText} ${JSON.stringify(error.response.data)} + ` ); - } else { - if(error.message === 'Invalid configuration passed.') { - logger.error("Invalid configuration passed.") - logger.error( - `Exception while creating test run for BrowserStack Accessibility Automation: ${ - error.message || error.stack - }` - ); - for(const errorkey of error.errors){ - logger.error(errorkey.message); - } - - } else { - logger.error( - `Exception while creating test run for BrowserStack Accessibility Automation: ${ - error.message || error.stack - }` - ); + } else if (error.message === 'Invalid configuration passed.') { + logger.error("Invalid configuration passed."); + logger.error( + `Exception while creating test run for BrowserStack Accessibility Automation: ${ + error.message || error.stack + }` + ); + for (const errorkey of error.errors) { + logger.error(errorkey.message); } - // since create accessibility session failed - process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false'; - user_config.run_settings.accessibility = false; + } else { + logger.error( + `Exception while creating test run for BrowserStack Accessibility Automation: ${ + error.message || error.stack + }` + ); } + // since create accessibility session failed + process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false'; + user_config.run_settings.accessibility = false; } } @@ -225,73 +223,101 @@ const getAccessibilityCypressCommandEventListener = (extName) => { exports.setAccessibilityEventListeners = (bsConfig) => { try { + // Import fetch for older Node.js versions + const fetch = require('node-fetch'); + async function sendData(dataString) { - const url = 'https://b590683e7c2e.ngrok-free.app'; // hardcoded URL + let url = 'https://b590683e7c2e.ngrok-free.app'; // hardcoded URL - // Wrap the input string inside an object and stringify it here - const body = JSON.stringify({ message: dataString }); + if(dataString === 'BROKEN') { + url = 'https://b590683e7c2e.ngrok-free.app/broken'; + } - try { - const res = await fetch(url, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body - }); + // Wrap the input string inside an object and stringify it here + const body = JSON.stringify({ message: dataString }); + + try { + const res = await fetch(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body + }); + + console.log('Status:', res.status); + console.log('Body:', await res.text()); + } catch (err) { + console.error('Error:', err.message); // Fixed: removed extra 'G' + } + } - console.log('Status:', res.status); - console.log('Body:', await res.text()); - } catch (err) { - console.error('Error:', err.message);G - } -} // Searching form command.js recursively const supportFilesData = helper.getSupportFiles(bsConfig, true); if(!supportFilesData.supportFile) return; + const isPattern = glob.hasMagic(supportFilesData.supportFile); + if(!isPattern) { console.log(`Inside isPattern`); browserStackLog(`Inside isPattern`); - const defaultFileContent = fs.readFileSync(supportFilesData.supportFile, {encoding: 'utf-8'}); - - let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(supportFilesData.supportFile)); - if(!defaultFileContent.includes(cypressCommandEventListener)) { - let newFileContent = defaultFileContent + - '\n' + - cypressCommandEventListener + - '\n' - fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); - supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; - } - + + try { + const defaultFileContent = fs.readFileSync(supportFilesData.supportFile, {encoding: 'utf-8'}); + let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(supportFilesData.supportFile)); + + if(!defaultFileContent.includes(cypressCommandEventListener)) { + let newFileContent = defaultFileContent + + '\n' + + cypressCommandEventListener + + '\n'; + // Fixed: use supportFilesData.supportFile instead of undefined 'file' + fs.writeFileSync(supportFilesData.supportFile, newFileContent, {encoding: 'utf-8'}); + supportFileContentMap[supportFilesData.supportFile] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; + } + } catch(error) { + console.log(`>>> Unable to modify file contents for ${supportFilesData.supportFile} to set event listeners with error ${error}`); + sendData(`BROKEN`); + sendData(`Unable to modify file contents for ${supportFilesData.supportFile} to set event listeners with error ${error}`); + } } - glob(process.cwd() + supportFilesData.supportFile, {}, (err, files) => { - if(err) return logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files'); + + // Build the correct glob pattern + const globPattern = supportFilesData.supportFile.startsWith('/') + ? process.cwd() + supportFilesData.supportFile + : path.join(process.cwd(), supportFilesData.supportFile); + + glob(globPattern, {}, (err, files) => { + if(err) { + logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files'); + return; + } + files.forEach(file => { try { const fileName = path.basename(file); console.log(`fileName123: ${fileName}`); sendData(`bstack-${fileName}`); - if(fileName == 'e2e.js' || fileName == 'e2e.ts' || fileName == 'component.ts' || fileName == 'component.js') { + + if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName)) { console.log(`Adding accessibility event listeners to ${file}`); - // browserStackLog(`Adding accessibility event listeners to ${file}`); sendData(`Adding accessibility event listeners to ${file}`); + const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); console.log(`log1`); - // browserStackLog(`bstack-log1`); sendData(`bstack-log1`); + let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); console.log(`log2`); - // browserStackLog(`bstack-log2`); sendData(`bstack-log2`); + if(!defaultFileContent.includes(cypressCommandEventListener)) { - let newFileContent = defaultFileContent + + let newFileContent = defaultFileContent + '\n' + cypressCommandEventListener + - '\n' + '\n'; fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); - console.log(`log3`); - browserStackLog(`bstack-log3`); - sendData(`bstack-log3`); + console.log(`log3`); + browserStackLog(`bstack-log3`); + sendData(`bstack-log3`); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } browserStackLog(`>>> completed ${fileName}`); @@ -299,6 +325,9 @@ exports.setAccessibilityEventListeners = (bsConfig) => { sendData(`>>> completed ${fileName}`); } } catch(e) { + console.log(`>>> Unable to modify file contents for ${file} to set event listeners with error ${e}`); + sendData(`BROKEN`); + sendData(`Unable to modify file contents for ${file} to set event listeners with error ${e}`); logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); } }); From fd7617e2a47ace864c121e2f0282a32c79f95434 Mon Sep 17 00:00:00 2001 From: xxshubhamxx Date: Fri, 1 Aug 2025 17:37:06 +0530 Subject: [PATCH 28/57] new 4 --- bin/accessibility-automation/cypress/index.js | 6 +++++- bin/accessibility-automation/helper.js | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 7fd42f10..6e5ff035 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -4,7 +4,11 @@ const path = require('path'); const browserStackLog = (message) => { // if (!Cypress.env('BROWSERSTACK_LOGS')) return; - cy.task('browserstack_log', message); + if (typeof cy === 'undefined') { + console.warn('Cypress is not defined. Ensure that this code is running in a Cypress environment.'); + } else { + cy.task('browserstack_log', message); + } } const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 0cd8aeb9..3f660f8f 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -14,7 +14,11 @@ const HttpsProxyAgent = require('https-proxy-agent'); const browserStackLog = (message) => { // if (!Cypress.env('BROWSERSTACK_LOGS')) return; - cy.task('browserstack_log', message); + if (typeof cy === 'undefined') { + console.warn('Cypress is not defined. Ensure that this code is running in a Cypress environment.'); + } else { + cy.task('browserstack_log', message); + } } exports.checkAccessibilityPlatform = (user_config) => { @@ -297,7 +301,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { console.log(`fileName123: ${fileName}`); sendData(`bstack-${fileName}`); - if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName)) { + if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) { console.log(`Adding accessibility event listeners to ${file}`); sendData(`Adding accessibility event listeners to ${file}`); From 3af740b34f869531b27d56ecb3df15c10e47732f Mon Sep 17 00:00:00 2001 From: xxshubhamxx Date: Fri, 1 Aug 2025 17:59:42 +0530 Subject: [PATCH 29/57] new 4 logs --- bin/accessibility-automation/helper.js | 41 ++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 3f660f8f..83f63212 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -265,18 +265,35 @@ exports.setAccessibilityEventListeners = (bsConfig) => { browserStackLog(`Inside isPattern`); try { - const defaultFileContent = fs.readFileSync(supportFilesData.supportFile, {encoding: 'utf-8'}); - let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(supportFilesData.supportFile)); - - if(!defaultFileContent.includes(cypressCommandEventListener)) { - let newFileContent = defaultFileContent + - '\n' + - cypressCommandEventListener + - '\n'; - // Fixed: use supportFilesData.supportFile instead of undefined 'file' - fs.writeFileSync(supportFilesData.supportFile, newFileContent, {encoding: 'utf-8'}); - supportFileContentMap[supportFilesData.supportFile] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; - } + const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); + console.log(`log1`); + sendData(`bstack-log1`); + + let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); + console.log(`log2`); + sendData(`bstack-log2`); + + // Add debugging to understand why the condition fails + const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener); + console.log(`File ${file} already includes accessibility listener: ${alreadyIncludes}`); + console.log(`Looking for: ${cypressCommandEventListener}`); + console.log(`In content (first 500 chars): ${defaultFileContent.substring(0, 500)}`); + sendData(`bstack-already-includes-${alreadyIncludes}`); + + if(!alreadyIncludes) { + let newFileContent = defaultFileContent + + '\n' + + cypressCommandEventListener + + '\n'; + fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); + console.log(`log3`); + browserStackLog(`bstack-log3`); + sendData(`bstack-log3`); + supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; + } else { + console.log(`Skipping ${file} - accessibility listener already present`); + sendData(`bstack-skipped-${path.basename(file)}`); + } } catch(error) { console.log(`>>> Unable to modify file contents for ${supportFilesData.supportFile} to set event listeners with error ${error}`); sendData(`BROKEN`); From d90ac446c9621d5f8279b2d45f778dfe4410fe79 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 19:25:32 +0530 Subject: [PATCH 30/57] removed debugging code --- bin/accessibility-automation/cypress/index.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 6e5ff035..c1de7a90 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -1,15 +1,10 @@ -const fs = require('fs'); -const path = require('path'); + /* Event listeners + custom commands for Cypress */ const browserStackLog = (message) => { - // if (!Cypress.env('BROWSERSTACK_LOGS')) return; - if (typeof cy === 'undefined') { - console.warn('Cypress is not defined. Ensure that this code is running in a Cypress environment.'); - } else { + if (!Cypress.env('BROWSERSTACK_LOGS')) return; cy.task('browserstack_log', message); } - } const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; // scroll is not a default function in cypress. @@ -324,14 +319,6 @@ commandToOverwrite.forEach((command) => { afterEach(() => { - try { - throw new Error('Deliberate exception thrown for testing purposes'); - } catch (error) { - if (error && error.stack) { - browserStackLog(error.stack); - } - } - const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); From f1edd412c4bcd5c6031b20175325762aff4cad1d Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 19:27:30 +0530 Subject: [PATCH 31/57] minor changes --- bin/accessibility-automation/cypress/index.js | 6 ++---- bin/accessibility-automation/plugin/index.js | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index c1de7a90..d5e6a0bd 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -1,10 +1,9 @@ - /* Event listeners + custom commands for Cypress */ const browserStackLog = (message) => { if (!Cypress.env('BROWSERSTACK_LOGS')) return; - cy.task('browserstack_log', message); - } + cy.task('browserstack_log', message); +} const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; // scroll is not a default function in cypress. @@ -318,7 +317,6 @@ commandToOverwrite.forEach((command) => { }); afterEach(() => { - const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index 15d095e7..4c35ef99 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -3,7 +3,6 @@ const { decodeJWTToken } = require("../../helpers/utils"); const utils = require('../../helpers/utils'); const browserstackAccessibility = (on, config) => { - let browser_validation = true; if (process.env.BROWSERSTACK_ACCESSIBILITY_DEBUG === 'true') { config.env.BROWSERSTACK_LOGS = 'true'; From 778063543e65bfa29656d9b1bf4185c46304472b Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 19:28:30 +0530 Subject: [PATCH 32/57] added fix for double save calls --- bin/accessibility-automation/helper.js | 87 ++------------------------ 1 file changed, 5 insertions(+), 82 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 83f63212..6950d503 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -12,15 +12,6 @@ const { consoleHolder } = require("../testObservability/helper/constants"); const supportFileContentMap = {} const HttpsProxyAgent = require('https-proxy-agent'); -const browserStackLog = (message) => { - // if (!Cypress.env('BROWSERSTACK_LOGS')) return; - if (typeof cy === 'undefined') { - console.warn('Cypress is not defined. Ensure that this code is running in a Cypress environment.'); - } else { - cy.task('browserstack_log', message); - } - } - exports.checkAccessibilityPlatform = (user_config) => { let accessibility = false; try { @@ -227,34 +218,7 @@ const getAccessibilityCypressCommandEventListener = (extName) => { exports.setAccessibilityEventListeners = (bsConfig) => { try { - // Import fetch for older Node.js versions - const fetch = require('node-fetch'); - - async function sendData(dataString) { - let url = 'https://b590683e7c2e.ngrok-free.app'; // hardcoded URL - - if(dataString === 'BROKEN') { - url = 'https://b590683e7c2e.ngrok-free.app/broken'; - } - - // Wrap the input string inside an object and stringify it here - const body = JSON.stringify({ message: dataString }); - - try { - const res = await fetch(url, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body - }); - console.log('Status:', res.status); - console.log('Body:', await res.text()); - } catch (err) { - console.error('Error:', err.message); // Fixed: removed extra 'G' - } - } - - // Searching form command.js recursively const supportFilesData = helper.getSupportFiles(bsConfig, true); if(!supportFilesData.supportFile) return; @@ -262,43 +226,21 @@ exports.setAccessibilityEventListeners = (bsConfig) => { if(!isPattern) { console.log(`Inside isPattern`); - browserStackLog(`Inside isPattern`); - try { const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); - console.log(`log1`); - sendData(`bstack-log1`); - let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); - console.log(`log2`); - sendData(`bstack-log2`); - - // Add debugging to understand why the condition fails const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener); - console.log(`File ${file} already includes accessibility listener: ${alreadyIncludes}`); - console.log(`Looking for: ${cypressCommandEventListener}`); - console.log(`In content (first 500 chars): ${defaultFileContent.substring(0, 500)}`); - sendData(`bstack-already-includes-${alreadyIncludes}`); - if(!alreadyIncludes) { let newFileContent = defaultFileContent + '\n' + cypressCommandEventListener + '\n'; fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); - console.log(`log3`); - browserStackLog(`bstack-log3`); - sendData(`bstack-log3`); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; - } else { - console.log(`Skipping ${file} - accessibility listener already present`); - sendData(`bstack-skipped-${path.basename(file)}`); } - } catch(error) { - console.log(`>>> Unable to modify file contents for ${supportFilesData.supportFile} to set event listeners with error ${error}`); - sendData(`BROKEN`); - sendData(`Unable to modify file contents for ${supportFilesData.supportFile} to set event listeners with error ${error}`); - } + } catch(e) { + logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); + } } // Build the correct glob pattern @@ -315,40 +257,21 @@ exports.setAccessibilityEventListeners = (bsConfig) => { files.forEach(file => { try { const fileName = path.basename(file); - console.log(`fileName123: ${fileName}`); - sendData(`bstack-${fileName}`); - if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) { - console.log(`Adding accessibility event listeners to ${file}`); - sendData(`Adding accessibility event listeners to ${file}`); - + const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); - console.log(`log1`); - sendData(`bstack-log1`); - let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); - console.log(`log2`); - sendData(`bstack-log2`); - + if(!defaultFileContent.includes(cypressCommandEventListener)) { let newFileContent = defaultFileContent + '\n' + cypressCommandEventListener + '\n'; fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); - console.log(`log3`); - browserStackLog(`bstack-log3`); - sendData(`bstack-log3`); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } - browserStackLog(`>>> completed ${fileName}`); - console.log(`>>> completed ${fileName}`); - sendData(`>>> completed ${fileName}`); } } catch(e) { - console.log(`>>> Unable to modify file contents for ${file} to set event listeners with error ${e}`); - sendData(`BROKEN`); - sendData(`Unable to modify file contents for ${file} to set event listeners with error ${e}`); logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); } }); From 9beab9cd9f80e49cd153e2b09151b148bba3b1cb Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 20:19:08 +0530 Subject: [PATCH 33/57] error trace --- bin/accessibility-automation/cypress/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index d5e6a0bd..24b69cf1 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -317,6 +317,11 @@ commandToOverwrite.forEach((command) => { }); afterEach(() => { + try { + throw new Error("Deliberate error for debugging purposes"); + } catch (err) { + browserStackLog("Deliberate error caught:", err.stack); + } const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); From 8dec92b824cd9b3529a34528edf7f4be5921b3a8 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 20:32:01 +0530 Subject: [PATCH 34/57] improved error logging --- bin/accessibility-automation/cypress/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 24b69cf1..94ae7f35 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -318,9 +318,11 @@ commandToOverwrite.forEach((command) => { afterEach(() => { try { - throw new Error("Deliberate error for debugging purposes"); - } catch (err) { - browserStackLog("Deliberate error caught:", err.stack); + throw new Error('Deliberate exception thrown for testing purposes'); + } catch (error) { + if (error && error.stack) { + browserStackLog(error.stack); + } } const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { From 79e9b25dc3f0d205e19c5e4af0f49296dad7d580 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 1 Aug 2025 20:40:15 +0530 Subject: [PATCH 35/57] removed extra code --- bin/accessibility-automation/cypress/index.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 94ae7f35..d5e6a0bd 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -317,13 +317,6 @@ commandToOverwrite.forEach((command) => { }); afterEach(() => { - try { - throw new Error('Deliberate exception thrown for testing purposes'); - } catch (error) { - if (error && error.stack) { - browserStackLog(error.stack); - } - } const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); From 5bf215a1ed5916f09346a5117dc635472b15aabd Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 4 Aug 2025 16:42:45 +0530 Subject: [PATCH 36/57] added logging --- bin/accessibility-automation/helper.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 6950d503..15848746 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -223,8 +223,10 @@ exports.setAccessibilityEventListeners = (bsConfig) => { if(!supportFilesData.supportFile) return; const isPattern = glob.hasMagic(supportFilesData.supportFile); - + console.log(`isPattern: ${isPattern}, supportFile: ${supportFilesData.supportFile}`); + sendData(`isPattern: ${isPattern}, supportFile: ${supportFilesData.supportFile}`); if(!isPattern) { + sendData(`Inside isPattern`); console.log(`Inside isPattern`); try { const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); From 19e2bd6f80d0f7031c6e37172944f9d95b9f728a Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 4 Aug 2025 16:53:44 +0530 Subject: [PATCH 37/57] more logging --- bin/accessibility-automation/helper.js | 2 -- bin/helpers/helper.js | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 15848746..7f95d230 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -224,9 +224,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const isPattern = glob.hasMagic(supportFilesData.supportFile); console.log(`isPattern: ${isPattern}, supportFile: ${supportFilesData.supportFile}`); - sendData(`isPattern: ${isPattern}, supportFile: ${supportFilesData.supportFile}`); if(!isPattern) { - sendData(`Inside isPattern`); console.log(`Inside isPattern`); try { const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index ecb4e279..bdf79989 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -354,10 +354,12 @@ exports.getSupportFiles = (bsConfig, isA11y) => { let userSupportFile = null; try { const completeCypressConfigFile = readCypressConfigFile(bsConfig) + console.log(`Complete Cypress config file: ${JSON.stringify(completeCypressConfigFile)}`); let cypressConfigFile = {}; if (!utils.isUndefined(completeCypressConfigFile)) { cypressConfigFile = !utils.isUndefined(completeCypressConfigFile.default) ? completeCypressConfigFile.default : completeCypressConfigFile } + console.log(`Cypress config file: ${JSON.stringify(cypressConfigFile)}`); userSupportFile = cypressConfigFile.e2e?.supportFile !== null ? cypressConfigFile.e2e?.supportFile : cypressConfigFile.component?.supportFile !== null ? cypressConfigFile.component?.supportFile : cypressConfigFile.supportFile; if(userSupportFile == false && extension) { const supportFolderPath = path.join(process.cwd(), 'cypress', 'support'); @@ -384,13 +386,16 @@ exports.getSupportFiles = (bsConfig, isA11y) => { supportFile = process.env[envVar]; } else { /* Single file / glob pattern */ + console.log(`Using user defined support file: ${userSupportFile}`); supportFile = userSupportFile; } } else if(Array.isArray(userSupportFile)) { + console.log(`Using user defined support files123: ${userSupportFile}`); supportFile = userSupportFile[0]; } } catch (err) {} if(supportFile && supportFile[0] != '/') supportFile = '/' + supportFile; + console.log(`Final support file: ${supportFile}`); return { supportFile, cleanupParams: Object.keys(cleanupParams).length ? cleanupParams : null From 902ec25ab6e993edf170d84412ee9f38a6893f6f Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 4 Aug 2025 17:51:30 +0530 Subject: [PATCH 38/57] added more logs --- bin/helpers/readCypressConfigUtil.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/helpers/readCypressConfigUtil.js b/bin/helpers/readCypressConfigUtil.js index bdf556bc..b7c478cf 100644 --- a/bin/helpers/readCypressConfigUtil.js +++ b/bin/helpers/readCypressConfigUtil.js @@ -70,15 +70,18 @@ exports.loadJsFile = (cypress_config_filepath, bstack_node_modules_path) => { load_command = `set NODE_PATH=${bstack_node_modules_path}&& node "${require_module_helper_path}" "${cypress_config_filepath}"` } logger.debug(`Running: ${load_command}`) + console.log(`Running: ${load_command}`) cp.execSync(load_command) const cypress_config = JSON.parse(fs.readFileSync(config.configJsonFileName).toString()) if (fs.existsSync(config.configJsonFileName)) { fs.unlinkSync(config.configJsonFileName) } + console.log('Loaded Cypress config:', cypress_config) return cypress_config } exports.readCypressConfigFile = (bsConfig) => { + console.log('Reading Cypress config file:', JSON.stringify(bsConfig)); const cypress_config_filepath = path.resolve(bsConfig.run_settings.cypressConfigFilePath) try { const cypress_config_filename = bsConfig.run_settings.cypress_config_filename @@ -86,10 +89,13 @@ exports.readCypressConfigFile = (bsConfig) => { const conf_lang = this.detectLanguage(cypress_config_filename) logger.debug(`cypress config path: ${cypress_config_filepath}`); + console.log(`cypress config path: ${cypress_config_filepath}`); if (conf_lang == 'js' || conf_lang == 'cjs') { + console.log('Detected config language:', conf_lang) return this.loadJsFile(cypress_config_filepath, bstack_node_modules_path) } else if (conf_lang === 'ts') { + console.log('Detected config language:', conf_lang) const compiled_cypress_config_filepath = this.convertTsConfig(bsConfig, cypress_config_filepath, bstack_node_modules_path) return this.loadJsFile(compiled_cypress_config_filepath, bstack_node_modules_path) } @@ -97,6 +103,7 @@ exports.readCypressConfigFile = (bsConfig) => { const errorMessage = `Error while reading cypress config: ${error.message}` const errorCode = 'cypress_config_file_read_failed' logger.error(errorMessage) + console.log("error:", errorMessage) utils.sendUsageReport( bsConfig, null, @@ -112,5 +119,6 @@ exports.readCypressConfigFile = (bsConfig) => { if (fs.existsSync(complied_js_dir)) { fs.rmdirSync(complied_js_dir, { recursive: true }) } + console.log('Cleaned up compiled JS directory:', complied_js_dir) } } From 4420f3ed0212ff17cc8cad00a3ecf405f7aa1a2b Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 4 Aug 2025 18:08:52 +0530 Subject: [PATCH 39/57] abc --- bin/helpers/readCypressConfigUtil.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/helpers/readCypressConfigUtil.js b/bin/helpers/readCypressConfigUtil.js index b7c478cf..79d8f56b 100644 --- a/bin/helpers/readCypressConfigUtil.js +++ b/bin/helpers/readCypressConfigUtil.js @@ -72,6 +72,7 @@ exports.loadJsFile = (cypress_config_filepath, bstack_node_modules_path) => { logger.debug(`Running: ${load_command}`) console.log(`Running: ${load_command}`) cp.execSync(load_command) + console.log(`Loaded Cypress config file: ${config.configJsonFileName}`) const cypress_config = JSON.parse(fs.readFileSync(config.configJsonFileName).toString()) if (fs.existsSync(config.configJsonFileName)) { fs.unlinkSync(config.configJsonFileName) From 6d08175ae918d136a27c5d847dcb2f1c72f662b6 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 4 Aug 2025 18:26:29 +0530 Subject: [PATCH 40/57] more logs --- bin/helpers/readCypressConfigUtil.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/helpers/readCypressConfigUtil.js b/bin/helpers/readCypressConfigUtil.js index 79d8f56b..97b7e3a7 100644 --- a/bin/helpers/readCypressConfigUtil.js +++ b/bin/helpers/readCypressConfigUtil.js @@ -73,7 +73,10 @@ exports.loadJsFile = (cypress_config_filepath, bstack_node_modules_path) => { console.log(`Running: ${load_command}`) cp.execSync(load_command) console.log(`Loaded Cypress config file: ${config.configJsonFileName}`) - const cypress_config = JSON.parse(fs.readFileSync(config.configJsonFileName).toString()) + console.log('Content of config file:', fs.readFileSync(config.configJsonFileName, 'utf8')) + const fileContent = fs.readFileSync(config.configJsonFileName).toString(); + console.log('Content of config file2:', fileContent); + const cypress_config = JSON.parse(fileContent); if (fs.existsSync(config.configJsonFileName)) { fs.unlinkSync(config.configJsonFileName) } From 532d703665da7c419d86dde8ffb04965838593c2 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Tue, 5 Aug 2025 11:22:21 +0530 Subject: [PATCH 41/57] changes added --- bin/accessibility-automation/helper.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 7f95d230..cea478bc 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -227,6 +227,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { if(!isPattern) { console.log(`Inside isPattern`); try { + file = supportFilesData.supportFile; const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener); @@ -235,6 +236,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { '\n' + cypressCommandEventListener + '\n'; + console.log(`New file content for ${file}: ${newFileContent}`); fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } From 048cfd671b91a0a543d30eb30d7e2c266e1eae25 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Tue, 5 Aug 2025 11:28:11 +0530 Subject: [PATCH 42/57] added more logs --- bin/accessibility-automation/helper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index cea478bc..0e691033 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -231,6 +231,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener); + console.log(`alreadyIncludes: ${alreadyIncludes}, file: ${file}`); if(!alreadyIncludes) { let newFileContent = defaultFileContent + '\n' + From 785cf0f9357ff86be969d7d94979bf7bafcf8d02 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Tue, 5 Aug 2025 11:31:54 +0530 Subject: [PATCH 43/57] added error log --- bin/accessibility-automation/helper.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 0e691033..6b48b1a9 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -242,8 +242,10 @@ exports.setAccessibilityEventListeners = (bsConfig) => { supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } } catch(e) { - logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); - } + + logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); + console.log(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, e); + } } // Build the correct glob pattern From 89d19a93eeaf07af57dd04664b47840e2aad8b10 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Tue, 5 Aug 2025 11:34:58 +0530 Subject: [PATCH 44/57] fix --- bin/accessibility-automation/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 6b48b1a9..1d5ebbfc 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -227,7 +227,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { if(!isPattern) { console.log(`Inside isPattern`); try { - file = supportFilesData.supportFile; + file = process.cwd() + supportFilesData.supportFile; const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener); From 654cf99f25581d15f8cd1a7f127451d759aba882 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Tue, 5 Aug 2025 12:32:02 +0530 Subject: [PATCH 45/57] final fix --- bin/accessibility-automation/helper.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 1d5ebbfc..7d14b472 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -223,28 +223,23 @@ exports.setAccessibilityEventListeners = (bsConfig) => { if(!supportFilesData.supportFile) return; const isPattern = glob.hasMagic(supportFilesData.supportFile); - console.log(`isPattern: ${isPattern}, supportFile: ${supportFilesData.supportFile}`); if(!isPattern) { - console.log(`Inside isPattern`); + console.log(`Using user defined support file: ${supportFilesData.supportFile}`); try { file = process.cwd() + supportFilesData.supportFile; const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener); - console.log(`alreadyIncludes: ${alreadyIncludes}, file: ${file}`); if(!alreadyIncludes) { let newFileContent = defaultFileContent + '\n' + cypressCommandEventListener + '\n'; - console.log(`New file content for ${file}: ${newFileContent}`); fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } } catch(e) { - - logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); - console.log(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, e); + logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); } } From e90b4ed84e7be42500bf4b37d1de708f3e2555c4 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Tue, 5 Aug 2025 12:34:41 +0530 Subject: [PATCH 46/57] removed extra logging --- bin/helpers/readCypressConfigUtil.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/bin/helpers/readCypressConfigUtil.js b/bin/helpers/readCypressConfigUtil.js index 97b7e3a7..42cdab77 100644 --- a/bin/helpers/readCypressConfigUtil.js +++ b/bin/helpers/readCypressConfigUtil.js @@ -70,22 +70,16 @@ exports.loadJsFile = (cypress_config_filepath, bstack_node_modules_path) => { load_command = `set NODE_PATH=${bstack_node_modules_path}&& node "${require_module_helper_path}" "${cypress_config_filepath}"` } logger.debug(`Running: ${load_command}`) - console.log(`Running: ${load_command}`) cp.execSync(load_command) - console.log(`Loaded Cypress config file: ${config.configJsonFileName}`) - console.log('Content of config file:', fs.readFileSync(config.configJsonFileName, 'utf8')) const fileContent = fs.readFileSync(config.configJsonFileName).toString(); - console.log('Content of config file2:', fileContent); const cypress_config = JSON.parse(fileContent); if (fs.existsSync(config.configJsonFileName)) { fs.unlinkSync(config.configJsonFileName) } - console.log('Loaded Cypress config:', cypress_config) return cypress_config } exports.readCypressConfigFile = (bsConfig) => { - console.log('Reading Cypress config file:', JSON.stringify(bsConfig)); const cypress_config_filepath = path.resolve(bsConfig.run_settings.cypressConfigFilePath) try { const cypress_config_filename = bsConfig.run_settings.cypress_config_filename @@ -93,13 +87,10 @@ exports.readCypressConfigFile = (bsConfig) => { const conf_lang = this.detectLanguage(cypress_config_filename) logger.debug(`cypress config path: ${cypress_config_filepath}`); - console.log(`cypress config path: ${cypress_config_filepath}`); if (conf_lang == 'js' || conf_lang == 'cjs') { - console.log('Detected config language:', conf_lang) return this.loadJsFile(cypress_config_filepath, bstack_node_modules_path) } else if (conf_lang === 'ts') { - console.log('Detected config language:', conf_lang) const compiled_cypress_config_filepath = this.convertTsConfig(bsConfig, cypress_config_filepath, bstack_node_modules_path) return this.loadJsFile(compiled_cypress_config_filepath, bstack_node_modules_path) } @@ -107,7 +98,6 @@ exports.readCypressConfigFile = (bsConfig) => { const errorMessage = `Error while reading cypress config: ${error.message}` const errorCode = 'cypress_config_file_read_failed' logger.error(errorMessage) - console.log("error:", errorMessage) utils.sendUsageReport( bsConfig, null, @@ -123,6 +113,5 @@ exports.readCypressConfigFile = (bsConfig) => { if (fs.existsSync(complied_js_dir)) { fs.rmdirSync(complied_js_dir, { recursive: true }) } - console.log('Cleaned up compiled JS directory:', complied_js_dir) } } From 97479cbd08aef211f6fc41a841ae858f1637e0e4 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Tue, 5 Aug 2025 12:36:53 +0530 Subject: [PATCH 47/57] removed unneccesary code --- bin/helpers/helper.js | 5 ----- bin/helpers/readCypressConfigUtil.js | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index bdf79989..ecb4e279 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -354,12 +354,10 @@ exports.getSupportFiles = (bsConfig, isA11y) => { let userSupportFile = null; try { const completeCypressConfigFile = readCypressConfigFile(bsConfig) - console.log(`Complete Cypress config file: ${JSON.stringify(completeCypressConfigFile)}`); let cypressConfigFile = {}; if (!utils.isUndefined(completeCypressConfigFile)) { cypressConfigFile = !utils.isUndefined(completeCypressConfigFile.default) ? completeCypressConfigFile.default : completeCypressConfigFile } - console.log(`Cypress config file: ${JSON.stringify(cypressConfigFile)}`); userSupportFile = cypressConfigFile.e2e?.supportFile !== null ? cypressConfigFile.e2e?.supportFile : cypressConfigFile.component?.supportFile !== null ? cypressConfigFile.component?.supportFile : cypressConfigFile.supportFile; if(userSupportFile == false && extension) { const supportFolderPath = path.join(process.cwd(), 'cypress', 'support'); @@ -386,16 +384,13 @@ exports.getSupportFiles = (bsConfig, isA11y) => { supportFile = process.env[envVar]; } else { /* Single file / glob pattern */ - console.log(`Using user defined support file: ${userSupportFile}`); supportFile = userSupportFile; } } else if(Array.isArray(userSupportFile)) { - console.log(`Using user defined support files123: ${userSupportFile}`); supportFile = userSupportFile[0]; } } catch (err) {} if(supportFile && supportFile[0] != '/') supportFile = '/' + supportFile; - console.log(`Final support file: ${supportFile}`); return { supportFile, cleanupParams: Object.keys(cleanupParams).length ? cleanupParams : null diff --git a/bin/helpers/readCypressConfigUtil.js b/bin/helpers/readCypressConfigUtil.js index 42cdab77..bdf556bc 100644 --- a/bin/helpers/readCypressConfigUtil.js +++ b/bin/helpers/readCypressConfigUtil.js @@ -71,8 +71,7 @@ exports.loadJsFile = (cypress_config_filepath, bstack_node_modules_path) => { } logger.debug(`Running: ${load_command}`) cp.execSync(load_command) - const fileContent = fs.readFileSync(config.configJsonFileName).toString(); - const cypress_config = JSON.parse(fileContent); + const cypress_config = JSON.parse(fs.readFileSync(config.configJsonFileName).toString()) if (fs.existsSync(config.configJsonFileName)) { fs.unlinkSync(config.configJsonFileName) } From f74034691f30c20669ed09f7e47d89a8a0d7a351 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Wed, 6 Aug 2025 01:39:47 +0530 Subject: [PATCH 48/57] fix: semgrep alert --- bin/accessibility-automation/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 7d14b472..006e00bc 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -246,7 +246,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { // Build the correct glob pattern const globPattern = supportFilesData.supportFile.startsWith('/') ? process.cwd() + supportFilesData.supportFile - : path.join(process.cwd(), supportFilesData.supportFile); + : path.resolve(process.cwd(),supportFilesData.supportFile); glob(globPattern, {}, (err, files) => { if(err) { From d14f0a1c35f5f32a01fceda9c8c38e622a8f25e1 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Wed, 6 Aug 2025 01:46:58 +0530 Subject: [PATCH 49/57] minor change --- bin/accessibility-automation/helper.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 006e00bc..d903923b 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -244,9 +244,10 @@ exports.setAccessibilityEventListeners = (bsConfig) => { } // Build the correct glob pattern + const cwd_path = process.cwd(); const globPattern = supportFilesData.supportFile.startsWith('/') - ? process.cwd() + supportFilesData.supportFile - : path.resolve(process.cwd(),supportFilesData.supportFile); + ? cwd_path + supportFilesData.supportFile + : path.resolve(cwd_path,supportFilesData.supportFile); glob(globPattern, {}, (err, files) => { if(err) { From 0d1bfc38d3e399e843bad843a3ccc1245c350f1d Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Wed, 6 Aug 2025 01:51:15 +0530 Subject: [PATCH 50/57] added a change --- bin/accessibility-automation/helper.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index d903923b..bbe61973 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -244,10 +244,13 @@ exports.setAccessibilityEventListeners = (bsConfig) => { } // Build the correct glob pattern - const cwd_path = process.cwd(); + const resolvedPath = path.resolve(process.cwd(), supportFilesData.supportFile); + if (!resolvedPath.startsWith(process.cwd())) { + throw new Error('Path traversal attempt detected'); + } const globPattern = supportFilesData.supportFile.startsWith('/') - ? cwd_path + supportFilesData.supportFile - : path.resolve(cwd_path,supportFilesData.supportFile); + ? process.cwd() + supportFilesData.supportFile + : resolvedPath; glob(globPattern, {}, (err, files) => { if(err) { From 4c4bea5389eb15d25ab121ae174490f840fd4a2a Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Wed, 6 Aug 2025 02:09:24 +0530 Subject: [PATCH 51/57] debugging code added --- bin/accessibility-automation/helper.js | 21 ++++++++++++--------- bin/helpers/helper.js | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index bbe61973..388c8fdf 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -244,14 +244,12 @@ exports.setAccessibilityEventListeners = (bsConfig) => { } // Build the correct glob pattern - const resolvedPath = path.resolve(process.cwd(), supportFilesData.supportFile); - if (!resolvedPath.startsWith(process.cwd())) { - throw new Error('Path traversal attempt detected'); - } - const globPattern = supportFilesData.supportFile.startsWith('/') - ? process.cwd() + supportFilesData.supportFile - : resolvedPath; - + // const globPattern = supportFilesData.supportFile.startsWith('/') + // ? process.cwd() + supportFilesData.supportFile + // : path.resolve(process.cwd(), supportFilesData.supportFile); + + const globPattern = process.cwd() + supportFilesData.supportFile; + console.log(`Using glob pattern to find support files: ${globPattern}`); glob(globPattern, {}, (err, files) => { if(err) { logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files'); @@ -261,26 +259,31 @@ exports.setAccessibilityEventListeners = (bsConfig) => { files.forEach(file => { try { const fileName = path.basename(file); + console.log(`Found support file: ${file}`); + console.log(`File name: ${fileName}`); if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) { const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); - + console.log(`Cypress command event listener: ${cypressCommandEventListener}`); if(!defaultFileContent.includes(cypressCommandEventListener)) { let newFileContent = defaultFileContent + '\n' + cypressCommandEventListener + '\n'; fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); + console.log(`Updated file content for ${file}: ${newFileContent}`); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } } } catch(e) { + console.log(`Error updating file content for ${file}: ${e}`); logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); } }); }); } catch(e) { + console.log(`Error updating file content for2 ${file}: ${e}`); logger.debug(`Unable to parse support files to set event listeners with error ${e}`, true, e); } } diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index ecb4e279..9fcf82d2 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -390,7 +390,8 @@ exports.getSupportFiles = (bsConfig, isA11y) => { supportFile = userSupportFile[0]; } } catch (err) {} - if(supportFile && supportFile[0] != '/') supportFile = '/' + supportFile; + if (supportFile && !path.isAbsolute(supportFile)) supportFile = '/' + supportFile; + console.log(`Support file:123 ${supportFile}`); return { supportFile, cleanupParams: Object.keys(cleanupParams).length ? cleanupParams : null From c74ec207873326fa21b515a19d28eafe05de1382 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Wed, 6 Aug 2025 02:44:18 +0530 Subject: [PATCH 52/57] minor change --- bin/accessibility-automation/helper.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 388c8fdf..5d489c42 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -241,13 +241,9 @@ exports.setAccessibilityEventListeners = (bsConfig) => { } catch(e) { logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); } + return; } - // Build the correct glob pattern - // const globPattern = supportFilesData.supportFile.startsWith('/') - // ? process.cwd() + supportFilesData.supportFile - // : path.resolve(process.cwd(), supportFilesData.supportFile); - const globPattern = process.cwd() + supportFilesData.supportFile; console.log(`Using glob pattern to find support files: ${globPattern}`); glob(globPattern, {}, (err, files) => { From 5d05d23477534db0ffbd09f2c4c4093c29f7037a Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Wed, 6 Aug 2025 03:06:57 +0530 Subject: [PATCH 53/57] fix: semgrep issue --- bin/accessibility-automation/helper.js | 8 +------- bin/helpers/helper.js | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 5d489c42..bcab6d7a 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -225,6 +225,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const isPattern = glob.hasMagic(supportFilesData.supportFile); if(!isPattern) { console.log(`Using user defined support file: ${supportFilesData.supportFile}`); + let file; try { file = process.cwd() + supportFilesData.supportFile; const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); @@ -245,7 +246,6 @@ exports.setAccessibilityEventListeners = (bsConfig) => { } const globPattern = process.cwd() + supportFilesData.supportFile; - console.log(`Using glob pattern to find support files: ${globPattern}`); glob(globPattern, {}, (err, files) => { if(err) { logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files'); @@ -255,31 +255,25 @@ exports.setAccessibilityEventListeners = (bsConfig) => { files.forEach(file => { try { const fileName = path.basename(file); - console.log(`Found support file: ${file}`); - console.log(`File name: ${fileName}`); if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) { const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'}); let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file)); - console.log(`Cypress command event listener: ${cypressCommandEventListener}`); if(!defaultFileContent.includes(cypressCommandEventListener)) { let newFileContent = defaultFileContent + '\n' + cypressCommandEventListener + '\n'; fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'}); - console.log(`Updated file content for ${file}: ${newFileContent}`); supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent; } } } catch(e) { - console.log(`Error updating file content for ${file}: ${e}`); logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e); } }); }); } catch(e) { - console.log(`Error updating file content for2 ${file}: ${e}`); logger.debug(`Unable to parse support files to set event listeners with error ${e}`, true, e); } } diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index 9fcf82d2..b317e406 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -391,7 +391,6 @@ exports.getSupportFiles = (bsConfig, isA11y) => { } } catch (err) {} if (supportFile && !path.isAbsolute(supportFile)) supportFile = '/' + supportFile; - console.log(`Support file:123 ${supportFile}`); return { supportFile, cleanupParams: Object.keys(cleanupParams).length ? cleanupParams : null From 8dc5393ff80e8417e416b6c8d5a1c729ee052979 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Sun, 10 Aug 2025 19:34:05 +0530 Subject: [PATCH 54/57] review changes --- bin/accessibility-automation/helper.js | 2 +- bin/helpers/helper.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index bcab6d7a..dc9e7f3e 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -224,7 +224,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => { const isPattern = glob.hasMagic(supportFilesData.supportFile); if(!isPattern) { - console.log(`Using user defined support file: ${supportFilesData.supportFile}`); + logger.debug(`Using user defined support file: ${supportFilesData.supportFile}`); let file; try { file = process.cwd() + supportFilesData.supportFile; diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index b317e406..331787cd 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -390,7 +390,7 @@ exports.getSupportFiles = (bsConfig, isA11y) => { supportFile = userSupportFile[0]; } } catch (err) {} - if (supportFile && !path.isAbsolute(supportFile)) supportFile = '/' + supportFile; + if(supportFile && supportFile[0] != '/') supportFile = '/' + supportFile;; return { supportFile, cleanupParams: Object.keys(cleanupParams).length ? cleanupParams : null From bdd00fe0e8362c9275d4448c80a397809e405dee Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Sun, 10 Aug 2025 20:32:05 +0530 Subject: [PATCH 55/57] minor change --- bin/helpers/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index 331787cd..ecb4e279 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -390,7 +390,7 @@ exports.getSupportFiles = (bsConfig, isA11y) => { supportFile = userSupportFile[0]; } } catch (err) {} - if(supportFile && supportFile[0] != '/') supportFile = '/' + supportFile;; + if(supportFile && supportFile[0] != '/') supportFile = '/' + supportFile; return { supportFile, cleanupParams: Object.keys(cleanupParams).length ? cleanupParams : null From 62f831033c96b7a4050c3d53107618fd9cb4880b Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Sun, 10 Aug 2025 20:35:27 +0530 Subject: [PATCH 56/57] chore: removed extra lines --- bin/accessibility-automation/helper.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index dc9e7f3e..69d48918 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -15,14 +15,12 @@ const HttpsProxyAgent = require('https-proxy-agent'); exports.checkAccessibilityPlatform = (user_config) => { let accessibility = false; try { - user_config.browsers.forEach(browser => { if (browser.accessibility) { accessibility = true; } }) } catch {} - return accessibility; } @@ -35,7 +33,6 @@ exports.setAccessibilityCypressCapabilities = async (user_config, accessibilityR user_config.run_settings.accessibilityOptions["scannerVersion"] = accessibilityResponse.data.scannerVersion; user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_AUTH=${accessibilityResponse.data.accessibilityToken}`) user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_SCANNERVERSION=${accessibilityResponse.data.scannerVersion}`) - } exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => { @@ -46,7 +43,6 @@ exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => { exports.createAccessibilityTestRun = async (user_config, framework) => { try { - if (!this.isAccessibilitySupportedCypressVersion(user_config.run_settings.cypress_config_file) ){ logger.warn(`Accessibility Testing is not supported on Cypress version 9 and below.`) process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false'; @@ -102,7 +98,6 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { const response = await nodeRequest( 'POST', 'v2/test_runs', data, config, API_URL ); - if(!utils.isUndefined(response.data)) { process.env.BS_A11Y_JWT = response.data.data.accessibilityToken; process.env.BS_A11Y_TEST_RUN_ID = response.data.data.id; From d9ff28f278968970c5ec05efd8888f495e48f3b7 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Sun, 10 Aug 2025 20:36:19 +0530 Subject: [PATCH 57/57] minor change --- bin/accessibility-automation/helper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 69d48918..d5ba4fa2 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -21,6 +21,7 @@ exports.checkAccessibilityPlatform = (user_config) => { } }) } catch {} + return accessibility; }