const { Builder, By, until } = require("selenium-webdriver"); const path = require("path"); const fs = require("fs"); const validImageExtensions = [".png", ".jpg", ".jpeg", ".webp", ".gif", ".svg"]; const baseUrl = "http://localhost:3000"; const pagesToTest = [ { url: "/", name: "Home" }, { url: "/about", name: "About" }, { url: "/services-digital-solutions", name: "Services" }, { url: "/careers", name: "Careers" }, { url: "/portfolio", name: "Portfolio" }, { url: "/blog", name: "Blog" }, { url: "/contact", name: "Contact" }, { url: "/faq", name: "Faq" }, { url: "/service/website-development-company", name: "Web Development" }, { url: "/service/mobile-application-development", name: "Application Development" }, { url: "/service/graphic-designing-company", name: "Graphic Designing" }, { url: "/service/ui-ux-designing", name: "UI/UX Designing" }, { url: "/service/search-engine-optimization-seo-content-writing", name: "Seo Content Writing" }, { url: "/service/digital-marketing-agency-in-canada", name: "Digital Marketing" }, ]; (async function testPages() { const driver = await new Builder().forBrowser("chrome").build(); try { for (const page of pagesToTest) { console.log(`\n\n🌐 Testing Page: ${page.name.toUpperCase()} - ${page.url}\n`); await driver.get(`${baseUrl}${page.url}`); await driver.wait(until.elementLocated(By.css("body")), 10000); // 1. Page Title const title = await driver.getTitle(); console.log(`šŸ“„ Title: "${title}" ${title ? "āœ…" : "āŒ"}`); // 2. Favicon Check try { const favicon = await driver.findElement(By.css("link[rel='icon']")); const href = await favicon.getAttribute("href"); console.log(`šŸ”— Favicon: ${href ? "āœ… Found" : "āŒ Missing"}`); } catch { console.log("āŒ Favicon Not Found"); } // 3. Check Images console.log("šŸ–¼ļø Checking Images..."); const images = await driver.findElements(By.css("img")); let allValid = true; for (let i = 0; i < images.length; i++) { const img = images[i]; const src = await img.getAttribute("src"); const isLoaded = await driver.executeScript( "return arguments[0].complete && arguments[0].naturalWidth > 0;", img ); const ext = path.extname(new URL(src).pathname).toLowerCase(); const isFormatValid = validImageExtensions.includes(ext); if (isLoaded && isFormatValid) { console.log(`āœ… Image ${i + 1}: ${src}`); } else { console.log(`āŒ Image ${i + 1} Invalid: ${src} | Loaded: ${isLoaded} | Format: ${ext}`); allValid = false; } } if (allValid) { console.log("šŸŽ‰ All images are loaded & formats valid āœ…"); } else { console.log("āš ļø Some images are broken or wrong format āŒ"); } // 4. Check Internal Links console.log("šŸ”— Validating internal links..."); const links = await driver.findElements(By.css("a")); const hrefs = []; for (const link of links) { const href = await link.getAttribute("href"); if (href && href.startsWith(baseUrl)) { const internalPath = href.replace(baseUrl, ""); if (!hrefs.includes(internalPath)) hrefs.push(internalPath); } } for (const href of hrefs) { try { await driver.get(`${baseUrl}${href}`); const bodyText = await driver.findElement(By.css("body")).getText(); const is404 = bodyText.includes("404") || bodyText.toLowerCase().includes("not found"); console.log(`${is404 ? "āŒ Broken Link:" : "āœ… Link OK:"} ${href}`); } catch { console.log(`āŒ Navigation Error: ${href}`); } } // Return to original page await driver.get(`${baseUrl}${page.url}`); } // 5. Test 404 Page console.log("\nšŸ”Ž Testing 404 Page..."); await driver.get(`${baseUrl}/404`); const bodyText = await driver.findElement(By.css("body")).getText(); if (bodyText.includes("404") || bodyText.toLowerCase().includes("not found")) { console.log("āœ… 404 Page Working"); } else { console.log("āŒ 404 Page Not Detected"); } } catch (err) { console.error("āŒ Test Error:", err.message); } finally { await driver.quit(); } })();