1.0.4 • Published 2 years ago

@devjoyvn/simulate-action v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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

FunctionAction
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