@devjoyvn/simulate-action

1.0.4 • Public • Published

Simulate user actions with Puppeteer

Uses

npm install @devjoyvn/simulate-action

or

yarn add @devjoyvn/simulate-action

In javascript file:

const {SimulateActions} = require('@devjoyvn/simulate-action')
const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--window-size=1920,1080',
        ]
    });
    const page = await browser.newPage();

    await page.setViewport({
        width: 1920,
        height: 1080,
    });

    const userFake = await new SimulateActions().init(page);

    await page.goto('https://www.npmjs.com/');

    await page.waitForSelector('input[name="q"]')

    const searchInput = await page.$('input[name="q"]')

    await userFake.simClickElement(searchInput)

    await userFake.simClick();

    await userFake.simKeyboardType('@devjoyvn/simulate-action', {pauseAfterLastKeyUp: true})

    await userFake.simKeyboardEsc();

    await page.waitForSelector('button[type="submit"]')
    const submitButtons = await page.$('button[type="submit"]');

    await userFake.simClickElement(submitButtons)

    await page.waitForNavigation();

})();

Support actions

Function Action
simMouseMoveTo({x: number, y: number}, maxPoints: number, timestamp: number, cpDelta: number) Move to any point
simRandomMouseMove() Random move to any point
simClick({pauseAfterMouseUp: true}) Click in recent point
simMoveToAndClick({x: number, y: number}, {pauseAfterMouseUp: true}) Move to point and click
simMouseMoveToElement(element: ElementHandle) Move to element
simClickElement(element: ElementHandle, {pauseAfterMouseUp: true}) Move to element and click element
simKeyboardType(text: string, {pauseAfterLastKeyUp: true}) Typing any text
simKeyboardEnter({pauseAfterKeyUp: true}) Press Enter
simKeyboardEsc({pauseAfterKeyUp: true}) Press Esc

Package Sidebar

Install

npm i @devjoyvn/simulate-action

Weekly Downloads

0

Version

1.0.4

License

ISC

Unpacked Size

29.4 kB

Total Files

5

Last publish

Collaborators

  • devjoy