Skip to content

Instantly share code, notes, and snippets.

@m-allanson
Created December 7, 2012 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-allanson/4235225 to your computer and use it in GitHub Desktop.
Save m-allanson/4235225 to your computer and use it in GitHub Desktop.
Broken noise-box casperJS script
var casper = require('casper').create();
var casper2 = require('casper').create();
var roomName = 'caspersroom';
var audiofile = '';
casper.start('http://localhost:7001/', function() {
this.test.assertTitle('NoiseBox', 'NoiseBox title is ok');
this.test.assertExists('form[action="/host/"]', 'The form to create a new host exists');
this.fill('form[action="/host/"]', {
id: roomName
}, true);
});
casper.then(function() {
this.test.assertUrlMatch('/host/caspersroom', 'Form submitted to new host url');
this.test.assertTextExists('Hosting "'+roomName+'"', 'New host identifies itself as existing');
});
casper.then(function(){
casper2.start('http://localhost:7001/caspersroom', function() {
this.test.assertUrlMatch(':7001/caspersroom', 'The client room exists');
this.test.assertTextExists('Viewing "'+roomName+'"', 'The client room identifies itself');
this.test.assertExists('a[href$=".mp3"]', 'An anchor element links to an mp3');
});
casper2.thenClick('a[href$=".mp3"]', function() {
this.test.assertUrlMatch(':7001/caspersroom', 'Clicking the anchor does not change the page');
});
casper2.run(function() {
this.test.done(4); // checks that all assertions have been executed
this.test.renderResults(true);
});
});
casper.then(function() {
var self = this;
casper.waitForSelector('audio[src$=".mp3"]', function() {
self.test.assertExists('audio[src$=".mp3"]', 'The host has an audio element pointing to an mp3');
});
});
casper.run(function() {
this.test.done(5); // checks that all assertions have been executed
this.test.renderResults(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment