const { Builder, By, until } = require("selenium-webdriver"); (async function testHomePage() { const driver = await new Builder().forBrowser("chrome").build(); try { await driver.get("http://localhost:3000/"); await driver.wait(until.elementLocated(By.css("body")), 10000); // 1. โœ… Page Title Test const title = await driver.getTitle(); console.log(`\n๐Ÿ“„ Page 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 Found: ${href ? href : "Missing"} ${href ? "โœ…" : "โŒ"}`); } catch { console.log("๐Ÿ”— Favicon - Not Found โŒ"); } // 3. โœ… Section Visibility console.log("\n๐Ÿ” Checking Section Visibility..."); const sections = [ { name: "Header", selector: ".header-style-two" }, { name: "Hero", selector: ".banner-section" }, { name: "Popular Dishes", selector: "#popular-dishes" }, { name: "Menu Card", selector: ".fluid-section-two" }, { name: "Sixty5 Street Specials", selector: "#sixty5-street-specials" }, { name: "Menu", selector: "#menu" }, { name: "Services", selector: ".menu-page-section" }, { name: "Gallery", selector: "#gallery" }, { name: "Footer", selector: ".footer-style-two" }, ]; for (let section of sections) { try { const el = await driver.findElement(By.css(section.selector)); const isDisplayed = await el.isDisplayed(); console.log(`${section.name} Section - ${isDisplayed ? "Visible โœ…" : "Not Visible โŒ"}`); } catch { console.log(`${section.name} Section - Not Found โŒ`); } } // 4. โœ… In-Page Anchor Links console.log("\n๐Ÿงช Testing Anchor Navigation Buttons..."); const navTests = [ { label: "Explore Menu", selector: "a[href='#menu']", anchorId: "menu" }, ]; for (const test of navTests) { try { const link = await driver.findElement(By.css(test.selector)); await link.click(); await driver.sleep(1000); const target = await driver.findElement(By.css(`#${test.anchorId}`)); const isDisplayed = await target.isDisplayed(); console.log(`Clicked '${test.label}' โžก๏ธ ${isDisplayed ? "Scrolled Successfully โœ…" : "Failed โŒ"}`); } catch { console.log(`Clicked '${test.label}' โžก๏ธ Error โŒ`); } } // 6. โœ… Check All Images on Page console.log("\n๐Ÿ–ผ๏ธ Checking All Images on Home Page..."); try { const images = await driver.findElements(By.css("img")); let allLoaded = true; for (let i = 0; i < images.length; i++) { const img = images[i]; const isLoaded = await driver.executeScript( "return arguments[0].complete && arguments[0].naturalWidth > 0;", img ); const src = await img.getAttribute("src"); if (isLoaded) { console.log(`โœ… Image ${i + 1}: ${src}`); } else { console.log(`โŒ Image ${i + 1} Not Loaded: ${src}`); allLoaded = false; } } if (allLoaded) { console.log("๐ŸŽ‰ All images are properly loaded โœ…"); } else { console.log("โš ๏ธ Some images failed to load โŒ"); } } catch (e) { console.log("โŒ Error during image check:", e.message); } // 7. โœ… 404 Page Test console.log("\n๐Ÿ”Ž Testing 404 Not Found Page..."); await driver.get("http://localhost:3000/thispagedoesnotexist"); await driver.sleep(1000); 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("โŒ Error:", err.message); } finally { await driver.quit(); } })();