automatonic-v2 v1.1.6
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.nodeIntegrationis set tofalsebecause 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:
stringvariable 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 ifnodeIntegrationis disabled (the default). - preloadScript:
stringof 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
BrowserWindowinstance belonging to thisBrowser.
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, andmouseupevents. This will wait up to 1s (default, change with thetimeoutoption) 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, andkeyup. Once all of the characters are added, achangeevent will be triggered. This will wait up to 1s (default, change with thetimeoutoption) for the element to appear. Specifyingappend: truewill not empty the target input before sending characters.checkForText(string)
Immediately check to see if
stringexists in the page HTML. Ifstringis a RegExp, then itstestmethod 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.