-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/IVYPORTAL-17377-Create-pipeline-to-run-Lighthouse-report
- Loading branch information
1 parent
ab07560
commit 9cff1d9
Showing
3 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
AxonIvyPortal/portal-selenium-test/lighthouse/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
69
AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
})(); |