Skip to content

Instantly share code, notes, and snippets.

@zedar
Created February 8, 2014 11:02
Show Gist options
  • Save zedar/8881969 to your computer and use it in GitHub Desktop.
Save zedar/8881969 to your computer and use it in GitHub Desktop.
CasperJS and underscore.js
Casper.js - testing library for web pages and javascript.
Underscore.js - utility library for javascript
Install casper.js globally
$ npm install -g casperjs
Install underscore.js globally
$ npm install -g underscore
Run casper with test javascript file
$ casperjs test tests/Test.js
"use strict";
// casper is globally defined variable
// turn on logging - console.log should be visible in casper.js log
casper.options.logLevel = "debug";
// load web page - there is assumption that server is running
casper.start("http://localhost:8080/tests/Test.html", function() {
this.echo("Started");
});
// wait for full page load. Some AMD modules need to be loaded before the following tests
casper.waitForSelector("#test", function() {
// evalute some variables - loaded as AMD modules
var t = this.evaluate(function() {
return new TestObject();
});
this.test.assert(!_.isNull(t), "Object t has to be given");
this.test.assert(_.has(t, "id"), "Object t has to have id property");
}, function() {
this.echo("Timeout");
}, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment