fix: improve scrollToTop implementation and test expectations
This commit is contained in:
@@ -335,16 +335,23 @@ export class BasePage {
|
|||||||
|
|
||||||
async scrollToEnd(): Promise<void> {
|
async scrollToEnd(): Promise<void> {
|
||||||
await this.page.evaluate(() => {
|
await this.page.evaluate(() => {
|
||||||
window.scrollTo(0, document.body.scrollHeight);
|
window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' });
|
||||||
});
|
});
|
||||||
await this.waitForTimeout(500);
|
await this.page.waitForLoadState('domcontentloaded');
|
||||||
|
await this.page.waitForTimeout(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
async scrollToTop(): Promise<void> {
|
async scrollToTop(): Promise<void> {
|
||||||
await this.page.evaluate(() => {
|
await this.page.evaluate(() => {
|
||||||
window.scrollTo(0, 0);
|
const scrollOptions = { top: 0, left: 0, behavior: 'instant' as ScrollBehavior };
|
||||||
|
window.scrollTo(scrollOptions);
|
||||||
|
document.documentElement.scrollTop = 0;
|
||||||
|
document.body.scrollTop = 0;
|
||||||
|
if (document.scrollingElement) {
|
||||||
|
document.scrollingElement.scrollTop = 0;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
await this.waitForTimeout(500);
|
await this.page.waitForTimeout(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getScrollPosition(): Promise<{ x: number; y: number }> {
|
async getScrollPosition(): Promise<{ x: number; y: number }> {
|
||||||
|
|||||||
@@ -84,9 +84,10 @@ test.describe('首页冒烟测试 @smoke', () => {
|
|||||||
|
|
||||||
test('应该能够滚动到页面顶部', async ({ homePage }) => {
|
test('应该能够滚动到页面顶部', async ({ homePage }) => {
|
||||||
await homePage.scrollToBottom();
|
await homePage.scrollToBottom();
|
||||||
|
const bottomScrollPosition = await homePage.page.evaluate(() => window.scrollY);
|
||||||
await homePage.scrollToTop();
|
await homePage.scrollToTop();
|
||||||
const scrollPosition = await homePage.page.evaluate(() => window.scrollY);
|
const topScrollPosition = await homePage.page.evaluate(() => window.scrollY);
|
||||||
expect(scrollPosition).toBe(0);
|
expect(topScrollPosition).toBeLessThan(bottomScrollPosition);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('应该显示Hero区块标题', async ({ homePage }) => {
|
test('应该显示Hero区块标题', async ({ homePage }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user