Skip to content

Instantly share code, notes, and snippets.

@martin-hewitt
Created October 17, 2013 14:57
Show Gist options
  • Save martin-hewitt/7026423 to your computer and use it in GitHub Desktop.
Save martin-hewitt/7026423 to your computer and use it in GitHub Desktop.
CasperJS
var Spooky = require('spooky')
var app = require('../../index');
var port = 3001
var spooky = new Spooky({
child: {
transport: 'stdio',
args: ['test']
},
casper: {
logLevel: 'warning'
}
}, function( err ) {
if ( err ) {
e = new Error("Failed to initialize SpookyJS")
e.details = err
throw e
}
options = {
site: 'http://localhost:' + port
}
app.server.listen( port, function() {
app.setupSocketEvents([
{
frequency: 'once',
event: 'xmpp.buddycloud.discover',
callback: function(data, callback) {
callback(null, 'channels.example.com')
}
},
{
frequency: 'once',
event: 'xmpp.login',
callback: function(data, callback) {
app.socket.emit('xmpp.connection', "online")
}
}
])
spooky.start(options.site, function() {})
spooky.then(function(options) {
var casper = this
casper.test.begin('Successful login', 3, function suite(test) {
casper.start(options.site, function() {})
casper.then( function() {
test.assertTitle('Home', 'Login title is shown')
})
casper.waitUntilVisible("form")
casper.then(function() {
test.assertUrlMatch(/login/, 'Login URL')
casper.fill('form', {
jid: '[email protected]',
password: 'correctpass'
})
casper.click('button')
})
casper.waitUntilVisible('div.banner')
casper.then(function() {
test.assertSelectorHasText('.channel h1', 'Recent Posts');
})
casper.then(function() {
test.done()
test.renderResults(true, 0, 'test-results.xml');
})
casper.run(function() {
console.log("DONE")
})
})
})
spooky.run( function() {
})
})
}
);
spooky.on('console', function (line) {
console.log(line);
});
spooky.on('remote.message', function (line) {
console.log(line);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment