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.nodeIntegration
is set tofalse
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 ifnodeIntegration
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 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.stringify
ing 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
, andmouseup
events. This will wait up to 1s (default, change with thetimeout
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
, andkeyup
. Once all of the characters are added, achange
event will be triggered. This will wait up to 1s (default, change with thetimeout
option) for the element to appear. Specifyingappend: true
will not empty the target input before sending characters.checkForText(string)
Immediately check to see if
string
exists in the page HTML. Ifstring
is a RegExp, then itstest
method will be used to determine whether or not there is a match.
Utility methods
- sleep(milliseconds)
Returns a Promise that resolves after
milliseconds
ms have elapsed.