gremlins.js is a monkey testing library for web apps and Node.js that simulates random user interactions to find robustness bugs.
Basic Usage
CDN Unleash
<script src="https://cdn.jsdelivr.net/npm/gremlins/dist/gremlins.js"></script>
<script>
gremlins.createHorde().unleash();
</script>
Customizing the Horde
gremlins.createHorde()
.allGremlins()
.gremlin(function () {
// Custom action executed at regular intervals
document.activeElement.blur();
})
.unleash();
Full Configuration Example
gremlins.createHorde()
.gremlin(gremlins.species.formFiller())
.gremlin(gremlins.species.clicker()
.clickTypes(['click'])
.canClick(element => element.tagName !== 'A')
.showAction((x, y) => { /* Visual click indicator */ }))
.gremlin(gremlins.species.scroller())
.gremlin(gremlins.species.typer())
.mogwai(gremlins.mogwais.alert())
.mogwai(gremlins.mogwais.fps())
.mogwai(gremlins.mogwais.gizmo().maxErrors(2))
.unleash();
Lifecycle Hooks
Synchronous Before and After
gremlins.createHorde()
.before(function () {
this.log('Beginning monkey test execution');
console.profile('gremlins');
})
.after(function () {
this.log('Monkey testing complete');
console.profileEnd();
})
.unleash();
Asynchronous Hooks
gremlins.createHorde()
.before(function (done) {
setTimeout(() => {
this.log('Async setup completed');
done();
}, 500);
})
.unleash();
Species Reference
Gremlins (Attackers)
formFiller: Populates input, textarea, and select form controls with random valid inputs.clicker: Randomly clicks on active elements in the viewport.scroller: Scrolls the window in randomized directions and offsets.typer: Randomly types keys on focused inputs.toucher: Generates touch gestures on touch-enabled screen displays.
Mogwais (Watchdogs)
alert: Traps and logswindow.alertdialog calls.fps: Monitors frame rate and logs drops below threshold.gizmo: Halts execution when JavaScript runtime uncaught error count exceeds limits.