Skip to content

Commit

Permalink
feat(taborder): taborder provide 1 image per tabable object
Browse files Browse the repository at this point in the history
BREAKING CHANGE: completly refectored taborder method
  • Loading branch information
forsti0506 committed Sep 5, 2021
1 parent 9553bc9 commit 8c28e43
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 185 deletions.
2 changes: 1 addition & 1 deletion lib/a11y-sitechecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async function checkSite(
mergeResults(report, result);
if (result.violations.length > config.threshold) {
throw new Error(
'Threshold not met. There are ' + result.violations.length + ' errors. Threshold was: ' + config.threshold,
'Threshold (' + config.threshold + ') not met. There are ' + result.violations.length + ' errors.',
);
}
if (config.json) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Page } from 'puppeteer';
import { Config } from '../models/config';
import { debug } from './helper-functions';
import { debug, waitForHTML } from './helper-functions';
import { saveScreenshot } from './helper-saving-screenshots';

let count = 0;

export async function acceptCookieConsent(page: Page, config: Config): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 2000)); //wait for frames to be loaded; ToDo: consider alternatives
// await new Promise((resolve) => setTimeout(resolve, 2000)); //wait for frames to be loaded; ToDo: consider alternatives
await waitForHTML(page, config.timeout, config.debugMode);
const frames = page.frames();
let cookieId;
for (const frame of frames) {
Expand All @@ -18,7 +19,6 @@ export async function acceptCookieConsent(page: Page, config: Config): Promise<v
const cookieElements = Array.from(elements).filter((d) =>
RegExp(cookieText, 'i').test(d.textContent.trim()),
);
console.log(JSON.stringify(cookieElements.length));
if (cookieElements && cookieElements.length > 0) {
const element: HTMLElement = cookieElements[0];
if (!element.id) {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/analyze-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { Page } from 'puppeteer';
import { ResultByUrl } from '../models/a11y-sitechecker-result';
import { makeScreenshotsWithErrorsBorderd } from './make-sreenshots-with-errors-borderd';
import { createUrlResult } from './create-url-result';
import { acceptCookieConsent } from './accept-cookies';
import { acceptCookieConsent } from './accept-consent-screens';
import { saveScreenshot } from './helper-saving-screenshots';

const savedScreenshotHtmls: string[] = [];
const savedScreenshotHtmls: Map<string, string> = new Map();

export async function analyzeUrl(
page: Page,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function executeLogin(page: Page, config: Config): Promise<number>
} catch (e: any) {
error(e);
}
await waitForHTML(page);
await waitForHTML(page, config.timeout, config.debugMode);
await saveScreenshot(page, config.imagesPath, 'loginSite.png', config.saveImages);
} catch (e) {
failedLoads++;
Expand Down
22 changes: 16 additions & 6 deletions lib/utils/make-sreenshots-with-errors-borderd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function makeScreenshotsWithErrorsBorderd(
resultByUrl: ResultByUrl,
page: Page,
config: Config,
savedScreenshotHtmls: string[],
savedScreenshotHtmls: Map<string, string | null>,
): Promise<void> {
let currentMapObject = uniqueNamePerUrl.get(resultByUrl.url);
if (!currentMapObject) {
Expand All @@ -46,7 +46,8 @@ export async function makeScreenshotsWithErrorsBorderd(

for (const result of resultByUrl.violations) {
for (const node of result.nodes) {
if (!savedScreenshotHtmls.includes(node.html) && currentMapObject) {
const alreadyScreenshotedImage = savedScreenshotHtmls.get(node.html);
if (alreadyScreenshotedImage === undefined && currentMapObject) {
const image = currentMapObject.id + '_' + currentMapObject.count + '.png';
const screenshotResult = await saveScreenshotSingleDomElement(
page,
Expand All @@ -60,15 +61,24 @@ export async function makeScreenshotsWithErrorsBorderd(

if (typeof screenshotResult === 'boolean' && screenshotResult === true) {
node.image = image;
savedScreenshotHtmls.set(node.html, image);
currentMapObject.count++;
} else if (typeof screenshotResult === 'string') {
node.image = screenshotResult;
savedScreenshotHtmls.set(node.html, screenshotResult);
currentMapObject.count++;
} else {
savedScreenshotHtmls.set(node.html, null);
}

savedScreenshotHtmls.push(node.html);
} else {
debug(config.debugMode, 'Nothing happend, because already screenshoted: ' + node.html);
} else if (alreadyScreenshotedImage !== null) {
debug(
config.debugMode,
'There was already a screenshot. Updated node ' +
node.html +
' with old image_id:' +
alreadyScreenshotedImage,
);
node.image = alreadyScreenshotedImage;
}
}
}
Expand Down
Loading

0 comments on commit 8c28e43

Please sign in to comment.