First CasperJS test -- woohoo

This commit is contained in:
Peter Cottle 2015-03-22 17:07:50 -07:00
parent 6ac9ed298d
commit 65480b4ed1
4 changed files with 94 additions and 11 deletions

View file

@ -0,0 +1,34 @@
var CasperHelp = {
getRoot: function() {
// Unfortunately this is hardcoded for now :*( cant get the path
// variable while in a casper context
return '/Users/pcottle/Dropbox/wip/learnGitBranching/';
},
getUrl: function () {
return 'file://localhost/' + this.getRoot() + '/index.html?NODEMO';
},
getUrlForCommands: function(commands) {
return this.getUrl() + '&command=' + commands.join(';');
},
waits: {
jsMount: function() {
return this.evaluate(function() {
return document.querySelectorAll('div.BaseHelperBar').length > 0;
});
},
allCommandsFinished: function () {
return this.evaluate(function() {
return document.querySelectorAll('p.commandLine').length ===
document.querySelectorAll('p.finished').length;
});
},
},
};
exports.CasperHelp = CasperHelp;

View file

@ -0,0 +1,46 @@
var CasperHelp = require('./casperHelp').CasperHelp;
var visibleIDs = [
'commandLineHistory',
'terminal',
'interfaceWrapper',
'mainVisSpace',
'commandLineBar'
];
var selectors = [
'div.visBackgroundColor',
'p.commandLine'
];
var doneSelectors = [
'p.finished'
];
casper.start(
CasperHelp.getUrlForCommands([
'git commit',
]),
function() {
this.test.assertTitle('Learn Git Branching');
casper.waitFor(CasperHelp.waits.jsMount, function then() {
visibleIDs.forEach(function(id) {
this.test.assertVisible('#' + id);
}.bind(this));
selectors.forEach(function(selector) {
this.test.assertExists(selector);
}.bind(this));
this.test.done();
})
.waitFor(CasperHelp.waits.allCommandsFinished, function then() {
doneSelectors.forEach(function(selector) {
this.test.assertExists(selector);
}.bind(this));
});
});
casper.run();