Skip to content

Instantly share code, notes, and snippets.

@cdinu
Created January 24, 2014 09:28
Show Gist options
  • Save cdinu/8594464 to your computer and use it in GitHub Desktop.
Save cdinu/8594464 to your computer and use it in GitHub Desktop.
// Run with
// casperjs test front-end.js 2> /dev/null
// to redirect ugly PhantomJS CTFontCreateWithName* errors
var siteURL = 'http://localhost:3000';
var clientDelay = 200; // delay 200ms
// Utility function, needed because Meteor static pages do not load instantly
casper.openWithClientDelay = function (url, fn) {
casper.thenOpen(url, function () {
this.wait(clientDelay, function () {
fn();
});
});
};
/*
....
*/
casper.test.begin('Static pages are fine', 7, function suite(test) {
casper.start();
casper.openWithClientDelay('http://localhost:3000', function () {
test.assertTitle('App Title', 'Homepage title is the one expected');
test.assertExists('h1', 'A heading is found');
});
casper.openWithClientDelay(siteURL + '/static/about', function () {
test.assertTextExists('About Us', 'About Us text exists in the page');
test.assertSelectorHasText('h1#contentTitle', 'About Us', 'About US heading found when navigating to about page');
});
casper.openWithClientDelay(siteURL + '/static/terms', function () {
test.assertTextExists('Terms', 'Terms and conditions text exists in the page');
test.assertSelectorHasText('h1#contentTitle', 'Terms', 'Terms and conditions heading found when navigating to terms page');
});
casper.openWithClientDelay(siteURL + '/static/thisPageDoesNotExistHaHaHa', function () {
test.assertTextExists('404', '404 message found when navigating to unknown page');
});
casper.run(function () {
test.done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment