When comparing CasperJS vs Nightwatch.js, the Slant community recommends Nightwatch.js for most people. In the question“What are the best Javascript end-to-end testing tools?” Nightwatch.js is ranked 2nd while CasperJS is ranked 10th. The most important reason people chose Nightwatch.js is:
Nightwatch solves the [Paradox of Choice](http://www.ted.com/talks/barry_schwartz_on_the_paradox_of_choice?language=en) among testing frameworks such as Jasmine, Cucumber or Mocha+Chai, by including its own BDD-style assertion library, based on Chai.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Allows screenshots (either the full page or parts of it) if performing UI testing
There are times where you don't want to open up a browser for screencaps, that is where CasperJS comes to use, it can render the page using its own rendering engine and take and save a screenshot for you, all via the commandline
Pro Easy to understand
Pro Written in JavaScript
Since all webdevs know JS, the start-up time of learning the framework will be reduced to zero, as your team can be productive from day one.
Pro Easily integrates with other applications
Due to the simplicity of the framework, not only other libraries can be built with it, but it can be integrated with any web application as well.
Pro Can run javascript code inside pages being tested
Can execute arbitrary javascript or load external JS into the page being tested. This feature is possible due to the presence of a rendering engine, and helps you see the effects of any client side scripting during your tests.
Pro You don't have to choose a testing framework
Nightwatch solves the Paradox of Choice among testing frameworks such as Jasmine, Cucumber or Mocha+Chai, by including its own BDD-style assertion library, based on Chai.
Pro Includes its own testing framework / assertions library
Pro Test organization is out of the box
Supports page object model, custom commands, custom assertions, and globals.js.
Pro 3rd party integration with Cucumber
Though Cucumber is not officially supported, Nightwatch can be used with Cucumber.
Cons
Con Not for unit testing but rather UI testing
These are two extremely different concepts. CasperJS should be removed from this list
Con Cannot guarantee 100% accurate Webkit-based browser screenshots
QtWebKit is the rendering engine used by CasperJS. Keep in mind this is NOT the same rendering engine as Chrome; hence, if you want to be 100% sure of the results, you must run a Webkit browser (such as Chrome) yourself.
Con No official BDD-style syntax support
Con Includes its own testing framework / assertions library
Unlike WebdriverIO, which lets you use various test frameworks and assertion libraries (e.g. Jasmine, Cucumber, Mocha + Chai), Nightwatch comes with its own BDD-style interface for performing assertions, based on Chai.
Here's a simple test example:
module.exports = {
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};