Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions accessibility-checker/src-ts/lib/ACHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ async function getComplianceHelperWebDriverIO(label, parsed, curPol) : Promise<I
});
origReport.screenshot = image;
}
finalReport = ReporterManager.addEngineReport("Puppeteer", startScan, url, title, label, origReport);
finalReport = ReporterManager.addEngineReport("WebDriverIO", startScan, url, title, label, origReport);
}
page.aceBusy = false;

Expand Down Expand Up @@ -747,7 +747,7 @@ async function getSimulationHelperWebDriverIO(label: string, parsed) : Promise<I
const url = await page.execute(() => document.location.href);
const title = await page.execute(() => (document.location as any).title);
const origResult: ISimulatorStructure = JSON.parse(JSON.stringify(result));
ReporterManager.addSimulatorResult("Selenium-simulator", startScan-Date.now(), url, title, label, origResult);
ReporterManager.addSimulatorResult("WebDriverIO-simulator", startScan-Date.now(), url, title, label, origResult);
}
page.aceBusy = false;

Expand Down Expand Up @@ -783,7 +783,7 @@ async function getSimulationHelperPuppeteer(label: string, parsed) : Promise<ISi
const title = await page.evaluate("document.location.title");
const origResult: ISimulatorStructure = JSON.parse(JSON.stringify(result));

ReporterManager.addSimulatorResult("Selenium-simulator", startScan-Date.now(), url, title, label, origResult);
ReporterManager.addSimulatorResult("Puppeteer-simulator", startScan-Date.now(), url, title, label, origResult);
}

page.aceBusy = false;
Expand All @@ -805,7 +805,7 @@ async function getSimulationHelperLocal(label: string, parsed) : Promise<ISimula
if (result) {
let url = parsed.location && parsed.location.href;
const origResult: ISimulatorStructure = JSON.parse(JSON.stringify(result));
ReporterManager.addSimulatorResult("Selenium-simulator", startScan-Date.now(), url, parsed.title, label, origResult);
ReporterManager.addSimulatorResult("Native-simulator", startScan-Date.now(), url, parsed.title, label, origResult);
}

return result;
Expand Down
53 changes: 53 additions & 0 deletions cypress-accessibility-checker/src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,59 @@ Cypress.Commands.add("getCompliance", (cyObj, scanLabel) => {
});
});

/**
* EXPERIMENTAL: Get screen reader simulation of a cypress object
*
* WARNING: This API is experimental and subject to change. The output format and behavior
* may be modified in future releases.
*
* This can be called with a single parameter - getSimulation("SCAN_LABEL"),
* which will simulate the current document. Otherwise, pass a cypress object
* (document) and a label
*/
Cypress.Commands.add("getSimulation", (cyObj, scanLabel) => {
let scanObj = cyObj;
let label = scanLabel;
let startScan = new Date().getTime();
let url;
let title;
let simulation;
return init().then(() => {
if (typeof cyObj === "string") {
return cy.document({ log: false })
.then(doc => {
scanObj = doc;
label = cyObj;
})
}
}).then(() => {
return cy.wrap(ACCommands.getSimulation(scanObj, label), { log: false });
}).then(simulationResult => {
simulation = simulationResult;
// To write metrics to disk, we have to be outside of the browser, so that's a task
return cy.title({ log: false });
}).then(pageTitle => {
title = pageTitle;
return cy.url({ log: false });
}).then(pageUrl => {
url = pageUrl;
return cy.task('accessibilityChecker', {
task: 'sendSimulationToReporter',
data: { profile: `${Cypress.browser.displayName} ${Cypress.browser.version}`, startScan, url, title, label, simulation }
}, { log: false }).then((updSimulation) => {
Cypress.log({
name: 'getSimulation',
displayName: 'getSimulation',
message: ` ${updSimulation.length} announcements`,
consoleProps: () => {
return updSimulation
},
})
return cy.wrap(updSimulation, { log: false });
});
});
});

/**
* Asserts accessibility compliance against a baseline or failure level of violation. If a failure
* is logged then the test will have an assertion fail.
Expand Down
23 changes: 23 additions & 0 deletions cypress-accessibility-checker/src/lib/ACTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@ let ACTasks = module.exports = {
});
},

/**
* This function is responsible for sending the simulation results to the reporter for metrics tracking.
*
* @param {String} profile - Browser profile information
* @param {Number} startScan - Timestamp when scan started
* @param {String} url - URL of the page
* @param {String} title - Title of the page
* @param {String} label - Label for the simulation
* @param {Object} simulation - Simulation results from the scan
*
* @return {Object} simulation - Returns the simulation object
*
* PUBLIC API
*
* @memberOf this
*/
sendSimulationToReporter: function (profile, startScan, url, title, label, simulation) {
return ACTasks.initialize().then(() => {
ReporterManager.addSimulatorResult(profile, startScan, url, title, label, simulation);
return simulation;
});
},

/**
* This function is responsible for printing the scan results to console.
*
Expand Down
6 changes: 6 additions & 0 deletions cypress-accessibility-checker/src/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ function sendResultsToReporter(profile, startScan, url, title, label, report) {
return ACTasks.sendResultsToReporter(profile, startScan, url, title, label, report);
}

function sendSimulationToReporter(profile, startScan, url, title, label, simulation) {
return ACTasks.sendSimulationToReporter(profile, startScan, url, title, label, simulation);
}

function getDiffResults({ label }) {
return BaselineManager.getDiffResults(label);
}
Expand All @@ -107,6 +111,8 @@ module.exports = ({ task, data }) => {
switch (task) {
case 'sendResultsToReporter':
return sendResultsToReporter(data.profile, data.startScan, data.url, data.title, data.label, data.report)
case 'sendSimulationToReporter':
return sendSimulationToReporter(data.profile, data.startScan, data.url, data.title, data.label, data.simulation)
case 'assertCompliance':
return assertCompliance(data);
case 'getBaseline':
Expand Down
Loading