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 6a57ea4 commit 6e43d44
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lighthouse-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
run: |
echo "Waiting for server to be ready..."
for ((i=1; i<=${{ env.WAIT_TIME }}; i++)); do
if curl -s -f http://localhost:8080 > /dev/null; then
if curl -s -f http://localhost:8080/pro/portal/1549F58C18A6C562/DashboardPage.ivp?dashboardId=1 > /dev/null; then
echo "Server is running"
exit 0
fi
Expand Down
59 changes: 34 additions & 25 deletions AxonIvyPortal/portal-selenium-test/lighthouse/puppeteer-script.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const PORTAL_URL = "http://localhost:8080";
const LOGIN_URL = `${PORTAL_URL}/Portal/login`;
const DASHBOARD_URL = `${PORTAL_URL}/Portal/pro/portal/1549F58C18A6C562/DashboardPage.ivp?dashboardId=1`;

const debugLog = (msg) => console.log(`[Debug] ${msg}`);

(async () => {
let browser;
try {
// Health check
// Check server availability first
debugLog("Checking server status...");
const healthCheck = await fetch("http://localhost:8080/portal/health");
if (!healthCheck.ok) {
throw new Error(`Server health check failed: ${healthCheck.status}`);
const serverCheck = await fetch(PORTAL_URL);
if (!serverCheck.ok) {
throw new Error(`Server not available: ${serverCheck.status}`);
}
debugLog("Server is healthy");

Expand All @@ -37,41 +41,46 @@ const debugLog = (msg) => console.log(`[Debug] ${msg}`);
await page.setViewport({ width: 1920, height: 1080 });
debugLog("Browser launched");

// Test portal access
const portalUrl = "http://localhost:8080/portal/faces/login.xhtml";
debugLog(`Navigating to ${portalUrl}`);

const response = await page.goto(portalUrl, {
waitUntil: ["networkidle0", "domcontentloaded"],
timeout: 60000,
// Navigate to login page
debugLog(`Navigating to ${LOGIN_URL}`);
const loginResponse = await page.goto(LOGIN_URL, {
waitUntil: "networkidle0",
timeout: 30000,
});

if (!response.ok()) {
throw new Error(`Page load failed: ${response.status()}`);
if (!loginResponse.ok()) {
throw new Error(`Login page failed to load: ${loginResponse.status()}`);
}
debugLog(`Portal loaded: ${response.status()}`);
debugLog(`Login page loaded: ${loginResponse.status()}`);

// Login
// Handle login form
debugLog("Attempting login...");
await page.waitForSelector("#username", { visible: true, timeout: 30000 });
await page.type("#username", "demo");
await page.type("#password", "demo");

await page.type('input[name="username"]', "demo");
await page.type('input[name="password"]', "demo");
await Promise.all([
page.click('button[type="submit"]'),
page.waitForNavigation({
waitUntil: "networkidle0",
timeout: 30000,
}),
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
debugLog("Login successful");

// Run Lighthouse
await page.goto(DASHBOARD_URL, {
waitUntil: "networkidle0",
timeout: 30000,
});

// Verify dashboard loaded
debugLog("Verifying dashboard loaded...");
await page.waitForSelector(".dashboard-container", {
timeout: 30000,
});
debugLog("Dashboard loaded");

// Run Lighthouse audit
debugLog("Starting Lighthouse audit...");
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
Expand Down

0 comments on commit 6e43d44

Please sign in to comment.