dailykart-testing/tests/footer-payment-icons.spec.ts

42 lines
1.6 KiB
TypeScript

import { test, expect } from '@playwright/test';
test('#8 Footer payment icons should not scroll page to top when clicked', async ({ page }) => {
// Step 1: Go to the shop page
await page.goto('https://uat.dailykart.net/shop', { waitUntil: 'domcontentloaded' });
// Step 2: Scroll to the bottom of the page
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
await page.waitForTimeout(1000); // wait for footer content to load
// Step 3: Capture current scroll position
const initialScrollY = await page.evaluate(() => window.scrollY);
console.log(`Initial scroll position: ${initialScrollY}`);
// Step 4: Select all payment icons that use href="#" (adjust selector as needed)
const paymentIcons = await page.$$('footer a[href="#"]');
const count = paymentIcons.length;
console.log(`Found ${count} payment icons.`);
expect(count).toBeGreaterThan(0); // make sure icons exist
// Step 5: Click each icon and verify scroll doesn't jump to top
for (let i = 0; i < count; i++) {
const icon = paymentIcons[i];
await icon.scrollIntoViewIfNeeded();
await icon.click();
await page.waitForTimeout(300);
const currentScrollY = await page.evaluate(() => window.scrollY);
console.log(`After clicking icon ${i + 1}, scrollY: ${currentScrollY}`);
// Assert the scroll doesn't jump to top (0)
expect(currentScrollY).toBeGreaterThan(0);
if (currentScrollY < initialScrollY - 2000) {
console.warn(` Scroll jumped unexpectedly after clicking icon ${i + 1}. Initial: ${initialScrollY}, Now: ${currentScrollY}`);
} else
{
expect(currentScrollY).toBeGreaterThan(0);
}
}
});