-
Notifications
You must be signed in to change notification settings - Fork 4
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
a9b61b2
commit ce23b82
Showing
2 changed files
with
98 additions
and
65 deletions.
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
50 changes: 50 additions & 0 deletions
50
AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.js
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,50 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const puppeteer = require("puppeteer"); | ||
const lighthouse = require("lighthouse"); | ||
const { URL } = require("url"); | ||
const { exec } = require("child_process"); | ||
|
||
// Read user credentials | ||
const csvFilePath = path.join( | ||
__dirname, | ||
"AxonIvyPortal/portal-selenium-test/jmeter/data/users_local.csv" | ||
); | ||
const users = fs | ||
.readFileSync(csvFilePath, "utf-8") | ||
.split("\n") | ||
.map((line) => { | ||
const [username, password] = line.split(","); | ||
return { username, password }; | ||
}); | ||
|
||
// Puppeteer script to navigate to the dashboard | ||
(async () => { | ||
const browser = await puppeteer.launch({ headless: false }); | ||
const page = await browser.newPage(); | ||
|
||
// Use the first user for login | ||
const user = users[0]; | ||
const loginUrl = "http://localhost:8080/Portal"; // Replace with actual login URL | ||
|
||
await page.goto(loginUrl); | ||
await page.type("#username", user.username); | ||
await page.type("#password", user.password); | ||
await page.click("#login-button"); // Replace with actual login button selector | ||
|
||
// Wait for navigation to dashboard | ||
await page.waitForNavigation(); | ||
|
||
// Run Lighthouse audit | ||
const { lhr } = await lighthouse(page.url(), { | ||
port: new URL(browser.wsEndpoint()).port, | ||
output: "html", | ||
logLevel: "info", | ||
}); | ||
|
||
// Save Lighthouse report | ||
const reportHtml = lhr.report; | ||
fs.writeFileSync("lighthouse-report.html", reportHtml); | ||
|
||
await browser.close(); | ||
})(); |