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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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);