Skip to content

Cbt 18943 #338

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

Merged
merged 9 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
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
76 changes: 75 additions & 1 deletion accessibility/scanner/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const fs = require("fs")

const LambdatestLog = (message) => {
if (!Cypress.env('LAMBDATEST_LOGS')) return;
Expand Down Expand Up @@ -93,6 +92,8 @@ cy.window().then((win) => {
bestPractice: bestPracticeValue,
needsReview: needsReviewValue
}

console.log('log', "payload to send " + payloadToSend);
let testId = Cypress.env("TEST_ID") || ""

const filePath = Cypress.env("ACCESSIBILITY_REPORT_PATH") || 'cypress/results/accessibilityReport_' + testId + '.json';
Expand Down Expand Up @@ -143,4 +144,77 @@ cy.window().then((win) => {
Cypress.on('command:end', (command) => {

return;
})


afterEach(() => {
console.log("after each hook")
cy.window().then((win) => {
let wcagCriteriaValue = Cypress.env("WCAG_CRITERIA") || "wcag21a";
let bestPracticeValue = Cypress.env("BEST_PRACTICE") || false;
let needsReviewValue = Cypress.env("NEEDS_REVIEW") || false;

bestPracticeValue = bestPracticeValue == "true" ? true : false;
needsReviewValue = needsReviewValue == "true" ? true : false;

let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
if (!isAccessibilityLoaded){
console.log('log', "accessibility not enabled " + isAccessibilityLoaded);
return;
}

const payloadToSend = {
message: 'SET_CONFIG',
wcagCriteria: wcagCriteriaValue,
bestPractice: bestPracticeValue,
needsReview: needsReviewValue
}

console.log('log', "payload to send " + payloadToSend);
let testId = Cypress.env("TEST_ID") || ""

const filePath = Cypress.env("ACCESSIBILITY_REPORT_PATH") || 'cypress/results/accessibilityReport_' + testId + '.json';

cy.wrap(setScanConfig(win, payloadToSend), {timeout: 30000}).then((res) => {
console.log('logging config reponse', res);

const payload = {
message: 'GET_LATEST_SCAN_DATA',
}

cy.wrap(getScanData(win, payload), {timeout: 45000}).then((res) => {
LambdatestLog('log', "scanning data ");


cy.task('initializeFile', filePath).then((filePath) => {
cy.readFile(filePath, { log: true, timeout: 45000 }).then((fileContent) => {
let resultsArray = [{}];
console.log('logging report', res);
// If the file is not empty, parse the existing content
if (fileContent) {
try {
resultsArray = JSON.parse(JSON.stringify(fileContent));
} catch (e) {
console.log("parsing error for content " , fileContent)
console.log('Error parsing JSON file:', e);
return;
}
}
console.log('scanned data recieved is', res.message);
if (res.message == "GET_LATEST_SCAN_DATA") {
// Append the new result
resultsArray.push(res);
console.log('resultsarray logging', resultsArray);
}

// Write the updated content back to the file
cy.writeFile(filePath, resultsArray, { log: true, timeout: 45000 });
});
});
});

});
})


})