122 lines
4.9 KiB
JavaScript
122 lines
4.9 KiB
JavaScript
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 <a> 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();
|
|
}
|
|
})();
|