如何使用TestCafe上下滚动?

时间:2019-09-30 21:23:36

标签: testing scroll automated-tests e2e-testing testcafe

如何使用TestCafe上下滚动?

我尝试了window.scroll()window.scrollTo()并引发错误窗口未定义。

1 个答案:

答案 0 :(得分:2)

根据您的情况,您可以创建自己的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);
});

TestCafe不提供特殊的滚动动作,因为它在单击,悬停等动作中具有内置的滚动功能。这意味着您可以使用hover动作代替上面的滚动客户端功能:

// scroll to the "#some-element-scroll-to" element
await t.hover(Selector('#some-element-scroll-to'));