Gremlin Actions for Nightmare
MIT License
Gremlin.js actions for Nightmare.js to allow for monkey testing
Nightmare Gremlins is an action and collection of tasks for Nightmare.js that allows for monkey testing via the Electron app.
There are two ways to use this npm:
Singular action that extends the Nightmare prototype via Nightmare.action
Series of individual tasks to be consumed by a Nightmare instance via nightmare.use
.
The Nightmare prototype can be extended by using the Nightmare.action
method:
import Nightmare from 'nightmare';
import gremlins from 'nightmare-gremlins';
Nightmare.action('gremlins', gremlins);
const nightmare = Nightmare();
const gremlinOptions = {
seed: Date.now(),
unleash: {
nb: 10000,
},
wait: {
maxErrors: 100,
maxTime: 10 * 1000,
},
};
nightmare
.goto('https://google.com')
.gremlins(gremlinOptions) // Run gremlins on the page
.then((errors) => { console.log('Page errors:\n', errors); });
Alternatively, Nightmare Gremlins also exposes a series of individual functions that can be used on an instance of Nightmare for custom composing via .use
:
import Nightmare from 'nightmare';
import * as gremlins from 'nightmare-gremlins';
Nightmare.action('gremlins', gremlins);
const nightmare = Nightmare();
const gremlinOptions = {
seed: Date.now(),
unleash: {
nb: 10000,
},
wait: {
maxErrors: 100,
maxTime: 10 * 1000,
},
};
const errors = [];
nightmare
.use(gremlins.recordErrors(errors))
.use(gremlins.injectGremlins())
.use(gremlins.createHorde())
.use(gremlins.seedHorde(gremlinOptions.seed))
.use(gremlins.unleashHorde(gremlinOptions.unleash))
.use(gremlins.waitForGremlins(errors, gremlinOptions.wait))
.then((errors) => { console.log('Page errors:\n', errors); });
By using a series of tasks, it is possible to add individual steps or functionality:
...
const errors = [];
nightmare
.use(gremlins.recordErrors(errors))
.use(gremlins.injectGremlins())
.evaluate((seed) => {
const horde = window.gremlins.createHorde();
horde.seed(seed);
horde.unleash();
}, Date.now())
.use(gremlins.waitForGremlins(errors, gremlinOptions.wait))
.then(() => { console.log('Page errors:\n', errors); });
Nightmare Gremlins exposes the following tasks (with arguments and defaults):
window.horde
namespacemaxTime
or the number of errors recorded is greater than maxErrors
Nightmare Gremlins includes an additional "super task", that is the same as the action used to extend the Nightmare prototype, but intended to be used on an instance instead:
import Nightmare from 'nightmare';
import {unleashGremlins} from 'nightmare-gremlins';
const nightmare = Nightmare();
const gremlinOptions = {
seed: Date.now(),
unleash: {
nb: 10000,
},
wait: {
maxErrors: 100,
maxTime: 10 * 1000,
},
};
nightmare
.use(unleashGremlins(gremlinOptions))
.then((errors) => { console.log('Page errors:\n', errors); });