Skip to content

Commit

Permalink
feature/IVYPORTAL-17377-Create-pipeline-to-run-Lighthouse-report
Browse files Browse the repository at this point in the history
  • Loading branch information
nhthinh-axonivy committed Dec 27, 2024
1 parent ab07560 commit 9cff1d9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/lighthouse-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ jobs:
xdpyinfo || true
- name: Run Puppeteer Script
run: node AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.js
run: |
cd AxonIvyPortal/portal-selenium-test/lighthouse
npm install
node puppeteer-script.mjs
- name: Upload Report
id: upload-artifact
Expand Down
10 changes: 10 additions & 0 deletions AxonIvyPortal/portal-selenium-test/lighthouse/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "lighthouse-test",
"version": "1.0.0",
"type": "module",
"dependencies": {
"lighthouse": "^11.6.0",
"puppeteer": "^22.3.0",
"@actions/core": "^1.10.1"
}
}
69 changes: 69 additions & 0 deletions AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import fs from "fs";
import path from "path";
import puppeteer from "puppeteer";
import lighthouse from "lighthouse";
import { fileURLToPath } from "url";
import { dirname } from "path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

(async () => {
try {
// Read user credentials
const csvFilePath = path.join(__dirname, "../jmeter/data/users_local.csv");
const users = fs
.readFileSync(csvFilePath, "utf-8")
.split("\n")
.filter(Boolean)
.map((line) => {
const [username, password] = line.trim().split(",");
return { username, password };
});

// Launch browser
const browser = await puppeteer.launch({
headless: "new",
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
],
});

const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 });

// Login process
const user = users[0];
await page.goto("http://localhost:8080/Portal", {
waitUntil: "networkidle0",
});
await page.waitForSelector("#username");
await page.type("#username", user.username);
await page.type("#password", user.password);
await page.click('button[type="submit"]');
await page.waitForNavigation({ waitUntil: "networkidle0" });

// Run Lighthouse
const { lhr } = await lighthouse(page.url(), {
port: new URL(browser.wsEndpoint()).port,
output: ["html", "json"],
logLevel: "info",
onlyCategories: ["performance", "accessibility", "best-practices", "seo"],
});

// Save reports
fs.writeFileSync("lighthouse-report.html", lhr.report[0]);
fs.writeFileSync(
"lighthouse-reports/report.json",
JSON.stringify(lhr, null, 2)
);

await browser.close();
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
})();

0 comments on commit 9cff1d9

Please sign in to comment.