localhost/tests/index.html
var start = new Date().getTime(), system = require('system'), page = require('webpage').create(); console.log('\nStart tests...\n'); /** * . */ var globalLog = (function() { var store = []; return { /** * . * * @param msg */ add: function(msg) { store.push(msg); }, /** * . */ console: function() { var log = ''; for (var i= 0; i < store.length; i++) { log += store[i] + '\n'; } console.log(log); } }; }()); if (system.args.length !== 2) { globalLog.add('Usage: phantomjs run-siesta.js URL'); myExit(1); } /** * . * * @param exitCode (0 - ) */ function myExit(exitCode) { globalLog.add('Total time: ' + (new Date().getTime() - start) + ' ms'); globalLog.add('Exit code: ' + exitCode); globalLog.console(); phantom.exit(exitCode); } /** * . * @param msg */ page.onConsoleMessage = function(msg) { if (msg.match(/END_TESTS/)) { var exitCode = page.evaluate( function() { var totalPass = document.getElementsByClassName('total-pass')[0].innerText; var totalFail = document.getElementsByClassName('total-fail')[0].innerText; if (totalFail !== '0') { console.log('\nFailed!'); } else { console.log('\nCompleted!'); } console.log('\nTotal pass: ' + totalPass); console.log('Total fail: ' + totalFail); return totalFail === '0' ? 0 : 1; } ); myExit(exitCode); } else if (!msg.match(/\[object Object\]/)) { console.log(msg); } }; /** * . * @param {String} URL */ page.open(system.args[1], function(status) { if (status !== "success") { globalLog.add("Unable to access network"); myExit(1); } } );
autoRun: true
listeners: { testfinalize: function(event, test) { var fail = test.$failCount, pass = test.$passCount; var log = (fail ? '~~~~~~~~\n FAILED ' : '[PASSED] ') + test.url + ' [pass: ' + pass + ', fail: ' + fail + ']' + (fail ? '\n~~~~~~~~' : ''); console.log(log); }, testsuiteend: function(event, harness) { console.log('END_TESTS'); } }
var Harness = Siesta.Harness.Browser.ExtJS; Harness.configure({ title : 'Awesome Test Suite', // autoRun : true, preload : [ // version of ExtJS used by your application '../ext-4.1.1/resources/css/ext-all.css', '../resources/yourproject-css-all.css', // version of ExtJS used by your application '../ext-4.1.1/ext-all-debug.js', '../yourproject-all.js' ], listeners: { // testfinalize: function(event, test) { var fail = test.$failCount, pass = test.$passCount; var log = (fail ? '~~~~~~~~\n FAILED ' : '[PASSED] ') + test.url + ' [pass: ' + pass + ', fail: ' + fail + ']' + (fail ? '\n~~~~~~~~' : ''); console.log(log); }, // testsuiteend: function(event, harness) { console.log('END_TESTS'); } } }); Harness.start( '010_sanity.t.js', '020_basic.t.js' );
Source: https://habr.com/ru/post/189144/
All Articles