Created
September 17, 2012 15:08
-
-
Save ulrich/3737910 to your computer and use it in GitHub Desktop.
This script tests a simple emberjs application with casperjs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var casper = require('casper').create({ | |
verbose: true, | |
logLevel: 'debug', | |
}); | |
var url = "file:///media/data/projects/personnal/js/ember.js/simple/index.html"; | |
// a callback that ensures the runloop is flushed before an assert is run. Based on gist... | |
/*casper.test.emberDidRender = function(cbk){ | |
casper.evaluate(function() { | |
return window.Ember.run.end(); | |
}); | |
cbk.call(casper) | |
};*/ | |
casper.start(url, function() { | |
// test the page title | |
this.test.assertTitleMatch(/Simple Ember.js Application/, 'Must find the correct title for the Simple application'); | |
// test if we found the input field | |
this.test.assertExists('input[id="compteur_field"]', 'Must find the textfield for the Simple application'); | |
// test if we found the minus button | |
this.test.assertExists('button[id="minus_button"]', 'Must find the minus button for the Simple application'); | |
// test if we found the plus button | |
this.test.assertExists('button[id="plus_button"]', 'Must find the plus button for the Simple application'); | |
}); | |
// first method | |
casper.then(function() { | |
this.click('button#plus_button'); | |
var result = this.evaluate(function() { | |
return document.querySelector('input#compteur_field').value; | |
}); | |
this.test.assertEquals(result, 2, 'The value must be incremented by 2'); | |
}); | |
// second method | |
casper.then(function() { | |
var result = this.evaluate(function() { | |
$('#plus_button').click(); | |
return $('#compteur_field').val(); | |
}); | |
//this.test.emberDidRender(function(){ | |
this.test.assertEquals(result, 2, 'The value must be 2'); | |
//}); | |
}); | |
casper.run(function() { | |
this.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment