Skip to content

Fix: Double Ally testcase save calls #988

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 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
58 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
5bf215a
added logging
Bhargavi-BS Aug 4, 2025
19e2bd6
more logging
Bhargavi-BS Aug 4, 2025
902ec25
added more logs
Bhargavi-BS Aug 4, 2025
4420f3e
abc
Bhargavi-BS Aug 4, 2025
6d08175
more logs
Bhargavi-BS Aug 4, 2025
532d703
changes added
Bhargavi-BS Aug 5, 2025
048cfd6
added more logs
Bhargavi-BS Aug 5, 2025
785cf0f
added error log
Bhargavi-BS Aug 5, 2025
89d19a9
fix
Bhargavi-BS Aug 5, 2025
654cf99
final fix
Bhargavi-BS Aug 5, 2025
e90b4ed
removed extra logging
Bhargavi-BS Aug 5, 2025
97479cb
removed unneccesary code
Bhargavi-BS Aug 5, 2025
f740346
fix: semgrep alert
Bhargavi-BS Aug 5, 2025
d14f0a1
minor change
Bhargavi-BS Aug 5, 2025
0d1bfc3
added a change
Bhargavi-BS Aug 5, 2025
4c4bea5
debugging code added
Bhargavi-BS Aug 5, 2025
c74ec20
minor change
Bhargavi-BS Aug 5, 2025
5d05d23
fix: semgrep issue
Bhargavi-BS Aug 5, 2025
8dc5393
review changes
Bhargavi-BS Aug 10, 2025
bdd00fe
minor change
Bhargavi-BS Aug 10, 2025
62f8310
chore: removed extra lines
Bhargavi-BS Aug 10, 2025
d9ff28f
minor change
Bhargavi-BS Aug 10, 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the changes done as part of this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karanshah-browserstack this is to check if the returned supportFile is a single file path or a glob pattern cause if it's a single path then user has explicitly passed in their cypress config and plugins should be added to only that file .If glob pattern is present which we return by default and then that needs to be treated with a loop.

if(!isPattern) {
console.log(`Using user defined support file: ${supportFilesData.supportFile}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to logger.

try {
file = process.cwd() + supportFilesData.supportFile;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you check whether supportfile is absolute/relative path? If we are always getting an absolute path why do we cwd to be added to it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test it windows + mac, locally.

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.resolve(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 {
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