Commit d3741b49 d3741b492c1ca03b25de711190cbcc41b7128949 by Nicolas Perriault

added more tests

1 parent 3622f3e2
......@@ -37,8 +37,9 @@ phantom.Casper.extend({
renderResults: function() {
this.echo("==========================================");
var total = testResults.passed + testResults.failed;
this.echo(total + ' tests executed, ' + testResults.passed + ' passed, ' + testResults.failed + ' failed.');
var total = testResults.passed + testResults.failed,
status = testResults.failed > 0 ? 'FAIL' : 'OK';
this.echo(status + ': ' + total + ' tests executed, ' + testResults.passed + ' passed, ' + testResults.failed + ' failed.');
this.exit();
}
});
\ No newline at end of file
......
......@@ -13,25 +13,44 @@ phantom.args.forEach(function(arg) {
}
});
// Casper#log()
var oldLevel = casper.options.logLevel;
casper.options.logLevel = 'info';
casper.options.verbose = false;
casper.log('foo', 'info');
casper.assert(casper.result.log.some(function(e) {
return e.message === 'foo' && e.level === 'info';
}), 'log() adds a log entry');
casper.options.logLevel = oldLevel;
casper.options.verbose = true;
// Casper#start()
casper.start('tests/site/index.html', function(self) {
self.assertEvalEquals(function() {
return document.title;
}, 'CasperJS test index', 'start() casper can start itself an open an url');
self.click('a:first-child');
var image = self.base64encode('file://' + phantom.libraryPath + '/site/images/phantom.png');
self.assertEquals(image.length, 6160, 'base64encode() can retrieve base64 contents');
self.click('a[href="test.html"]');
});
casper.assert(casper.steps.length === 1, 'start() can add a new navigation step');
// Casper#then()
casper.then(function(self) {
self.assertEvalEquals(function() {
return document.title;
}, 'CasperJS test target', 'click() casper can click on a text link and react when it is loaded');
self.click('a:first-child');
}, 'CasperJS test target', 'click() casper can click on a text link and react when it is loaded 1/2');
self.click('a[href="form.html"]');
});
casper.assert(casper.steps.length === 2, 'then() adds a new navigation step');
// Casper#fill()
casper.then(function(self) {
self.assertEvalEquals(function() {
return document.title;
}, 'CasperJS test form', 'click() casper can click on a text link and react when it is loaded 2/2');
self.fill('form[action="form.html"]', {
email: 'chuck@norris.com',
content: 'Am watching thou',
......@@ -50,10 +69,10 @@ casper.then(function(self) {
}, true, 'fill() can check a form checkbox');
self.assertEvalEquals(function() {
return document.querySelector('input[name="choice"][value="no"]').checked;
}, true, 'fill() can check a form radio button');
}, true, 'fill() can check a form radio button 1/2');
self.assertEvalEquals(function() {
return document.querySelector('input[name="choice"][value="no"]').checked;
}, true, 'fill() can check a form radio button');
return document.querySelector('input[name="choice"][value="yes"]').checked;
}, false, 'fill() can check a form radio button 2/2');
self.assertEvalEquals(function() {
return document.querySelector('input[name="file"]').files.length === 1;
}, true, 'fill() can select a file to upload');
......@@ -63,5 +82,6 @@ casper.then(function(self) {
});
casper.run(function(self) {
self.assert(self.result.log.length > 0, 'log() logged messages');
self.renderResults();
});
......
......@@ -5,6 +5,7 @@
<title>CasperJS test index</title>
</head>
<body>
<img src="images/phantom.png"/>
<a href="test.html">test</a>
<a href="form.html">form</a>
</body>
......