Skip to content
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

Ats fixes #907

Merged
merged 50 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c0732de
changes
Dave3130 Oct 20, 2024
bb179a1
changes
Dave3130 Oct 23, 2024
fd6b752
changes
Dave3130 Oct 23, 2024
b13ee04
changes
Dave3130 Oct 23, 2024
7b3ad25
added user agent in caps
Dave3130 Oct 25, 2024
4a70212
changes
Dave3130 Oct 25, 2024
0e7da87
changes
Dave3130 Oct 28, 2024
e3370e9
add: turboscale build_artifact url
Ankit098 Oct 28, 2024
6b38dca
Merge branch 'HST-1587-cypress-custom-report' into HST_1153_cypress_a…
Ankit098 Oct 30, 2024
58123f5
Merge pull request #890 from browserstack/HST_1153_cypress_artifact_cli
Ankit098 Oct 30, 2024
4f8add1
Merge pull request #884 from browserstack/HST-1587-cypress-custom-report
pranavj1001 Oct 31, 2024
68345f7
1.31.10
pranavj1001 Oct 31, 2024
653e76d
Merge pull request #896 from browserstack/deploy
pranavj1001 Oct 31, 2024
641f4ee
changed request to axios
osho-20 Nov 5, 2024
68b9e7c
recovered code
osho-20 Nov 5, 2024
fcca5e9
added debugger.
osho-20 Nov 8, 2024
754271d
resolved comments.
osho-20 Nov 8, 2024
931e8bf
fixes
nagpalkaran95 Nov 13, 2024
491646e
remove unwnte
nagpalkaran95 Nov 13, 2024
0554ab5
bug fix
nagpalkaran95 Nov 13, 2024
11fdefe
fix creation
nagpalkaran95 Nov 13, 2024
1398118
fix build creation
nagpalkaran95 Nov 13, 2024
34006dc
fix build creation + polling
nagpalkaran95 Nov 14, 2024
8a09bd6
add: Send Error logs for ATS
sauravdas1997 Nov 14, 2024
64b5b44
Merge branch 'ats_fixes' of github.com:browserstack/browserstack-cypr…
sauravdas1997 Nov 14, 2024
30e5d15
add missing require
nagpalkaran95 Nov 14, 2024
55f959c
fix report
nagpalkaran95 Nov 14, 2024
9688b14
Merge branch 'master' of github.com:browserstack/browserstack-cypress…
nagpalkaran95 Nov 14, 2024
b2a6d13
fix report
nagpalkaran95 Nov 14, 2024
7747267
remove unwanted log lin
nagpalkaran95 Nov 15, 2024
59679ad
Merge branch 'axios-master-without-speedboats' of github.com:browsers…
nagpalkaran95 Nov 15, 2024
a454240
added debugger.
osho-20 Nov 17, 2024
721b5ed
fix: Proxy for o11y
sauravdas1997 Nov 18, 2024
3b2505c
fix: Proxy for a11y
sauravdas1997 Nov 18, 2024
a49df92
Merge pull request #920 from browserstack/axios-master-without-speedb…
bsautomation Nov 18, 2024
6bfa9d5
Merge pull request #921 from osho-20/axios-master
ShashankG-Gollapally Nov 18, 2024
e3c9346
Chore: PreProd Merge Conflict Resolution
KrishnaSuravarapu Nov 18, 2024
eda4b76
fix: Proxy for o11y and a11y
sauravdas1997 Nov 18, 2024
b5550d7
fix: Proxy for o11y and a11y
sauravdas1997 Nov 18, 2024
fc30d6f
Chore: Adding Proxy for ATSHelper
KrishnaSuravarapu Nov 18, 2024
05c63d5
Chore: Master Merge and Conflict resolution
KrishnaSuravarapu Nov 18, 2024
41df80c
removed debuggers
osho-20 Nov 18, 2024
5a99a0c
Merge pull request #924 from browserstack/axios-master-without-speedb…
bsautomation Nov 19, 2024
33fb7d4
Merge branch 'pre_prod' into ats_fixes
sauravdas1997 Nov 19, 2024
8ced5aa
Merge pull request #927 from browserstack/axios-master-without-speedb…
ShashankG-Gollapally Nov 19, 2024
35241e7
Merge branch 'pre_prod' of github.com:browserstack/browserstack-cypre…
KrishnaSuravarapu Nov 19, 2024
da25bb1
fix: proxy fix
sauravdas1997 Nov 19, 2024
d3dd8d7
Merge branch 'axios-master-without-speedboats' of github.com:browsers…
KrishnaSuravarapu Nov 20, 2024
252da50
Chore: Disabling proxy
KrishnaSuravarapu Nov 20, 2024
074b95f
Chore: Adding missing semicolon
KrishnaSuravarapu Nov 20, 2024
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
1 change: 1 addition & 0 deletions bin/accessibility-automation/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.API_URL = 'https://accessibility.browserstack.com/api';
381 changes: 381 additions & 0 deletions bin/accessibility-automation/cypress/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,381 @@
/* Event listeners + custom commands for Cypress */

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'];

const performScan = (win, payloadToSend) =>
new Promise(async (resolve, reject) => {
const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol);
if (!isHttpOrHttps) {
resolve();
}

function findAccessibilityAutomationElement() {
return win.document.querySelector("#accessibility-automation-element");
}

function waitForScannerReadiness(retryCount = 30, retryInterval = 100) {
return new Promise(async (resolve, reject) => {
let count = 0;
const intervalID = setInterval(async () => {
if (count > retryCount) {
clearInterval(intervalID);
reject(
new Error(
"Accessibility Automation Scanner is not ready on the page."
)
);
} else if (findAccessibilityAutomationElement()) {
clearInterval(intervalID);
resolve("Scanner set");
} else {
count += 1;
}
}, retryInterval);
});
}

function startScan() {
function onScanComplete() {
win.removeEventListener("A11Y_SCAN_FINISHED", onScanComplete);
resolve();
}

win.addEventListener("A11Y_SCAN_FINISHED", onScanComplete);
const e = new CustomEvent("A11Y_SCAN", { detail: payloadToSend });
win.dispatchEvent(e);
}

if (findAccessibilityAutomationElement()) {
startScan();
} else {
waitForScannerReadiness()
.then(startScan)
.catch(async (err) => {
resolve("Scanner is not ready on the page after multiple retries. performscan");
});
}
})

const getAccessibilityResultsSummary = (win) =>
new Promise((resolve) => {
const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol);
if (!isHttpOrHttps) {
resolve();
}

function findAccessibilityAutomationElement() {
return win.document.querySelector("#accessibility-automation-element");
}

function waitForScannerReadiness(retryCount = 30, retryInterval = 100) {
return new Promise((resolve, reject) => {
let count = 0;
const intervalID = setInterval(() => {
if (count > retryCount) {
clearInterval(intervalID);
reject(
new Error(
"Accessibility Automation Scanner is not ready on the page."
)
);
} else if (findAccessibilityAutomationElement()) {
clearInterval(intervalID);
resolve("Scanner set");
} else {
count += 1;
}
}, retryInterval);
});
}

function getSummary() {
function onReceiveSummary(event) {
win.removeEventListener("A11Y_RESULTS_SUMMARY", onReceiveSummary);
resolve(event.detail);
}

win.addEventListener("A11Y_RESULTS_SUMMARY", onReceiveSummary);
const e = new CustomEvent("A11Y_GET_RESULTS_SUMMARY");
win.dispatchEvent(e);
}

if (findAccessibilityAutomationElement()) {
getSummary();
} else {
waitForScannerReadiness()
.then(getSummary)
.catch((err) => {
resolve();
});
}
})

const getAccessibilityResults = (win) =>
new Promise((resolve) => {
const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol);
if (!isHttpOrHttps) {
resolve();
}

function findAccessibilityAutomationElement() {
return win.document.querySelector("#accessibility-automation-element");
}

function waitForScannerReadiness(retryCount = 30, retryInterval = 100) {
return new Promise((resolve, reject) => {
let count = 0;
const intervalID = setInterval(() => {
if (count > retryCount) {
clearInterval(intervalID);
reject(
new Error(
"Accessibility Automation Scanner is not ready on the page."
)
);
} else if (findAccessibilityAutomationElement()) {
clearInterval(intervalID);
resolve("Scanner set");
} else {
count += 1;
}
}, retryInterval);
});
}

function getResults() {
function onReceivedResult(event) {
win.removeEventListener("A11Y_RESULTS_RESPONSE", onReceivedResult);
resolve(event.detail);
}

win.addEventListener("A11Y_RESULTS_RESPONSE", onReceivedResult);
const e = new CustomEvent("A11Y_GET_RESULTS");
win.dispatchEvent(e);
}

if (findAccessibilityAutomationElement()) {
getResults();
} else {
waitForScannerReadiness()
.then(getResults)
.catch((err) => {
resolve();
});
}
});

const saveTestResults = (win, payloadToSend) =>
new Promise( (resolve, reject) => {
try {
const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol);
if (!isHttpOrHttps) {
resolve("Unable to save accessibility results, Invalid URL.");
}

function findAccessibilityAutomationElement() {
return win.document.querySelector("#accessibility-automation-element");
}

function waitForScannerReadiness(retryCount = 30, retryInterval = 100) {
return new Promise((resolve, reject) => {
let count = 0;
const intervalID = setInterval(async () => {
if (count > retryCount) {
clearInterval(intervalID);
reject(
new Error(
"Accessibility Automation Scanner is not ready on the page."
)
);
} else if (findAccessibilityAutomationElement()) {
clearInterval(intervalID);
resolve("Scanner set");
} else {
count += 1;
}
}, retryInterval);
});
}

function saveResults() {
function onResultsSaved(event) {
resolve();
}
win.addEventListener("A11Y_RESULTS_SAVED", onResultsSaved);
const e = new CustomEvent("A11Y_SAVE_RESULTS", {
detail: payloadToSend,
});
win.dispatchEvent(e);
}

if (findAccessibilityAutomationElement()) {
saveResults();
} else {
waitForScannerReadiness()
.then(saveResults)
.catch(async (err) => {
resolve("Scanner is not ready on the page after multiple retries. after run");
});
}
} catch(er) {
resolve()
}

})

const shouldScanForAccessibility = (attributes) => {
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return false;

const extensionPath = Cypress.env("ACCESSIBILITY_EXTENSION_PATH");
const isHeaded = Cypress.browser.isHeaded;

if (!isHeaded || (extensionPath === undefined)) return false;

let shouldScanTestForAccessibility = true;

if (Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY") || Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY")) {
try {
let includeTagArray = [];
let excludeTagArray = [];
if (Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY")) {
includeTagArray = Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY").split(";")
}
if (Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY")) {
excludeTagArray = Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY").split(";")
}

const fullTestName = attributes.title;
const excluded = excludeTagArray.some((exclude) => fullTestName.includes(exclude));
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);
}
}

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;

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;
cy.window().then(async (win) => {
let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);
if (!shouldScanTestForAccessibility) return cy.wrap({});

cy.wrap(performScan(win), {timeout: 30000}).then(() => {
try {
let os_data;
if (Cypress.env("OS")) {
os_data = Cypress.env("OS");
} else {
os_data = Cypress.platform === 'linux' ? 'mac' : "win"
}
let filePath = '';
if (attributes.invocationDetails !== undefined && attributes.invocationDetails.relativeFile !== undefined) {
filePath = attributes.invocationDetails.relativeFile;
}
const payloadToSend = {
"saveResults": shouldScanTestForAccessibility,
"testDetails": {
"name": attributes.title,
"testRunId": '5058', // variable not consumed, shouldn't matter what we send
"filePath": filePath,
"scopeList": [
filePath,
attributes.title
]
},
"platform": {
"os_name": os_data,
"os_version": Cypress.env("OS_VERSION"),
"browser_name": Cypress.browser.name,
"browser_version": Cypress.browser.version
}
};
browserStackLog(`Saving accessibility test results`);
cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => {
browserStackLog(`Saved accessibility test results`);
})

} catch (er) {
}
})
});
})

Cypress.Commands.add('performScan', () => {
try {
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable;
const shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);
if (!shouldScanTestForAccessibility) {
browserStackLog(`Not a Accessibility Automation session, cannot perform scan.`);
return cy.wrap({});
}
cy.window().then(async (win) => {
browserStackLog(`Performing accessibility scan`);
await performScan(win);
});
} catch {}
})

Cypress.Commands.add('getAccessibilityResultsSummary', () => {
try {
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable;
const shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);
if (!shouldScanTestForAccessibility) {
browserStackLog(`Not a Accessibility Automation session, cannot retrieve Accessibility results summary.`);
return cy.wrap({});
}
cy.window().then(async (win) => {
await performScan(win);
browserStackLog('Getting accessibility results summary');
return await getAccessibilityResultsSummary(win);
});
} catch {}

});

Cypress.Commands.add('getAccessibilityResults', () => {
try {
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable;
const shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);
if (!shouldScanTestForAccessibility) {
browserStackLog(`Not a Accessibility Automation session, cannot retrieve Accessibility results.`);
return cy.wrap({});
}

/* browserstack_accessibility_automation_script */

cy.window().then(async (win) => {
await performScan(win);
browserStackLog('Getting accessibility results');
return await getAccessibilityResults(win);
});

} catch {}

});
Loading