A high-level browser automation library.
Every method is a simple English command: goto, refresh, click, type... you can check out Nightmare's full API here.
Nightmare lets you simplify deeply nested callbacks into a few sequential statements. Here's an example search on Yahoo:
phantom.create(function (ph) {
ph.createPage(function (page) {
page.open('http://yahoo.com', function (status) {
page.evaluate(function () {
var el =
document.querySelector('input[title="Search"]');
el.value = 'github nightmare';
}, function (result) {
page.evaluate(function () {
var el = document.querySelector('.searchsubmit');
var event = document.createEvent('MouseEvent');
event.initEvent('click', true, false);
el.dispatchEvent(event);
}, function (result) {
ph.exit();
});
});
});
});
});
yield Nightmare()
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit');
Nightmare and its plugins can be installed with npm:
$ npm install nightmare
The package exposes a JavaScript API.