From 234fcfd8e1f9155194dc98009c1b646cce0ce0f4 Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Tue, 3 Dec 2024 19:36:59 +0530 Subject: [PATCH 1/9] SDK-1884: wrapping A11Y commands appropriately --- bin/accessibility-automation/cypress/index.js | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 6586a256..32468a48 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -18,7 +18,7 @@ new Promise(async (resolve, reject) => { return win.document.querySelector("#accessibility-automation-element"); } - function waitForScannerReadiness(retryCount = 30, retryInterval = 100) { + function waitForScannerReadiness(retryCount = 100, retryInterval = 100) { return new Promise(async (resolve, reject) => { let count = 0; const intervalID = setInterval(async () => { @@ -261,24 +261,16 @@ const shouldScanForAccessibility = (attributes) => { return shouldScanTestForAccessibility; } -Cypress.on('command:start', async (command) => { - if(!command || !command.attributes) return; - if(command.attributes.name == 'window' || command.attributes.name == 'then' || command.attributes.name == 'wrap') { - return; - } - - if (!commandsToWrap.includes(command.attributes.name)) return; - - const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; - - let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); - if (!shouldScanTestForAccessibility) return; +const commandToOverwrite = [ 'visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; +commandToOverwrite.forEach((command) => { + Cypress.Commands.overwrite(command, (originalFn, url, options) => { + const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; + let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); + if (!shouldScanTestForAccessibility) return; + cy.wrap(null).performScan().then(() => originalFn(url, options)); + }); +}); - cy.window().then((win) => { - browserStackLog('Performing scan form command ' + command.attributes.name); - cy.wrap(performScan(win, {method: command.attributes.name}), {timeout: 30000}); - }) -}) afterEach(() => { const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; @@ -337,7 +329,7 @@ Cypress.Commands.add('performScan', () => { } cy.window().then(async (win) => { browserStackLog(`Performing accessibility scan`); - await performScan(win); + cy.wrap(performScan(win), {timeout:40000}); }); } catch {} }) From 02ea36a3b4007a89505a0259ce75c3f95439fa8a Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Tue, 3 Dec 2024 19:57:48 +0530 Subject: [PATCH 2/9] SDK-1884: added error debugging logs. --- bin/accessibility-automation/cypress/index.js | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 32468a48..532476b1 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -6,6 +6,15 @@ const browserStackLog = (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']; +const commandToOverwrite = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; +commandToOverwrite.forEach((command) => { + Cypress.Commands.overwrite(command, (originalFn, url, options) => { + const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; + let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); + if (!shouldScanTestForAccessibility) return; + cy.wrap(null).performScan().then(() => originalFn(url, options)); + }); +}); const performScan = (win, payloadToSend) => new Promise(async (resolve, reject) => { @@ -222,7 +231,8 @@ new Promise( (resolve, reject) => { resolve("Scanner is not ready on the page after multiple retries. after run"); }); } - } catch(er) { + } catch(error) { + browserStackLog(`Error in saving results with error: ${error.message}`); resolve() } @@ -254,24 +264,13 @@ const shouldScanForAccessibility = (attributes) => { 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); + browserStackLog(`Error while validating test case for accessibility before scanning. Error : ${error.message}`); } } return shouldScanTestForAccessibility; } -const commandToOverwrite = [ 'visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; -commandToOverwrite.forEach((command) => { - Cypress.Commands.overwrite(command, (originalFn, url, options) => { - const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; - let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); - if (!shouldScanTestForAccessibility) return; - cy.wrap(null).performScan().then(() => originalFn(url, options)); - }); -}); - - afterEach(() => { const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { @@ -314,6 +313,7 @@ afterEach(() => { }) } catch (er) { + browserStackLog(`Error in saving results with error: ${er.message}`); } }) }); @@ -331,7 +331,9 @@ Cypress.Commands.add('performScan', () => { browserStackLog(`Performing accessibility scan`); cy.wrap(performScan(win), {timeout:40000}); }); - } catch {} + } catch(error) { + browserStackLog(`Error in performing scan with error: ${error.message}`); + } }) Cypress.Commands.add('getAccessibilityResultsSummary', () => { @@ -347,7 +349,9 @@ Cypress.Commands.add('getAccessibilityResultsSummary', () => { browserStackLog('Getting accessibility results summary'); return await getAccessibilityResultsSummary(win); }); - } catch {} + } catch(error) { + browserStackLog(`Error in getting accessibilty results summary with error: ${error.message}`); + } }); @@ -368,6 +372,7 @@ Cypress.Commands.add('getAccessibilityResults', () => { return await getAccessibilityResults(win); }); - } catch {} - + } catch(error) { + browserStackLog(`Error in getting accessibilty results with error: ${error.message}`); + } }); From da5fc16e21febd82872b1691af3968d8f999ebde Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Wed, 4 Dec 2024 16:45:39 +0530 Subject: [PATCH 3/9] SDK-1884: fixed scanner started twice. --- bin/accessibility-automation/cypress/index.js | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 532476b1..7636f2a0 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -11,8 +11,11 @@ commandToOverwrite.forEach((command) => { Cypress.Commands.overwrite(command, (originalFn, url, options) => { const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); - if (!shouldScanTestForAccessibility) return; - cy.wrap(null).performScan().then(() => originalFn(url, options)); + if (!shouldScanTestForAccessibility) { + cy.wrap(null).then(() => originalFn(url, options)); + return; + } + else cy.wrap(null).performScan().then(() => originalFn(url, options)); }); }); @@ -21,6 +24,7 @@ new Promise(async (resolve, reject) => { const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol); if (!isHttpOrHttps) { resolve(); + return; } function findAccessibilityAutomationElement() { @@ -38,9 +42,11 @@ new Promise(async (resolve, reject) => { "Accessibility Automation Scanner is not ready on the page." ) ); + return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); resolve("Scanner set"); + return; } else { count += 1; } @@ -52,6 +58,7 @@ new Promise(async (resolve, reject) => { function onScanComplete() { win.removeEventListener("A11Y_SCAN_FINISHED", onScanComplete); resolve(); + return; } win.addEventListener("A11Y_SCAN_FINISHED", onScanComplete); @@ -66,7 +73,8 @@ new Promise(async (resolve, reject) => { .then(startScan) .catch(async (err) => { resolve("Scanner is not ready on the page after multiple retries. performscan"); - }); + return; + }); } }) @@ -75,6 +83,7 @@ new Promise((resolve) => { const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol); if (!isHttpOrHttps) { resolve(); + return; } function findAccessibilityAutomationElement() { @@ -92,9 +101,11 @@ new Promise((resolve) => { "Accessibility Automation Scanner is not ready on the page." ) ); + return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); resolve("Scanner set"); + return; } else { count += 1; } @@ -106,6 +117,7 @@ new Promise((resolve) => { function onReceiveSummary(event) { win.removeEventListener("A11Y_RESULTS_SUMMARY", onReceiveSummary); resolve(event.detail); + return; } win.addEventListener("A11Y_RESULTS_SUMMARY", onReceiveSummary); @@ -120,7 +132,8 @@ new Promise((resolve) => { .then(getSummary) .catch((err) => { resolve(); - }); + return; + }); } }) @@ -129,6 +142,7 @@ new Promise((resolve) => { const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol); if (!isHttpOrHttps) { resolve(); + return; } function findAccessibilityAutomationElement() { @@ -146,9 +160,11 @@ new Promise((resolve) => { "Accessibility Automation Scanner is not ready on the page." ) ); + return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); resolve("Scanner set"); + return; } else { count += 1; } @@ -160,6 +176,7 @@ new Promise((resolve) => { function onReceivedResult(event) { win.removeEventListener("A11Y_RESULTS_RESPONSE", onReceivedResult); resolve(event.detail); + return; } win.addEventListener("A11Y_RESULTS_RESPONSE", onReceivedResult); @@ -174,7 +191,8 @@ new Promise((resolve) => { .then(getResults) .catch((err) => { resolve(); - }); + return; + }); } }); @@ -184,6 +202,7 @@ new Promise( (resolve, reject) => { const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol); if (!isHttpOrHttps) { resolve("Unable to save accessibility results, Invalid URL."); + return; } function findAccessibilityAutomationElement() { @@ -201,9 +220,11 @@ new Promise( (resolve, reject) => { "Accessibility Automation Scanner is not ready on the page." ) ); + return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); resolve("Scanner set"); + return; } else { count += 1; } @@ -214,6 +235,7 @@ new Promise( (resolve, reject) => { function saveResults() { function onResultsSaved(event) { resolve(); + return; } win.addEventListener("A11Y_RESULTS_SAVED", onResultsSaved); const e = new CustomEvent("A11Y_SAVE_RESULTS", { @@ -229,11 +251,13 @@ new Promise( (resolve, reject) => { .then(saveResults) .catch(async (err) => { resolve("Scanner is not ready on the page after multiple retries. after run"); + return; }); } } catch(error) { - browserStackLog(`Error in saving results with error: ${error.message}`); - resolve() + browserStackLog(`Error in saving results with error: ${error.message}`); + resolve(); + return; } }) @@ -313,7 +337,7 @@ afterEach(() => { }) } catch (er) { - browserStackLog(`Error in saving results with error: ${er.message}`); + browserStackLog(`Error in saving results with error: ${er.message}`); } }) }); @@ -332,8 +356,8 @@ Cypress.Commands.add('performScan', () => { cy.wrap(performScan(win), {timeout:40000}); }); } catch(error) { - browserStackLog(`Error in performing scan with error: ${error.message}`); - } + browserStackLog(`Error in performing scan with error: ${error.message}`); + } }) Cypress.Commands.add('getAccessibilityResultsSummary', () => { @@ -350,8 +374,8 @@ Cypress.Commands.add('getAccessibilityResultsSummary', () => { return await getAccessibilityResultsSummary(win); }); } catch(error) { - browserStackLog(`Error in getting accessibilty results summary with error: ${error.message}`); - } + browserStackLog(`Error in getting accessibilty results summary with error: ${error.message}`); + } }); @@ -373,6 +397,6 @@ Cypress.Commands.add('getAccessibilityResults', () => { }); } catch(error) { - browserStackLog(`Error in getting accessibilty results with error: ${error.message}`); - } + browserStackLog(`Error in getting accessibilty results with error: ${error.message}`); + } }); From e8d4bc94927d6c57555fca0afefde8756b8ab5d6 Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Wed, 4 Dec 2024 21:52:07 +0530 Subject: [PATCH 4/9] SDK-1907: added launchOptions --- bin/accessibility-automation/plugin/index.js | 11 ++++++++++ bin/helpers/utils.js | 21 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index 8d614cf7..e6b9237c 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -1,4 +1,6 @@ const path = require("node:path"); +const { decodeJWTToken } = require("../../helpers/utils"); +const utils = require('../../helpers/utils'); const browserstackAccessibility = (on, config) => { let browser_validation = true; @@ -30,7 +32,16 @@ const browserstackAccessibility = (on, config) => { } if (browser_validation) { const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH) + const {_, payload} = decodeJWTToken(process.env.ACCESSIBILITY_AUTH); launchOptions.extensions.push(ally_path); + if(!utils.isUndefined(payload) && !utils.isUndefined(payload.a11y_core_config) && payload.a11y_core_config.domForge === true) { + 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"] || {}; + launchOptions.preferences.default["devtools"]["preferences"][ + "currentDockState" + ] = '"undocked"'; + } return launchOptions } } diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 12d6c99a..9cb564e5 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1775,3 +1775,24 @@ exports.getMajorVersion = (version) => { return null; } } + +const base64UrlDecode = (str) => { + const base64 = str.replace(/-/g, '+').replace(/_/g, '/'); + const buffer = Buffer.from(base64, 'base64'); + return buffer.toString('utf-8'); +}; + +exports.decodeJWTToken = (token) => { + try{ + const parts = token.split('.'); + if (parts.length < 2) { + throw new Error('Invalid JWT token'); + } + const header = JSON.parse(base64UrlDecode(parts[0])); + const payload = JSON.parse(base64UrlDecode(parts[1])); + return { header, payload }; + } catch (error) { + logger.err(error.message); + return {undefined, undefined}; + } +} From ccde61eb002a4a7ed1ec8ef0df1dc93b1d1bdc3a Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Thu, 5 Dec 2024 15:06:52 +0530 Subject: [PATCH 5/9] SDK-1884: improved logic --- bin/accessibility-automation/cypress/index.js | 74 ++++++++++++++++--- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 7636f2a0..80fa7532 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -7,17 +7,44 @@ const browserStackLog = (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']; const commandToOverwrite = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; -commandToOverwrite.forEach((command) => { - Cypress.Commands.overwrite(command, (originalFn, url, options) => { - const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; - let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); - if (!shouldScanTestForAccessibility) { - cy.wrap(null).then(() => originalFn(url, options)); - return; - } - else cy.wrap(null).performScan().then(() => originalFn(url, options)); - }); -}); +const performModifiedScan = (originalFn, Subject, stateType, ...args) => { + let customChaining = cy.wrap(null).performScan(); + function changeSub(args, stateType, newSubject) { + if (stateType !== 'parent') { + return [newSubject, ...args.slice(1)]; + } + return args; + } + function runCutomizedCommand() { + if (!Subject) { + let orgS1, orgS2, cypressCommandSubject; + if((orgS2 = (orgS1 = cy).subject) !==null && orgS2 !== void 0){ + cypressCommandSubject = orgS2.call(orgS1); + } + else{ + cypressCommandSubject = null; + } + customChaining.then(()=> cypressCommandSubject).then(() => {originalFn(...args)}); + } + else { + let orgSC1, orgSC2, timeO1, cypressCommandChain, setTimeout; + if((timeO1 = args.find(arg => arg !== null && arg !== void 0 ? arg.timeout : null)) !== null && timeO1 !== void 0) { + setTimeout = timeO1.timeout; + } + else { + setTimeout = null; + } + if((orgSC1 = (orgSC2 = cy).subjectChain) !== null && orgSC1 !== void 0){ + cypressCommandChain = orgSC1.call(orgSC2); + } + else { + cypressCommandChain = null; + } + customChaining.performScanSubjectQuery(cypressCommandChain, setTimeout).then({timeout: 30000}, (newSubject) => originalFn(...changeSub(args, stateType, newSubject))); + } + } + runCutomizedCommand(); +} const performScan = (win, payloadToSend) => new Promise(async (resolve, reject) => { @@ -295,6 +322,26 @@ const shouldScanForAccessibility = (attributes) => { return shouldScanTestForAccessibility; } +commandToOverwrite.forEach((command) => { + Cypress.Commands.overwrite(command, (originalFn, ...args) => { + const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; + const shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); + const state = cy.state('current'), Subject = 'getSubjectFromChain' in cy; + const stateName = state === null || state === void 0 ? void 0 : state.get('name'); + let stateType; + if (!shouldScanTestForAccessibility || (stateName && stateName !== command)) { + return originalFn(...args); + } + if(state !== null && state !== void 0){ + stateType = state.get('type'); + } + else { + stateType = null; + } + performModifiedScan(originalFn, Subject, stateType, ...args); + }); +}); + afterEach(() => { const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { @@ -400,3 +447,8 @@ Cypress.Commands.add('getAccessibilityResults', () => { browserStackLog(`Error in getting accessibilty results with error: ${error.message}`); } }); + +Cypress.Commands.addQuery('performScanSubjectQuery', function (chaining, setTimeout) { + this.set('timeout', setTimeout); + return () => cy.getSubjectFromChain(chaining); +}); From f96066ac80360ca55122ca29ed94dfc3d17b6ffd Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Thu, 5 Dec 2024 17:25:50 +0530 Subject: [PATCH 6/9] SDK-1884: resolved reviews. --- bin/accessibility-automation/cypress/index.js | 107 +++++++----------- bin/accessibility-automation/plugin/index.js | 2 +- bin/helpers/utils.js | 7 +- 3 files changed, 42 insertions(+), 74 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 80fa7532..042cc10d 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -6,41 +6,30 @@ const browserStackLog = (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. const commandToOverwrite = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; + +/* + Overrriding the cypress commands to perform Accessibility Scan before Each command + - runCutomizedCommand is handling both the cases of subject available in cypress original command + and chaning available from original cypress command. +*/ const performModifiedScan = (originalFn, Subject, stateType, ...args) => { let customChaining = cy.wrap(null).performScan(); - function changeSub(args, stateType, newSubject) { + const changeSub = (args, stateType, newSubject) => { if (stateType !== 'parent') { return [newSubject, ...args.slice(1)]; } return args; } - function runCutomizedCommand() { + const runCutomizedCommand = () => { if (!Subject) { - let orgS1, orgS2, cypressCommandSubject; - if((orgS2 = (orgS1 = cy).subject) !==null && orgS2 !== void 0){ - cypressCommandSubject = orgS2.call(orgS1); - } - else{ - cypressCommandSubject = null; - } - customChaining.then(()=> cypressCommandSubject).then(() => {originalFn(...args)}); - } - else { - let orgSC1, orgSC2, timeO1, cypressCommandChain, setTimeout; - if((timeO1 = args.find(arg => arg !== null && arg !== void 0 ? arg.timeout : null)) !== null && timeO1 !== void 0) { - setTimeout = timeO1.timeout; - } - else { - setTimeout = null; - } - if((orgSC1 = (orgSC2 = cy).subjectChain) !== null && orgSC1 !== void 0){ - cypressCommandChain = orgSC1.call(orgSC2); - } - else { - cypressCommandChain = null; - } - customChaining.performScanSubjectQuery(cypressCommandChain, setTimeout).then({timeout: 30000}, (newSubject) => originalFn(...changeSub(args, stateType, newSubject))); + let cypressCommandSubject = (cy.subject?.call(cy)) ?? null; + customChaining.then(() => cypressCommandSubject).then(() => { originalFn(...args); }); + } else { + let setTimeout = args.find(arg => arg?.timeout)?.timeout ?? null; + let cypressCommandChain = (cy.subjectChain?.call(cy)) ?? null; + customChaining.performScanSubjectQuery(cypressCommandChain, setTimeout).then({ timeout: 10000 }, newSubject => originalFn(...changeSub(args, stateType, newSubject))); } } runCutomizedCommand(); @@ -50,8 +39,7 @@ const performScan = (win, payloadToSend) => new Promise(async (resolve, reject) => { const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol); if (!isHttpOrHttps) { - resolve(); - return; + return resolve(); } function findAccessibilityAutomationElement() { @@ -64,16 +52,14 @@ new Promise(async (resolve, reject) => { const intervalID = setInterval(async () => { if (count > retryCount) { clearInterval(intervalID); - reject( + return reject( new Error( "Accessibility Automation Scanner is not ready on the page." ) ); - return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); - resolve("Scanner set"); - return; + return resolve("Scanner set"); } else { count += 1; } @@ -84,8 +70,7 @@ new Promise(async (resolve, reject) => { function startScan() { function onScanComplete() { win.removeEventListener("A11Y_SCAN_FINISHED", onScanComplete); - resolve(); - return; + return resolve(); } win.addEventListener("A11Y_SCAN_FINISHED", onScanComplete); @@ -99,8 +84,7 @@ new Promise(async (resolve, reject) => { waitForScannerReadiness() .then(startScan) .catch(async (err) => { - resolve("Scanner is not ready on the page after multiple retries. performscan"); - return; + return resolve("Scanner is not ready on the page after multiple retries. performscan"); }); } }) @@ -109,8 +93,7 @@ const getAccessibilityResultsSummary = (win) => new Promise((resolve) => { const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol); if (!isHttpOrHttps) { - resolve(); - return; + return resolve(); } function findAccessibilityAutomationElement() { @@ -123,16 +106,14 @@ new Promise((resolve) => { const intervalID = setInterval(() => { if (count > retryCount) { clearInterval(intervalID); - reject( + return reject( new Error( "Accessibility Automation Scanner is not ready on the page." ) ); - return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); - resolve("Scanner set"); - return; + return resolve("Scanner set"); } else { count += 1; } @@ -143,8 +124,7 @@ new Promise((resolve) => { function getSummary() { function onReceiveSummary(event) { win.removeEventListener("A11Y_RESULTS_SUMMARY", onReceiveSummary); - resolve(event.detail); - return; + return resolve(event.detail); } win.addEventListener("A11Y_RESULTS_SUMMARY", onReceiveSummary); @@ -158,8 +138,7 @@ new Promise((resolve) => { waitForScannerReadiness() .then(getSummary) .catch((err) => { - resolve(); - return; + return resolve(); }); } }) @@ -168,8 +147,7 @@ const getAccessibilityResults = (win) => new Promise((resolve) => { const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol); if (!isHttpOrHttps) { - resolve(); - return; + return resolve(); } function findAccessibilityAutomationElement() { @@ -182,16 +160,14 @@ new Promise((resolve) => { const intervalID = setInterval(() => { if (count > retryCount) { clearInterval(intervalID); - reject( + return reject( new Error( "Accessibility Automation Scanner is not ready on the page." ) ); - return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); - resolve("Scanner set"); - return; + return resolve("Scanner set"); } else { count += 1; } @@ -202,8 +178,7 @@ new Promise((resolve) => { function getResults() { function onReceivedResult(event) { win.removeEventListener("A11Y_RESULTS_RESPONSE", onReceivedResult); - resolve(event.detail); - return; + return resolve(event.detail); } win.addEventListener("A11Y_RESULTS_RESPONSE", onReceivedResult); @@ -217,8 +192,7 @@ new Promise((resolve) => { waitForScannerReadiness() .then(getResults) .catch((err) => { - resolve(); - return; + return resolve(); }); } }); @@ -242,16 +216,14 @@ new Promise( (resolve, reject) => { const intervalID = setInterval(async () => { if (count > retryCount) { clearInterval(intervalID); - reject( + return reject( new Error( "Accessibility Automation Scanner is not ready on the page." ) ); - return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); - resolve("Scanner set"); - return; + return resolve("Scanner set"); } else { count += 1; } @@ -261,8 +233,7 @@ new Promise( (resolve, reject) => { function saveResults() { function onResultsSaved(event) { - resolve(); - return; + return resolve(); } win.addEventListener("A11Y_RESULTS_SAVED", onResultsSaved); const e = new CustomEvent("A11Y_SAVE_RESULTS", { @@ -277,14 +248,12 @@ new Promise( (resolve, reject) => { waitForScannerReadiness() .then(saveResults) .catch(async (err) => { - resolve("Scanner is not ready on the page after multiple retries. after run"); - return; + return resolve("Scanner is not ready on the page after multiple retries. after run"); }); } } catch(error) { browserStackLog(`Error in saving results with error: ${error.message}`); - resolve(); - return; + return resolve(); } }) @@ -348,7 +317,7 @@ afterEach(() => { let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); if (!shouldScanTestForAccessibility) return cy.wrap({}); - cy.wrap(performScan(win), {timeout: 30000}).then(() => { + cy.wrap(performScan(win), {timeout: 10000}).then(() => { try { let os_data; if (Cypress.env("OS")) { @@ -379,7 +348,7 @@ afterEach(() => { } }; browserStackLog(`Saving accessibility test results`); - cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => { + cy.wrap(saveTestResults(win, payloadToSend), {timeout: 10000}).then(() => { browserStackLog(`Saved accessibility test results`); }) @@ -400,7 +369,7 @@ Cypress.Commands.add('performScan', () => { } cy.window().then(async (win) => { browserStackLog(`Performing accessibility scan`); - cy.wrap(performScan(win), {timeout:40000}); + cy.wrap(performScan(win), {timeout:10000}); }); } catch(error) { browserStackLog(`Error in performing scan with error: ${error.message}`); diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index e6b9237c..4c35ef99 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -32,7 +32,7 @@ const browserstackAccessibility = (on, config) => { } if (browser_validation) { const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH) - const {_, payload} = decodeJWTToken(process.env.ACCESSIBILITY_AUTH); + const payload = decodeJWTToken(process.env.ACCESSIBILITY_AUTH); launchOptions.extensions.push(ally_path); if(!utils.isUndefined(payload) && !utils.isUndefined(payload.a11y_core_config) && payload.a11y_core_config.domForge === true) { launchOptions.args.push("--auto-open-devtools-for-tabs"); diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 9cb564e5..095ebab1 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1788,11 +1788,10 @@ exports.decodeJWTToken = (token) => { if (parts.length < 2) { throw new Error('Invalid JWT token'); } - const header = JSON.parse(base64UrlDecode(parts[0])); const payload = JSON.parse(base64UrlDecode(parts[1])); - return { header, payload }; + return payload } catch (error) { - logger.err(error.message); - return {undefined, undefined}; + logger.err("Error in token decoding with error:", error.message); + return undefined; } } From f04069d0c47211a95ac65f3c7986104aec85e5d0 Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Thu, 5 Dec 2024 17:37:06 +0530 Subject: [PATCH 7/9] SDK-1884: original time to save results --- 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 042cc10d..30c0e77b 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -348,7 +348,7 @@ afterEach(() => { } }; browserStackLog(`Saving accessibility test results`); - cy.wrap(saveTestResults(win, payloadToSend), {timeout: 10000}).then(() => { + cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => { browserStackLog(`Saved accessibility test results`); }) From deefe01ba3d6468651c1a246908200c10ca7108a Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Thu, 5 Dec 2024 17:51:45 +0530 Subject: [PATCH 8/9] SDK-1884: refactored code --- bin/accessibility-automation/cypress/index.js | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 30c0e77b..f20762df 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -22,17 +22,25 @@ const performModifiedScan = (originalFn, Subject, stateType, ...args) => { } return args; } - const runCutomizedCommand = () => { + const runCustomizedCommand = () => { if (!Subject) { - let cypressCommandSubject = (cy.subject?.call(cy)) ?? null; - customChaining.then(() => cypressCommandSubject).then(() => { originalFn(...args); }); + let orgS1, orgS2, cypressCommandSubject = null; + if((orgS2 = (orgS1 = cy).subject) !==null && orgS2 !== void 0){ + cypressCommandSubject = orgS2.call(orgS1); + } + customChaining.then(()=> cypressCommandSubject).then(() => {originalFn(...args)}); } else { - let setTimeout = args.find(arg => arg?.timeout)?.timeout ?? null; - let cypressCommandChain = (cy.subjectChain?.call(cy)) ?? null; - customChaining.performScanSubjectQuery(cypressCommandChain, setTimeout).then({ timeout: 10000 }, newSubject => originalFn(...changeSub(args, stateType, newSubject))); + let orgSC1, orgSC2, timeO1, cypressCommandChain = null, setTimeout = null; + if((timeO1 = args.find(arg => arg !== null && arg !== void 0 ? arg.timeout : null)) !== null && timeO1 !== void 0) { + setTimeout = timeO1.timeout; + } + if((orgSC1 = (orgSC2 = cy).subjectChain) !== null && orgSC1 !== void 0){ + cypressCommandChain = orgSC1.call(orgSC2); + } + customChaining.performScanSubjectQuery(cypressCommandChain, setTimeout).then({timeout: 30000}, (newSubject) => originalFn(...changeSub(args, stateType, newSubject))); } } - runCutomizedCommand(); + runCustomizedCommand(); } const performScan = (win, payloadToSend) => @@ -297,16 +305,13 @@ commandToOverwrite.forEach((command) => { const shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); const state = cy.state('current'), Subject = 'getSubjectFromChain' in cy; const stateName = state === null || state === void 0 ? void 0 : state.get('name'); - let stateType; + let stateType = null; if (!shouldScanTestForAccessibility || (stateName && stateName !== command)) { return originalFn(...args); } if(state !== null && state !== void 0){ stateType = state.get('type'); } - else { - stateType = null; - } performModifiedScan(originalFn, Subject, stateType, ...args); }); }); From 2148ba16847f61054f0073aba216b29bc6c530c2 Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Thu, 5 Dec 2024 18:06:35 +0530 Subject: [PATCH 9/9] SDK-1884: timoute --- bin/accessibility-automation/cypress/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index f20762df..994cdaaf 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -322,7 +322,7 @@ afterEach(() => { let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); if (!shouldScanTestForAccessibility) return cy.wrap({}); - cy.wrap(performScan(win), {timeout: 10000}).then(() => { + cy.wrap(performScan(win), {timeout: 30000}).then(() => { try { let os_data; if (Cypress.env("OS")) { @@ -374,7 +374,7 @@ Cypress.Commands.add('performScan', () => { } cy.window().then(async (win) => { browserStackLog(`Performing accessibility scan`); - cy.wrap(performScan(win), {timeout:10000}); + cy.wrap(performScan(win), {timeout:30000}); }); } catch(error) { browserStackLog(`Error in performing scan with error: ${error.message}`);