mercredi 10 janvier 2018

Trigger mouse wheel scroll event - puppeteer

I have a script in which I need to test the scrolling functionality on my page. I have two scroll bars, one for the browser window and another for my grid in which I have implemented infinite scroll. I am testing the browser window scroll like so:

(async () => {

    const innerWidth = await page.evaluate(_ => { return window.innerWidth} );
    const innerHeight = await page.evaluate(_ => { return window.innerHeight} );
    const mouse = page.mouse
    await mouse.move(innerWidth/2, innerHeight/2);

    await page.waitFor(500);

    // Scroll Window
    page.evaluate(_ => {
        window.scrollBy(0, innerHeight);
    });     
    ...
}();

This works fine for the window scroll, however, I cannot use this to test the mouse wheel scroll in the grid. I understand that there is a way to create a mouse wheel event in JQuery like so:

$(".testdiv").on('mousewheel', function(e){
  console.log(e);

})
var event = jQuery.Event( "mousewheel" );
event.deltaY = -1;
$(".testdiv").trigger(event); 

I need to do this in pure JS. Is there a way to implement this in my script with pure JS?

Aucun commentaire:

Enregistrer un commentaire