Skip to content

[WIP] SDK-3449 fix #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d54c407
fix: use valid variable
dandonarahul2002 Jul 17, 2025
b3d79f8
chore: add detailed logging
dandonarahul2002 Jul 18, 2025
fc985b7
chore: more logs
dandonarahul2002 Jul 22, 2025
e45f782
new changes
Bhargavi-BS Jul 28, 2025
9214805
more changes
Bhargavi-BS Jul 28, 2025
1bd74d2
added more logging
Bhargavi-BS Jul 28, 2025
136c2fe
changes
Bhargavi-BS Jul 28, 2025
8fa469d
minor change
Bhargavi-BS Jul 28, 2025
2aa6f71
more changes
Bhargavi-BS Jul 28, 2025
dfa60aa
more changes
Bhargavi-BS Jul 28, 2025
f922241
support folder change
Bhargavi-BS Jul 31, 2025
58dde04
fix
Bhargavi-BS Jul 31, 2025
5c9ff21
fix changes
Bhargavi-BS Jul 31, 2025
7db800c
minor change
Bhargavi-BS Jul 31, 2025
7087439
temp log changes
Bhargavi-BS Jul 31, 2025
9d6500a
removed extra logging
Bhargavi-BS Aug 1, 2025
e1ef09d
minor change
Bhargavi-BS Aug 1, 2025
0f7ca3c
added logs
Bhargavi-BS Aug 1, 2025
c0769c3
added logs
Bhargavi-BS Aug 1, 2025
967684b
small change
Bhargavi-BS Aug 1, 2025
42273d0
minor change
Bhargavi-BS Aug 1, 2025
5d82249
small change
Bhargavi-BS Aug 1, 2025
dc92b92
Merge pull request #985 from browserstack/SDK-3449-new2
Bhargavi-BS Aug 1, 2025
689ad31
minor change
Bhargavi-BS Aug 1, 2025
1e6b4b3
minor change again
Bhargavi-BS Aug 1, 2025
b12a7c3
minor change again
Bhargavi-BS Aug 1, 2025
906f64d
fhbksdj
xxshubhamxx Aug 1, 2025
3ed07f5
ASfsdg
xxshubhamxx Aug 1, 2025
fd7617e
new 4
xxshubhamxx Aug 1, 2025
3af740b
new 4 logs
xxshubhamxx Aug 1, 2025
d90ac44
removed debugging code
Bhargavi-BS Aug 1, 2025
f1edd41
minor changes
Bhargavi-BS Aug 1, 2025
7780635
added fix for double save calls
Bhargavi-BS Aug 1, 2025
9beab9c
error trace
Bhargavi-BS Aug 1, 2025
8dec92b
improved error logging
Bhargavi-BS Aug 1, 2025
79e9b25
removed extra code
Bhargavi-BS Aug 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/accessibility-automation/cypress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const browserStackLog = (message) => {
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.
Expand Down
97 changes: 66 additions & 31 deletions bin/accessibility-automation/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
exports.checkAccessibilityPlatform = (user_config) => {
let accessibility = false;
try {

user_config.browsers.forEach(browser => {
if (browser.accessibility) {
accessibility = true;
}
})
} catch {}

return accessibility;
}

Expand All @@ -34,6 +35,7 @@
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) => {
Expand All @@ -44,6 +46,7 @@
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';
Expand Down Expand Up @@ -99,6 +102,7 @@
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;
Expand All @@ -113,35 +117,33 @@

} 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;
}
}

Expand Down Expand Up @@ -216,22 +218,55 @@

exports.setAccessibilityEventListeners = (bsConfig) => {
try {
// Searching form command.js recursively

const supportFilesData = helper.getSupportFiles(bsConfig, true);
if(!supportFilesData.supportFile) return;
glob(process.cwd() + supportFilesData.supportFile, {}, (err, files) => {
if(err) return logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');

const isPattern = glob.hasMagic(supportFilesData.supportFile);

if(!isPattern) {
console.log(`Inside isPattern`);
try {
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener);
if(!alreadyIncludes) {
let newFileContent = defaultFileContent +
'\n' +
cypressCommandEventListener +
'\n';
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);
}
}

// Build the correct glob pattern
const globPattern = supportFilesData.supportFile.startsWith('/')
? process.cwd() + supportFilesData.supportFile
: path.join(process.cwd(), supportFilesData.supportFile);

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal Warning

Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

glob(globPattern, {}, (err, files) => {
if(err) {
logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');
return;
}

files.forEach(file => {
try {
if(!file.includes('commands.js') && !file.includes('commands.ts')) {
const fileName = path.basename(file);
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));

if(!defaultFileContent.includes(cypressCommandEventListener)) {
let newFileContent = defaultFileContent +
let newFileContent = defaultFileContent +
'\n' +
cypressCommandEventListener +
'\n'
'\n';
fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
}
Expand Down
Loading