如何使用 TestCafe 向上和向下滚动?

chr*_*ris 5 testing scroll automated-tests e2e-testing testcafe

如何使用 TestCafe 向上和向下滚动?

我试过了window.scroll()window.scrollTo()并抛出一个错误窗口未定义。

Vla*_* A. 9

UPD:在v1.14.0及更高版本中,您可以使用以下滚动方法:t.scrollt.scrollByt.scrollIntoView

旧答案:

在您的情况下,您可以创建自己的ClientFunction

import { ClientFunction } from 'testcafe';

fixture `Fixture`
    .page `https://github.com/DevExpress/testcafe`;

const scroll = ClientFunction(function() {
    window.scrollBy(0,1500);
});

test(`test`, async t => {
    await scroll();
    await t.wait(1000);
});
Run Code Online (Sandbox Code Playgroud)

t.hover操作实例:

// scroll to the "#some-element-scroll-to" element
await t.hover(Selector('#some-element-scroll-to'));
Run Code Online (Sandbox Code Playgroud)

  • 请参阅[此处](https://github.com/DevExpress/testcafe-examples/tree/master/examples/scroll)的可执行示例 (2认同)