Update CasperJS and refactor tests

This commit is contained in:
Dávid Szabó
2016-08-31 14:11:29 +02:00
parent 52eaa8b170
commit 0238dffe71
7 changed files with 78 additions and 65 deletions

View File

@@ -1,42 +1,48 @@
(function () {
var tests = require('./test/drawing/DrawingTests.casper.js').tests;
var tests = require('../drawing/DrawingTests.casper.js').tests;
// Polyfill for Object.assign (missing in PhantomJS)
casper.options.clientScripts.push('./node_modules/phantomjs-polyfill-object-assign/object-assign-polyfill.js');
var baseUrl = casper.cli.get('baseUrl')+"?debug";
var resultSelector = '#drawing-test-result';
casper.start();
var runTest = function (index) {
var test = 'drawing/tests/' + tests[index];
casper.test.begin('Drawing Tests', tests.length, function(test) {
casper.start();
casper.open(baseUrl + "&test-run=" + test);
var runTest = function (index) {
var currentTest = 'drawing/tests/' + tests[index];
casper.then(function () {
this.echo('Running test : ' + test);
this.wait(casper.cli.get('delay'));
});
casper.open(baseUrl + "&test-run=" + currentTest);
casper.then(function () {
this.echo('... Waiting for test result : ' + resultSelector);
this.waitForSelector(resultSelector, function () {
// then
var result = this.getHTML(resultSelector);
this.echo('... Test finished : ' + result);
this.test.assertEquals(result, 'OK');
}, function () {
// onTimeout
this.test.fail('Test timed out');
}, 60*1000);
})
.run(function () {
if (tests[index+1]) {
runTest(index+1);
} else {
this.test.done();
}
});
};
casper.then(function () {
this.echo('Running test : ' + currentTest);
this.wait(casper.cli.get('delay'));
});
runTest(0);
casper.then(function () {
this.echo('... Waiting for test result : ' + resultSelector);
this.waitForSelector(resultSelector, function () {
// then
var result = this.getHTML(resultSelector);
this.echo('... Test finished : ' + result);
test.assertEquals(result, 'OK');
}, function () {
// onTimeout
test.fail('Test timed out');
}, 15*1000);
})
.run(function () {
if (tests[index+1]) {
runTest(index+1);
} else {
test.done();
}
});
};
runTest(0);
});
})();

View File

@@ -1,15 +1,19 @@
casper
.start(casper.cli.get('baseUrl')+"?debug")
.then(function () {
this.wait(casper.cli.get('delay'));
})
.then(function () {
this.echo(casper.cli.get('baseUrl')+"?debug");
// If there was a JS error after the page load, casper won't perform asserts
this.test.assertExists('html', 'Casper JS cannot assert DOM elements. A JS error has probably occured.');
casper.test.begin('Smoke Test', 2, function(test) {
casper
.start(casper.cli.get('baseUrl')+"/?debug")
.then(function () {
this.wait(casper.cli.get('delay'));
})
.then(function () {
this.echo(casper.cli.get('baseUrl')+"/?debug");
// If there was a JS error after the page load, casper won't perform asserts
test.assertExists('html', 'Casper JS cannot assert DOM elements. A JS error has probably occured.');
this.test.assertExists('#drawing-canvas-container canvas', 'Check if drawing canvas element is created');
})
.run(function () {
this.test.done();
});
this.waitForSelector('#drawing-canvas-container canvas', function() {
test.assertExists('#drawing-canvas-container canvas', 'Check if drawing canvas element is created');
});
})
.run(function () {
test.done();
});
});

View File

@@ -1,4 +1,4 @@
(typeof exports != "undefined" ? exports : pskl_exports).tests = [
// did not manage to successfully run drawing tests on travis yet ...
'SmokeTest.js'
'SmokeTest.js',
'DrawingTest.js'
];