Gremlins.js

Gremlins is a JavaScript library to do “monkey-testing” by providing random user input (clicks, scrolls, and so on).

A cheatsheet by @rstacruz|Refreshed 7 months ago.Refresh|View source on Github

Simple example

Simple example

<script src='https://cdn.jsdelivr.net/npm/gremlins/dist/gremlins.js'></script>
<script>
gremlins.createHorde().unleash()
</script>

Custom gremlins

Custom gremlins

gremlins.createHorde()
  .allGremlins()
  .gremlin(function () {
    document.activeElement.blur()
  })

Runs the given function at regular intervals.

Full example

Full example

gremlins.createHorde()
  .gremlin(gremlins.species.formFiller())
  .gremlin(gremlins.species.clicker()
    .clickTypes(['click'])
    .canClick(element => { ··· })
    .showAction((x, y) => { ··· }))
  .gremlin(gremlins.species.scroller())
  .mogwai(gremlins.mogwais.alert())
  .mogwai(gremlins.mogwais.fps())
  .mogwai(gremlins.mogwais.gizmo().maxErrors(2))
  .unleash()

By default, all gremlins and mogwais species are added to the horde. Do it this way to customize gremlins.

See: Specifying gremlins

Before and after

Before and after

gremlins.createHorde()
  .before(function () {
    this.log('sync')
    console.profile('gremlins')
  })
  .after(function () {
    this.log('done')
    console.profileEnd()
  })

Asynchronous

Asynchronous

gremlins.createHorde()
  .before(function (done) {
    setTimeout(() => {
      this.log('async')
      done()
    }, 500)
  })