automatonic-v2

Browser automation using cordova and electron.

Usage no npm install needed!

<script type="module">
  import automatonicV2 from 'https://cdn.skypack.dev/automatonic-v2';
</script>

README

Automatonic

automatonic is a library that is meant to be used for browser automation.

API

All of the API methods return a Promise, and all of them use an internal queue to make sure actions run in the correct order. As this is still in a proof-of-concept phase, the API is fairly limited.

Browser

  • constructor([options object]) or Browser.new([options object])

    The options object is passed straight through to Electron's BrowserWindow. If not specified, webPreferences.nodeIntegration is set to false because it can interfere with module loaders and has the tiny risk of having a third party script completely own your machine.

    The automatonic specific options are:

    • pollInterval: number of milliseconds between element checks when waiting for an element to appear. Default is 200.
    • typingInterval: number of milliseconds between characters when typing into an input. Default is 50.
    • exposeElectronAs: string variable name to expose the electron module to the page e.g. window.${exposeElectronAs} = require('electron'). This is implemented with a preload script, so it works even if nodeIntegration is disabled (the default).
    • preloadScript: string of extra script that gets added to any generated preload script to be handed to electron.

    Any generated preload scripts are created as temporary files that are cleaned up when the main process exits.

Properties

  • browser

    The BrowserWindow instance belonging to this Browser.

Methods

  • goto(url)

    Navigate to the given url. The returned Promise resolves when the page load is complete.

  • execute(function[, ...args])

    Execute the given function in the browser by toString()ing it, JSON.stringifying the arguments, shipping them to the render instance, wrapping everything up in a Promise, and returning the result.

  • click(selector[, options object])

    Find an element with the given selector and trigger mouseover, mousedown, click, and mouseup events. This will wait up to 1s (default, change with the timeout option) for the element to appear.

  • type(selector, string[, options object])

    Find an element with the given selector, focus it, and then pass each character from the string into the target element. Each character will trigger keydown, keypress, update the value, input, and keyup. Once all of the characters are added, a change event will be triggered. This will wait up to 1s (default, change with the timeout option) for the element to appear. Specifying append: true will not empty the target input before sending characters.

  • checkForText(string)

    Immediately check to see if string exists in the page HTML. If string is a RegExp, then its test method will be used to determine whether or not there is a match.

Utility methods

  • sleep(milliseconds)

    Returns a Promise that resolves after millisecondsms have elapsed.