Skip to content

Commit

Permalink
WEBUI-1317: Accessibility checks are failing after upgrade NodeJS 18-1
Browse files Browse the repository at this point in the history
  • Loading branch information
alokhyland authored and poonamyadav252 committed Oct 10, 2023
1 parent abe37d4 commit 9ada451
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 79 deletions.
19 changes: 10 additions & 9 deletions packages/nuxeo-web-ui-ftest/pages/login.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
export default class Login {
set username(username) {
$('#username').waitForDisplayed();
$('#username').setValue(username);
async username(username) {
const inputUserName = await $('#username');
await inputUserName.setValue(username);
// return result;
}

set password(password) {
$('#password').waitForDisplayed();
$('#password').setValue(password);
async password(password) {
const inputPassword = await $('#password');
await inputPassword.setValue(password);
}

submit() {
$('[name="Submit"]').waitForDisplayed();
return $('[name="Submit"]').click();
async submit() {
const submitButton = await $('[name="Submit"]');
await submitButton.click();
}

static get() {
Expand Down
3 changes: 1 addition & 2 deletions packages/nuxeo-web-ui-ftest/scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ if (process.env.DRIVER_VERSION == null) {
console.log(`${version} detected.`);
const match = version && version.match(/([0-9]+)\./);
if (match) {
// const checkVersion = match[1];
const checkVersion = match[1];
// we will revert this once driver issue is resolved.
const checkVersion = 114;
try {
done = fetch(`https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_${checkVersion}`).then(
(response) => {
Expand Down
3 changes: 1 addition & 2 deletions plugin/a11y/getDriverVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ try {
}
const match = version && version.match(/([0-9]+)\./);
if (match) {
// const checkVersion = match[1];
const checkVersion = match[1];
// we will revert this once driver issue is resolved.
const checkVersion = 114;
try {
fetch(`https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_${checkVersion}`).then((response) => {
if (response.ok) {
Expand Down
28 changes: 12 additions & 16 deletions plugin/a11y/test/a11y-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@ import { runAxeCore } from './axe-reporter.js';

export function reportA11y(expectedViolations, expectedIncompleteViolations, setup) {
let _report;

const getReport = () => {
const getReport = async () => {
if (_report) {
return _report;
}
browser.setTimeout({ script: 240000 });

setup();

browser.pause(3000);
_report = runAxeCore();

await browser.setTimeout({ script: 240000 });
await browser.pause(3000);
_report = await runAxeCore();
return _report;
};

context('Violations', () => {
let report;

before(() => {
report = getReport();
before(async () => {
report = await getReport();
});

Object.entries(expectedViolations).forEach(([violation, issues]) => {
it(`${violation}: ${issues} issue(s)`, () => {
expect(report.violations).toEqual(
it(`${violation}: ${issues} issue(s)`, async () => {
await expect(report.violations).toEqual(
expect.arrayContaining([
{
id: violation,
Expand All @@ -41,13 +37,13 @@ export function reportA11y(expectedViolations, expectedIncompleteViolations, set
context('Incomplete violations', () => {
let report;

before(() => {
report = getReport();
before(async () => {
report = await getReport();
});

Object.entries(expectedIncompleteViolations).forEach(([violation, issues]) => {
it(`${violation}: ${issues} issue(s)`, () => {
expect(report.incomplete).toEqual(
it(`${violation}: ${issues} issue(s)`, async () => {
await expect(report.incomplete).toEqual(
expect.arrayContaining([
{
id: violation,
Expand Down
65 changes: 35 additions & 30 deletions plugin/a11y/test/axe-reporter.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
// eslint-disable-next-line import/no-unresolved
import { source } from 'axe-core';

export function runAxeCore() {
// inject the axe-core lib
browser.execute(source);
class AxeCore {
async run() {
await browser.execute(source);
const options = {
runOnly: {
type: 'tag',
values: ['ACT', 'best-practice', 'wcag2a', 'wcag2aa'],
},
};
// run inside browser and get results
const results = await browser.executeAsync((opts, done) => {
// eslint-disable-next-line no-undef
axe
.run(opts)
.then((res) => done(res))
.catch((err) => {
throw err;
});
}, options);
return this.process(await results);
}

// https://github.com/dequelabs/axe-core/blob/develop/doc/API.md
const options = {
runOnly: {
type: 'tag',
values: ['ACT', 'best-practice', 'wcag2a', 'wcag2aa'],
},
};
// run inside browser and get results
const results = browser.executeAsync((opts, done) => {
// eslint-disable-next-line no-undef
axe
.run(opts)
.then((res) => done(res))
.catch((err) => {
throw err;
});
}, options);

return {
results,
incomplete: results.incomplete.map((a) => {
return { id: a.id, issues: a.nodes.length };
}),
violations: results.violations.map((a) => {
return { id: a.id, issues: a.nodes.length };
}),
};
process(results) {
return {
results,
incomplete: results.incomplete.map((a) => {
return { id: a.id, issues: a.nodes.length };
}),
violations: results.violations.map((a) => {
return { id: a.id, issues: a.nodes.length };
}),
};
}
}
export async function runAxeCore() {
return new AxeCore().run();
}
10 changes: 5 additions & 5 deletions plugin/a11y/test/helpers/login.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Login from '@nuxeo/nuxeo-web-ui-ftest/pages/login';
import UI from '@nuxeo/nuxeo-web-ui-ftest/pages/ui';

const login = (username = 'Administrator', password = 'Administrator') => {
const login = async (username = 'Administrator', password = 'Administrator') => {
const logIn = Login.get();
logIn.username = username;
logIn.password = password;
logIn.submit();
await logIn.username(username);
await logIn.password(password);
await logIn.submit();
const ui = UI.get();
ui.waitForVisible('nuxeo-page');
await ui.waitForVisible('nuxeo-page');
};

export default login;
4 changes: 2 additions & 2 deletions plugin/a11y/test/specs/browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../imports';
import UI from '@nuxeo/nuxeo-web-ui-ftest/pages/ui';
import documentService from '@nuxeo/nuxeo-web-ui-ftest/features/step_definitions/support/services/documentService';
import UI from '@nuxeo/nuxeo-web-ui-ftest/pages/ui';
import login from '../helpers/login';
import { reportA11y } from '../a11y-reporter.js';

Expand Down Expand Up @@ -34,7 +34,7 @@ describe('Nuxeo Browser', () => {

after(async () => documentService.reset());

reportA11y(EXPECTED_VIOLATIONS, EXPECTED_INCOMPLETE_VIOLATIONS, () => {
reportA11y(EXPECTED_VIOLATIONS, EXPECTED_INCOMPLETE_VIOLATIONS, async () => {
login();
const ui = UI.get();
ui.browser.browseTo(doc.path);
Expand Down
4 changes: 2 additions & 2 deletions plugin/a11y/test/specs/home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../imports';
import UI from '@nuxeo/nuxeo-web-ui-ftest/pages/ui';
import documentService from '@nuxeo/nuxeo-web-ui-ftest/features/step_definitions/support/services/documentService';
import UI from '@nuxeo/nuxeo-web-ui-ftest/pages/ui';
import login from '../helpers/login';
import { reportA11y } from '../a11y-reporter.js';

Expand Down Expand Up @@ -28,7 +28,7 @@ describe('Nuxeo Home', () => {
await documentService.create(parent.path, child);
});

reportA11y(EXPECTED_VIOLATIONS, EXPECTED_INCOMPLETE_VIOLATIONS, () => {
reportA11y(EXPECTED_VIOLATIONS, EXPECTED_INCOMPLETE_VIOLATIONS, async () => {
login();
const ui = UI.get();
ui.home.el.$('nuxeo-card[icon="nuxeo:edit"]').waitForDisplayed();
Expand Down
12 changes: 1 addition & 11 deletions plugin/a11y/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,7 @@ exports.config = {
// Services take over a specific job you don't want to take care of. They enhance
// your test setup with almost no effort. Unlike plugins, they don't add new
// commands. Instead, they hook themselves up into the test process.
services: [
[
'selenium-standalone',
{
installArgs: { drivers },
args: { drivers },
},
],
[CompatService],
[ShadowService],
],
services: [[CompatService], [ShadowService]],

// Framework you want to run your specs with.
// The following are supported: Mocha, Jasmine, and Cucumber
Expand Down

0 comments on commit 9ada451

Please sign in to comment.