From 5ab0adc8839290f6eb0e0cc651bdc4bb45d7a136 Mon Sep 17 00:00:00 2001 From: Ashok Kumar Date: Fri, 31 Oct 2025 12:34:41 +0800 Subject: [PATCH] Chore: Update the Cypress JS example with custom threshold validation at the test level and capture a screenshot in Cypress to handle the session with a red highlighter --- .../cypress.config.js | 23 +- .../cypress/e2e/spec.cy.js | 36 +-- .../cypress/support/e2e.js | 214 +++++++++++++----- .../oobee-cypress-integration-js/package.json | 5 +- 4 files changed, 203 insertions(+), 75 deletions(-) diff --git a/examples/oobee-cypress-integration-js/cypress.config.js b/examples/oobee-cypress-integration-js/cypress.config.js index 5ee1a137..0df5d036 100644 --- a/examples/oobee-cypress-integration-js/cypress.config.js +++ b/examples/oobee-cypress-integration-js/cypress.config.js @@ -1,5 +1,8 @@ import { defineConfig } from "cypress"; import oobeeA11yInit from "@govtechsg/oobee"; +import fs from 'fs-extra'; +import { glob } from 'glob'; +import path from 'path'; // viewport used in tests to optimise screenshots const viewportSettings = { width: 1920, height: 1040 }; @@ -15,7 +18,7 @@ const oobeeA11y = await oobeeA11yInit({ testLabel: "Demo Cypress Scan", // label for test name: "Your Name", email: "email@domain.com", - includeScreenshots: true, // include screenshots of affected elements in the report + includeScreenshots: false, // include screenshots of affected elements in the report viewportSettings, thresholds, scanAboutMetadata, @@ -56,6 +59,24 @@ export default defineConfig({ async terminateOobeeA11y() { return await oobeeA11y.terminate(); }, + returnOobeeRandomTokenAndPage() { + return { + randomToken: oobeeA11y.randomToken, + // page: `${String(oobeeA11y.scanDetails.urlsCrawled.scanned.length).padStart(9, '0')}.json`, + }; + }, + copyFiles({fromPattern, toDir}) { + !fs.existsSync(toDir) && fs.mkdirSync(toDir, {recursive: true}); + + const files = glob.sync(fromPattern); + + for (const file of files) { + const to = path.join(toDir, path.basename(file)); + fs.copyFileSync(file, to); + } + + return null; + }, }); }, }, diff --git a/examples/oobee-cypress-integration-js/cypress/e2e/spec.cy.js b/examples/oobee-cypress-integration-js/cypress/e2e/spec.cy.js index cc359176..8a15a757 100644 --- a/examples/oobee-cypress-integration-js/cypress/e2e/spec.cy.js +++ b/examples/oobee-cypress-integration-js/cypress/e2e/spec.cy.js @@ -1,19 +1,27 @@ -describe("template spec", () => { - it("should run oobee A11y", () => { - cy.visit( - "https://govtechsg.github.io/purple-banner-embeds/purple-integrated-scan-example.htm" - ); +describe('template spec', () => { + beforeEach(() => { + cy.visit('https://govtechsg.github.io/purple-banner-embeds/purple-integrated-scan-example.htm'); cy.injectOobeeA11yScripts(); - cy.runOobeeA11yScan(); - - cy.get("button[onclick=\"toggleSecondSection()\"]").click(); - // Run a scan on and