Skip to content

Commit 8b736fc

Browse files
Merge branch 'master' into fix_cypress_v13_approach_2
2 parents 4aad557 + 4da13ba commit 8b736fc

File tree

2 files changed

+60
-32
lines changed

2 files changed

+60
-32
lines changed

bin/accessibility-automation/cypress/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const browserStackLog = (message) => {
44
if (!Cypress.env('BROWSERSTACK_LOGS')) return;
55
cy.task('browserstack_log', message);
6-
}
6+
}
77

88
const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'];
99
// scroll is not a default function in cypress.

bin/accessibility-automation/helper.js

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exports.checkAccessibilityPlatform = (user_config) => {
2121
}
2222
})
2323
} catch {}
24-
24+
2525
return accessibility;
2626
}
2727

@@ -113,35 +113,33 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
113113

114114
} catch (error) {
115115
if (error.response) {
116-
logger.error("Incorrect Cred")
116+
logger.error("Incorrect Cred");
117117
logger.error(
118118
`Exception while creating test run for BrowserStack Accessibility Automation: ${
119119
error.response.status
120-
} ${error.response.statusText} ${JSON.stringify(error.response.data)}`
120+
} ${error.response.statusText} ${JSON.stringify(error.response.data)}
121+
`
121122
);
122-
} else {
123-
if(error.message === 'Invalid configuration passed.') {
124-
logger.error("Invalid configuration passed.")
125-
logger.error(
126-
`Exception while creating test run for BrowserStack Accessibility Automation: ${
127-
error.message || error.stack
128-
}`
129-
);
130-
for(const errorkey of error.errors){
131-
logger.error(errorkey.message);
132-
}
133-
134-
} else {
135-
logger.error(
136-
`Exception while creating test run for BrowserStack Accessibility Automation: ${
137-
error.message || error.stack
138-
}`
139-
);
123+
} else if (error.message === 'Invalid configuration passed.') {
124+
logger.error("Invalid configuration passed.");
125+
logger.error(
126+
`Exception while creating test run for BrowserStack Accessibility Automation: ${
127+
error.message || error.stack
128+
}`
129+
);
130+
for (const errorkey of error.errors) {
131+
logger.error(errorkey.message);
140132
}
141-
// since create accessibility session failed
142-
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false';
143-
user_config.run_settings.accessibility = false;
133+
} else {
134+
logger.error(
135+
`Exception while creating test run for BrowserStack Accessibility Automation: ${
136+
error.message || error.stack
137+
}`
138+
);
144139
}
140+
// since create accessibility session failed
141+
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false';
142+
user_config.run_settings.accessibility = false;
145143
}
146144
}
147145

@@ -216,22 +214,52 @@ const getAccessibilityCypressCommandEventListener = (extName) => {
216214

217215
exports.setAccessibilityEventListeners = (bsConfig) => {
218216
try {
219-
// Searching form command.js recursively
217+
220218
const supportFilesData = helper.getSupportFiles(bsConfig, true);
221219
if(!supportFilesData.supportFile) return;
222-
glob(process.cwd() + supportFilesData.supportFile, {}, (err, files) => {
223-
if(err) return logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');
220+
221+
const isPattern = glob.hasMagic(supportFilesData.supportFile);
222+
if(!isPattern) {
223+
logger.debug(`Using user defined support file: ${supportFilesData.supportFile}`);
224+
let file;
225+
try {
226+
file = process.cwd() + supportFilesData.supportFile;
227+
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
228+
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
229+
const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener);
230+
if(!alreadyIncludes) {
231+
let newFileContent = defaultFileContent +
232+
'\n' +
233+
cypressCommandEventListener +
234+
'\n';
235+
fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
236+
supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
237+
}
238+
} catch(e) {
239+
logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
240+
}
241+
return;
242+
}
243+
244+
const globPattern = process.cwd() + supportFilesData.supportFile;
245+
glob(globPattern, {}, (err, files) => {
246+
if(err) {
247+
logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');
248+
return;
249+
}
250+
224251
files.forEach(file => {
225252
try {
226-
if(!file.includes('commands.js') && !file.includes('commands.ts')) {
253+
const fileName = path.basename(file);
254+
if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) {
255+
227256
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
228-
229257
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
230258
if(!defaultFileContent.includes(cypressCommandEventListener)) {
231-
let newFileContent = defaultFileContent +
259+
let newFileContent = defaultFileContent +
232260
'\n' +
233261
cypressCommandEventListener +
234-
'\n'
262+
'\n';
235263
fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
236264
supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
237265
}

0 commit comments

Comments
 (0)