|
1 | 1 | import { test, expect } from "@playwright/test"; |
2 | 2 |
|
3 | | -const languages = ["en", "id"]; |
| 3 | +const URL = "http://localhost:3000"; |
4 | 4 |
|
5 | | -for (const lang of languages) { |
6 | | - test(`Homepage (${lang}) should load sections`, async ({ page }) => { |
7 | | - await page.goto(`/${lang}`); |
| 5 | +test.describe("Homepage", () => { |
| 6 | + test("Branding: should display hyperjump logo correctly in navbar and footer", async ({ |
| 7 | + page |
| 8 | + }) => { |
| 9 | + await page.goto(URL); |
8 | 10 |
|
9 | | - await expect(page.locator("#hero")).toBeVisible({ timeout: 10000 }); |
10 | | - await expect(page.locator("#services")).toBeVisible({ timeout: 10000 }); |
11 | | - await expect(page.locator("#case-studies")).toBeVisible({ timeout: 10000 }); |
12 | | - await expect(page.locator("#open-source")).toBeVisible({ timeout: 10000 }); |
13 | | - await expect(page.locator("#faqs")).toBeVisible({ timeout: 10000 }); |
| 11 | + const navbarLogo = page |
| 12 | + .getByRole("link", { name: "Hyperjump Logo" }) |
| 13 | + .first(); |
| 14 | + await expect(navbarLogo).toBeVisible(); |
| 15 | + await navbarLogo.click(); |
| 16 | + await expect(page).toHaveURL(/\/(en|id)?\/?$/); |
| 17 | + |
| 18 | + // Footer |
| 19 | + const footerLogo = page |
| 20 | + .getByRole("contentinfo") |
| 21 | + .getByRole("link", { name: "Hyperjump Logo" }); |
| 22 | + await expect(footerLogo).toBeVisible(); |
| 23 | + await footerLogo.click(); |
| 24 | + await expect(page).toHaveURL(/\/(en|id)?\/?$/); |
| 25 | + }); |
| 26 | + |
| 27 | + test("SEO: meta title and description should exist and match expected content", async ({ |
| 28 | + page |
| 29 | + }) => { |
| 30 | + await page.goto(URL); |
| 31 | + |
| 32 | + const title = await page.title(); |
| 33 | + const description = await page |
| 34 | + .locator('meta[name="description"]') |
| 35 | + .getAttribute("content"); |
| 36 | + |
| 37 | + expect(title.length).toBeGreaterThan(10); |
| 38 | + expect(description?.length).toBeGreaterThan(20); |
| 39 | + }); |
| 40 | + |
| 41 | + // Test Structure / UI Sections |
| 42 | + test("Hero Section: should display hero title, subtitle, and CTA button correctly", async ({ |
| 43 | + page |
| 44 | + }) => { |
| 45 | + await page.goto(URL); |
| 46 | + |
| 47 | + // Hero title and subtitle |
| 48 | + const heroHeading = page.getByRole("heading", { |
| 49 | + name: "Your partner in building" |
| 50 | + }); |
| 51 | + await expect(heroHeading).toBeVisible(); |
| 52 | + |
| 53 | + const heroSubtitle = page.getByText("We help organizations deliver"); |
| 54 | + await expect(heroSubtitle).toBeVisible(); |
| 55 | + |
| 56 | + // Partner logos |
| 57 | + const partnerLogos = [ |
| 58 | + "Amman Mineral Internasional", |
| 59 | + "Bank Tabungan Negara", |
| 60 | + "Eka Mas Republik", |
| 61 | + "Sinar Mas Digital Day", |
| 62 | + "Smartfren" |
| 63 | + ]; |
| 64 | + |
| 65 | + for (const name of partnerLogos) { |
| 66 | + const logo = page.getByRole("img", { name }); |
| 67 | + await expect(logo).toBeVisible(); |
| 68 | + } |
| 69 | + }); |
| 70 | + |
| 71 | + test("Services Section: should display all service cards and links correctly", async ({ |
| 72 | + page |
| 73 | + }) => { |
| 74 | + await page.goto(URL); |
| 75 | + |
| 76 | + const servicesHeading = page.getByRole("heading", { |
| 77 | + name: "Services", |
| 78 | + exact: true |
| 79 | + }); |
| 80 | + await expect(servicesHeading).toBeVisible(); |
| 81 | + await expect(page.getByText("We offer expert technology")).toBeVisible(); |
| 82 | + |
| 83 | + // Service cards |
| 84 | + const services = [ |
| 85 | + { title: "Inference AI", desc: "Inference AIDesign, develop," }, |
| 86 | + { title: "ERP Implementation", desc: "ERP ImplementationStreamline" }, |
| 87 | + { title: "CTO-as-a-Service", desc: "CTO-as-a-ServiceFinding," }, |
| 88 | + { title: "Software as a Service", desc: "Software as a ServiceDeploy" }, |
| 89 | + { title: "Tech Due Diligence", desc: "Tech Due DiligenceVerify and" } |
| 90 | + ]; |
| 91 | + |
| 92 | + for (const s of services) { |
| 93 | + await expect(page.getByText(s.desc)).toBeVisible(); |
| 94 | + await expect(page.getByRole("img", { name: s.title })).toBeVisible(); |
| 95 | + await expect(page.getByText(s.title, { exact: true })).toBeVisible(); |
| 96 | + } |
| 97 | + |
| 98 | + // View more link |
| 99 | + const viewMore = page |
| 100 | + .locator("#services") |
| 101 | + .getByRole("link", { name: "View More" }); |
| 102 | + await expect(viewMore).toBeVisible(); |
| 103 | + await expect(viewMore).toHaveAttribute("href", /services/i); |
| 104 | + }); |
| 105 | + |
| 106 | + test("Case Studies Section: should display case study items and links correctly", async ({ |
| 107 | + page |
| 108 | + }) => { |
| 109 | + await page.goto(URL); |
| 110 | + |
| 111 | + await page.locator("#case-studies").click(); |
| 112 | + |
| 113 | + const caseHeading = page.getByRole("heading", { name: "Case Studies" }); |
| 114 | + await expect(caseHeading).toBeVisible(); |
| 115 | + await expect(page.getByText("Discover how we successfully")).toBeVisible(); |
| 116 | + |
| 117 | + await expect(page.getByText("Transforming a Fisheries Tech")).toBeVisible(); |
| 118 | + await expect(page.getByText("Elevating a Media-Tech")).toBeVisible(); |
| 119 | + }); |
| 120 | + |
| 121 | + test("FAQ Section: should toggle FAQ items correctly on click", async ({ |
| 122 | + page |
| 123 | + }) => { |
| 124 | + await page.goto(URL); |
| 125 | + |
| 126 | + await page.locator("#faqs").click(); |
| 127 | + |
| 128 | + const faqHeading = page.getByRole("heading", { |
| 129 | + name: "Frequently asked questions" |
| 130 | + }); |
| 131 | + await expect(faqHeading).toBeVisible(); |
| 132 | + await expect(page.getByText("Find answers to commonly")).toBeVisible(); |
| 133 | + |
| 134 | + const faqQuestions = [ |
| 135 | + "What is CTO as a Service (", |
| 136 | + "How do you approach ERP", |
| 137 | + "What does your tech due", |
| 138 | + "Why should we choose your" |
| 139 | + ]; |
| 140 | + |
| 141 | + for (const question of faqQuestions) { |
| 142 | + const btn = page.getByRole("button", { name: question }); |
| 143 | + await expect(btn).toBeVisible(); |
| 144 | + await btn.click(); |
| 145 | + } |
| 146 | + |
| 147 | + await expect(page.getByText("We offer specialized")).toBeVisible(); |
14 | 148 | }); |
15 | | -} |
| 149 | + |
| 150 | + // Responsive Design |
| 151 | + const devices = [ |
| 152 | + { name: "Mobile", width: 375, height: 812 }, |
| 153 | + { name: "Tablet", width: 768, height: 1024 }, |
| 154 | + { name: "Desktop", width: 1440, height: 900 }, |
| 155 | + { name: "Large Desktop", width: 1920, height: 1080 } |
| 156 | + ]; |
| 157 | + |
| 158 | + for (const device of devices) { |
| 159 | + test.describe(`${device.name} Responsive Layout`, () => { |
| 160 | + test(`should display correctly on ${device.name}`, async ({ |
| 161 | + browser |
| 162 | + }) => { |
| 163 | + const context = await browser.newContext({ |
| 164 | + viewport: { width: device.width, height: device.height } |
| 165 | + }); |
| 166 | + const page = await context.newPage(); |
| 167 | + |
| 168 | + await page.goto(URL, { |
| 169 | + waitUntil: "domcontentloaded" |
| 170 | + }); |
| 171 | + |
| 172 | + const hero = page.locator("#hero"); |
| 173 | + const services = page.locator("#services"); |
| 174 | + const caseStudies = page.locator("#case-studies"); |
| 175 | + const openSource = page.locator("#open-source"); |
| 176 | + const faq = page.locator("#faqs"); |
| 177 | + const footer = page.locator("footer"); |
| 178 | + |
| 179 | + await expect(hero).toBeVisible(); |
| 180 | + await expect(services).toBeVisible(); |
| 181 | + await expect(caseStudies).toBeVisible(); |
| 182 | + await expect(openSource).toBeVisible(); |
| 183 | + await expect(faq).toBeVisible(); |
| 184 | + await expect(footer).toBeVisible(); |
| 185 | + |
| 186 | + await page.evaluate(async () => { |
| 187 | + const delay = (ms: number) => |
| 188 | + new Promise((res) => setTimeout(res, ms)); |
| 189 | + const totalHeight = document.body.scrollHeight; |
| 190 | + const step = window.innerHeight / 2; |
| 191 | + for (let y = 0; y < totalHeight; y += step) { |
| 192 | + window.scrollTo({ top: y, behavior: "smooth" }); |
| 193 | + await delay(200); |
| 194 | + } |
| 195 | + window.scrollTo({ top: totalHeight, behavior: "smooth" }); |
| 196 | + }); |
| 197 | + |
| 198 | + await page.waitForTimeout(2000); |
| 199 | + |
| 200 | + await page.screenshot({ |
| 201 | + path: `screenshots/homepage-full-${device.name.toLowerCase()}.png`, |
| 202 | + fullPage: true |
| 203 | + }); |
| 204 | + |
| 205 | + await context.close(); |
| 206 | + }); |
| 207 | + }); |
| 208 | + } |
| 209 | +}); |
0 commit comments