Skip to content

Commit

Permalink
Merge pull request #1857 from IBMa/joho-checkerReportsTestCases-1841
Browse files Browse the repository at this point in the history
chore(extension): Checker XLS Report Test Case
  • Loading branch information
tombrunet authored May 17, 2024
2 parents dadf6d2 + b16ea27 commit 7954dcd
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 167 deletions.
3 changes: 3 additions & 0 deletions accessibility-checker-extension/src/ts/devtools/indexMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import { getTabIdAsync } from '../util/tabId';
let tabRef = (await chrome.tabs.query({ index }))[0];
let contentTabId = tabRef.id;
let toolTabId = await getTabIdAsync();
while (!toolTabId) {
toolTabId = await getTabIdAsync();
}
if (!toolTabId || !contentTabId) {
console.warn("Test initializing", toolTabId, contentTabId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
@e2e
Feature: HTML Report
Scenario: Generate a basic HTML report from side panel
When manual step
"""
Given page "https://altoromutual.12mc9fdq8fib.us-south.codeengine.appdomain.cloud/"
When user opens Devtools
When user opens Devtools panel "Elements"
When user opens Devtools subpanel "Accessibility Checker"
When user activates Button "Scan"
When user activates Button "Export XLS"
When user opens downloaded file "Accessibility_Report-Altoro Accessibility Testing Site.xlsx"
"""

Background:
# Load the checker panel, scan the page, and then download the reports
Given "desktop" page "altoro" and panel "assessment"
Given browser download folder "TC_HTML_report"
Then Button "Scan" is enabled
When user activates Button "Scan"
Then elem ".reportTreeGrid #tableGridHeader .gridHeaderCell > span" is visible
Then elem "#totalIssuesCount" text ends with "issues found"
When user activates Button "Export XLS"
When wait 2000
Then downloaded file "Accessibility_Report-Altoro Accessibility Testing Site.html" exists

Scenario: HTML report exists
Then downloaded file "Accessibility_Report-Altoro Accessibility Testing Site.html" exists
150 changes: 138 additions & 12 deletions accessibility-checker-extension/test/features/TC_XLS_report.feature

Large diffs are not rendered by default.

183 changes: 40 additions & 143 deletions accessibility-checker-extension/test/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions accessibility-checker-extension/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"exceljs": "^4.4.0",
"ts-node": "^10.9.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export class BrowserWrapper {
}
}
await new Promise(resolve => setTimeout(resolve, 3000));
const index = this.pageKeyToTabId("altoro")!;
const panelUrl = this.panelKeyToURL("assessment");
let p = await browser.newPage();
await p.goto(`${panelUrl}?index=${encodeURIComponent(index)}`);
await new Promise(resolve => setTimeout(resolve, 1000));
await p.close();

return browser;
})
}
Expand Down
22 changes: 22 additions & 0 deletions accessibility-checker-extension/test/support/steps/steps_excel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Given, Then} from '@cucumber/cucumber';
import { Workbook } from 'exceljs';
import { join } from 'path';
import { PupUtil } from '../util/pup';
import { strict as assert } from "assert";

Given("excel file {string}", async function(filename: string) {
const workbook = new Workbook();
await workbook.xlsx.readFile(join(PupUtil.getTempDownloadFolder(), filename));
this.excelFile = workbook;
});

Then ("Excel Sheet {string} Cell {string} is {string}", async function(sheetStr: string, cellStr: string, txt: string) {
let workbook: Workbook = this.excelFile;
let sheet = workbook.getWorksheet(sheetStr);
if (!sheet) {
assert.fail("Sheet does not exist");
} else {
let cell = sheet.getCell(cellStr);
assert.strictEqual(cell.text, txt);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {CustomWorld} from '../CustomWorld';
import { BrowserWrapper } from '../BrowserWrapper';
import { strict as assert } from "assert";
import { PupUtil } from "../util/pup";
import { existsSync, readdirSync } from 'fs';
import { join } from 'path';

Given("{string} page {string} and panel {string}", async function(widthKey, pageKey, panelKey) {
const browser : BrowserWrapper = this.browser;
Expand All @@ -12,6 +14,19 @@ Given("{string} page {string} and panel {string}", async function(widthKey, page
// assert.strictEqual(false, true, "Test");
});

Given("browser download folder {string}", async function(folder:string) {
const browser : BrowserWrapper = this.browser;
await PupUtil.setTempDownloadFolder(browser.page(), folder);
});

Then("downloaded file {string} exists", async function(file: string) {
let bExists = existsSync(join(PupUtil.getTempDownloadFolder(), file));
if (!bExists) {
console.info(readdirSync(PupUtil.getTempDownloadFolder()))
}
assert.strictEqual(bExists, true);
});

Then("Banner is loaded", function() {

})
Expand Down
23 changes: 23 additions & 0 deletions accessibility-checker-extension/test/support/util/pup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Page, ElementHandle, KeyInput } from "puppeteer";
import { strict as assert } from "assert";
import { IBaselineReport, IBaselineResult } from "accessibility-checker/lib/common/engine/IReport";
import { assertCompliance, getBaseline, getCompliance } from "accessibility-checker";
import { join } from "path";
import { tmpdir } from "os";
import { mkdirSync } from "fs";


export namespace PupUtil {
Expand Down Expand Up @@ -218,4 +221,24 @@ export namespace PupUtil {
assert(report.summary.counts.violation === (baseline ? baseline.summary.counts.violation : 0), message);
}
}

let downloadFolder: string | null = null;

export function getTempDownloadFolder() {
if (!downloadFolder) throw new Error("Download folder not set");
return downloadFolder;
}

export async function setTempDownloadFolder(page: Page, folder: string) {
if (folder.includes("..")) throw new Error(".. not allowed in folder name");
downloadFolder = join(tmpdir(),folder);
mkdirSync(downloadFolder, { recursive: true });

const client = await page.target().createCDPSession()
await client.send('Browser.setDownloadBehavior', {
behavior: 'allow',
downloadPath: downloadFolder
})
console.log("Setting download folder", downloadFolder);
}
}

0 comments on commit 7954dcd

Please sign in to comment.