const { test, expect } = require('@playwright/test');
test('Check if the page can scroll to the end', async ({ page }) => {
await page.goto('https://yourwebsite.com'); // Visit your website
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight)); // scroll to bottom
await page.waitForTimeout(500); // Wait for any lazy-loaded content to load
// if not lazy loaded content you can remove above line
// Calculate if user scrolled to end of page
const isAtEndOfPage = await page.evaluate(() => {
const scrollableHeight = document.documentElement.scrollHeight;
const currentScrollPosition = window.innerHeight + window.scrollY;
return currentScrollPosition >= scrollableHeight;
});
// Check if the page scrolls to the end
expect(isAtEndOfPage).toBe(true);
});
我会这样测试。滚动到页面末尾。检查滚动高度是否与滚动位置和视口高度相匹配。如果匹配,则为页面末尾。如果不匹配,则可能是一些 CSS 问题,例如内容溢出。这是我的代码,如果它对您有帮助,请告诉我: