Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll up and scroll down using TestCafe?

How can I scroll up and scroll down using TestCafe?

I tried window.scroll(), window.scrollTo()and throws an error window is not defined.

like image 268
chris Avatar asked Sep 30 '19 21:09

chris


1 Answers

UPD: In v1.14.0 and later versions, you can use the following scroll methods: t.scroll, t.scrollBy, and t.scrollIntoView.

Old answer:

In your case, you can create your own 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);
});

The t.hover action example:

// scroll to the "#some-element-scroll-to" element
await t.hover(Selector('#some-element-scroll-to'));
like image 167
Vladimir A. Avatar answered Nov 12 '22 17:11

Vladimir A.