Skip to content

Commit e45f782

Browse files
committed
new changes
1 parent fc985b7 commit e45f782

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

bin/accessibility-automation/cypress/index.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
14
/* Event listeners + custom commands for Cypress */
25

36
const browserStackLog = (message) => {
@@ -15,6 +18,7 @@ const commandToOverwrite = ['visit', 'click', 'type', 'request', 'dblclick', 'ri
1518
and chaning available from original cypress command.
1619
*/
1720
const performModifiedScan = (originalFn, Subject, stateType, ...args) => {
21+
process.env.PERFORM_MODIFIED_SCAN = 'true';
1822
let customChaining = cy.wrap(null).performScan();
1923
const changeSub = (args, stateType, newSubject) => {
2024
if (stateType !== 'parent') {
@@ -41,8 +45,10 @@ const performModifiedScan = (originalFn, Subject, stateType, ...args) => {
4145
}
4246
}
4347
runCustomizedCommand();
48+
process.env.PERFORM_MODIFIED_SCAN = 'true';
4449
}
4550

51+
4652
const performScan = (win, payloadToSend) =>
4753
new Promise(async (resolve, reject) => {
4854
const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol);
@@ -289,7 +295,7 @@ const shouldScanForAccessibility = (attributes) => {
289295

290296
const fullTestName = attributes.title;
291297
const excluded = excludeTagArray.some((exclude) => fullTestName.includes(exclude));
292-
const included = includeTagArray.length === 0 || includeTagArray.some((include) => fullTestName.includes(include));
298+
const included = includeTagArray.length === 0 || includeTags.some((include) => fullTestName.includes(include));
293299
shouldScanTestForAccessibility = !excluded && included;
294300
} catch (error) {
295301
browserStackLog(`Error while validating test case for accessibility before scanning. Error : ${error.message}`);
@@ -316,20 +322,35 @@ commandToOverwrite.forEach((command) => {
316322
});
317323
});
318324

325+
const logFilePath = path.join(__dirname, 'accessibility-log.txt');
319326
afterEach(() => {
327+
328+
const logMessage = `afterEach executed for test`
329+
try {
330+
fs.appendFileSync(logFilePath, logMessage);
331+
} catch (err) {
332+
// ignore logging errors
333+
}
334+
if (process.env.AFTER_EACH_RUN === 'true' || process.env.PERFORM_MODIFIED_SCAN === 'true') {
335+
return;
336+
}
337+
process.env.AFTER_EACH_RUN = 'true';
338+
339+
try {
340+
throw new Error('Deliberate exception thrown for testing purposes');
341+
} catch (error) {
342+
console.error('Exception caught in afterEach:', error);
343+
if (error && error.stack) {
344+
console.error(error.stack);
345+
}
346+
}
347+
320348
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest;
321-
console.log(`--- ENTERING AFTEREACH FOR: ${testTitle} ---`); // Added
322-
console.log(`Timestamp (afterEach start): ${new Date().toISOString()}`)
323349
cy.window().then(async (win) => {
324350
let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);
325-
if (!shouldScanTestForAccessibility) {
326-
console.log(`Skipping scan for: ${testTitle} (not accessibility session)`); // Added
327-
return cy.wrap({});
328-
}
329-
console.log(`Performing initial scan within afterEach for: ${testTitle}`); // Added
351+
if (!shouldScanTestForAccessibility) return cy.wrap({});
330352

331353
cy.wrap(performScan(win), {timeout: 30000}).then(() => {
332-
console.log(`Initial scan completed within afterEach for: ${testTitle}`); // Added
333354
try {
334355
let os_data;
335356
if (Cypress.env("OS")) {
@@ -361,19 +382,15 @@ afterEach(() => {
361382
"browser_version": Cypress.browser.version
362383
}
363384
};
364-
browserStackLog(`Saving accessibility test results`);
365-
console.log(`Timestamp (saveTestResults call): ${new Date().toISOString()}`); // Added
385+
browserStackLog(`afterEach hook called from function: ${attributes.title}, file: ${filePath}`);
386+
browserStackLog(`File name: ${__filename}`);
387+
browserStackLog(`Saving accessibility test results123`);
366388
cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => {
367389
browserStackLog(`Saved accessibility test results`);
368-
console.log(`Timestamp (saveTestResults completed): ${new Date().toISOString()}`); // Added
369-
console.log(`--- EXITING AFTEREACH FOR: ${testTitle} ---`); // Added
370-
371390
})
372391

373392
} catch (er) {
374393
browserStackLog(`Error in saving results with error: ${er.message}`);
375-
console.error(`Error in afterEach for ${testTitle}:`, er); // Added
376-
377394
}
378395
})
379396
});

bin/accessibility-automation/plugin/index.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11
const path = require("node:path");
22
const { decodeJWTToken } = require("../../helpers/utils");
33
const utils = require('../../helpers/utils');
4+
const fs = require('fs');
45

56
const browserstackAccessibility = (on, config) => {
7+
const logFilePath = path.join(__dirname, 'accessibility-start-log.txt');
8+
const logMessage = `afterEach executed for test`
9+
try {
10+
fs.appendFileSync(logFilePath, logMessage);
11+
} catch (err) {
12+
// ignore logging errors
13+
}
614
let browser_validation = true;
7-
console.log('[A11Y][plugin] Initializing BrowserStack Accessibility plugin');
815
if (process.env.BROWSERSTACK_ACCESSIBILITY_DEBUG === 'true') {
916
config.env.BROWSERSTACK_LOGS = 'true';
1017
process.env.BROWSERSTACK_LOGS = 'true';
11-
console.log('[A11Y][plugin] BROWSERSTACK_ACCESSIBILITY_DEBUG enabled, forcing BROWSERSTACK_LOGS to true');
1218
}
1319
on('task', {
1420
browserstack_log(message) {
15-
console.log('[A11Y][plugin][browserstack_log]', message)
21+
console.log(message)
22+
1623
return null
1724
},
1825
})
1926
on('before:browser:launch', (browser = {}, launchOptions) => {
2027
try {
21-
console.log(`[A11Y][plugin][before:browser:launch] Browser: ${browser.name}, Version: ${browser.majorVersion}, Headless: ${browser.isHeadless}`);
2228
if (process.env.ACCESSIBILITY_EXTENSION_PATH !== undefined) {
23-
console.log(`[A11Y][plugin] ACCESSIBILITY_EXTENSION_PATH: ${process.env.ACCESSIBILITY_EXTENSION_PATH}`);
2429
if (browser.name !== 'chrome') {
25-
console.log(`[A11Y][plugin] Accessibility Automation will run only on Chrome browsers.`);
30+
console.log(`Accessibility Automation will run only on Chrome browsers.`);
2631
browser_validation = false;
2732
}
2833
if (browser.name === 'chrome' && browser.majorVersion <= 94) {
29-
console.log(`[A11Y][plugin] Accessibility Automation will run only on Chrome browser version greater than 94.`);
34+
console.log(`Accessibility Automation will run only on Chrome browser version greater than 94.`);
3035
browser_validation = false;
3136
}
3237
if (browser.isHeadless === true) {
33-
console.log(`[A11Y][plugin] Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`);
38+
console.log(`Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`);
3439
browser_validation = false;
3540
}
3641
if (browser_validation) {
3742
const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH)
3843
const payload = decodeJWTToken(process.env.ACCESSIBILITY_AUTH);
39-
console.log(`[A11Y][plugin] Decoded JWT payload:`, payload);
4044
launchOptions.extensions.push(ally_path);
4145
if(!utils.isUndefined(payload) && !utils.isUndefined(payload.a11y_core_config) && payload.a11y_core_config.domForge === true) {
42-
console.log('[A11Y][plugin] domForge enabled, opening devtools for tabs');
4346
launchOptions.args.push("--auto-open-devtools-for-tabs");
4447
launchOptions.preferences.default["devtools"] = launchOptions.preferences.default["devtools"] || {};
4548
launchOptions.preferences.default["devtools"]["preferences"] = launchOptions.preferences.default["devtools"]["preferences"] || {};
@@ -50,9 +53,8 @@ const browserstackAccessibility = (on, config) => {
5053
return launchOptions
5154
}
5255
}
53-
} catch(err) {
54-
console.log('[A11Y][plugin][before:browser:launch] Error:', err);
55-
}
56+
} catch(err) {}
57+
5658
})
5759
config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH
5860
config.env.OS_VERSION = process.env.OS_VERSION
@@ -63,7 +65,6 @@ const browserstackAccessibility = (on, config) => {
6365
config.env.INCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE
6466
config.env.EXCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE
6567

66-
console.log('[A11Y][plugin] Final config.env:', config.env);
6768
return config;
6869
}
6970

0 commit comments

Comments
 (0)