Skip to content

Instantly share code, notes, and snippets.

@thibaudcolas
Created December 2, 2015 20:22
Show Gist options
  • Save thibaudcolas/064c010e3b02d6243805 to your computer and use it in GitHub Desktop.
Save thibaudcolas/064c010e3b02d6243805 to your computer and use it in GitHub Desktop.
Nightmare example
'use strict';
require('mocha-generators').install();
var expect = require('chai').expect;
var nightmare = require('nightmare');
describe('Test blog content', function() {
this.timeout(10000);
let night;
before('setup nightmare instance', function() {
night = nightmare({ show: true });
});
after('teardown nightmare instance', function*() {
yield night.end();
});
describe('homepage', function() {
before('go to page', function*() {
yield night.goto('http://blog.thib.me/');
});
it('page title', function*() {
var title = yield night.evaluate(function() {
return document.querySelector('header h1').innerText;
});
expect(title).to.equal('ThibWeb\'s Blog');
});
it('articles on homepage', function*() {
var nbArticles = yield night.evaluate(function() {
return document.querySelectorAll('.blog-index h1').length;
});
expect(nbArticles).to.equal(5);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment