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 e4cdefa commit ab07560
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,41 @@ const packageJson = {
// Launch browser
const browser = await puppeteer.launch({
headless: "new",
args: ["--no-sandbox", "--disable-setuid-sandbox"],
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");
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"]');

// Wait for dashboard
await page.waitForNavigation();
await page.waitForNavigation({ waitUntil: "networkidle0" });

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

// Ensure directory exists
if (!fs.existsSync("lighthouse-reports")) {
fs.mkdirSync("lighthouse-reports");
}

// Save reports
fs.writeFileSync("lighthouse-reports/report.html", lhr.report[1]);
fs.writeFileSync(
Expand Down

0 comments on commit ab07560

Please sign in to comment.