# HG changeset patch # User Atul Varma # Date 1272630361 25200 # Node ID 4567dc69cb3e5be0468831ec5c4b39a5d2ae5ae1 # Parent 8335b1abc2959dc1a80b173dd801ae29ba418dab Added failure messages and more color feedback to black-box tests diff -r 8335b1abc295 -r 4567dc69cb3e black-box.html --- a/black-box.html Fri Apr 30 05:10:10 2010 -0700 +++ b/black-box.html Fri Apr 30 05:26:01 2010 -0700 @@ -24,6 +24,7 @@
+
Login without Password diff -r 8335b1abc295 -r 4567dc69cb3e css/black-box.css --- a/css/black-box.css Fri Apr 30 05:10:10 2010 -0700 +++ b/css/black-box.css Fri Apr 30 05:26:01 2010 -0700 @@ -30,6 +30,14 @@ cursor: pointer; } +.fail { + color: red; +} + +.success { + color: #00ff00; +} + .running:after { content: " (now running)"; color: yellow; diff -r 8335b1abc295 -r 4567dc69cb3e js/black-box.js --- a/js/black-box.js Fri Apr 30 05:10:10 2010 -0700 +++ b/js/black-box.js Fri Apr 30 05:26:01 2010 -0700 @@ -1,6 +1,7 @@ -function Automator(window, jQuery, onDone) { +function Automator(window, jQuery, onDone, onFail) { this.jQuery = jQuery; this.onDone = onDone; + this.onFail = onFail; this.queue = []; this.window = window; } @@ -24,10 +25,10 @@ var query = this.jQuery(sel); if (query.length == 0) - throw new Error("selector yields no results: " + sel); + this.onFail("selector yields no results: " + sel); if (query.length > 1) - throw new Error("selector yields " + query.length + - " results instead of 1: " + sel); + this.onFail("selector yields " + query.length + + " results instead of 1: " + sel); return query; }, @@ -37,7 +38,7 @@ var query = this.jQuery(field + ":visible"); if (query.length == 0) - throw new Error("selector not visible: " + field); + this.onFail("selector not visible: " + field); }); }, type: function type(field, value) { @@ -48,6 +49,13 @@ } }; +function testLoginWithNoPassword(auto) { + auto.type("#login .username", "john@doe.com"); + auto.type("#login .password", ""); + auto.submit("#login form"); + auto.verifyVisible("#header .requires-login"); +} + function testLoginWithCorrectPassword(auto) { auto.type("#login .username", "john@doe.com"); auto.type("#login .password", "test"); @@ -56,13 +64,6 @@ auto.verifyVisible("#header .requires-auth-login"); } -function testLoginWithNoPassword(auto) { - auto.type("#login .username", "john@doe.com"); - auto.type("#login .password", ""); - auto.submit("#login form"); - auto.verifyVisible("#header .requires-login"); -} - function testLoginWithIncorrectPassword(auto) { auto.type("#login .username", "john@doe.com"); auto.type("#login .password", "u"); @@ -118,8 +119,19 @@ var auto; $(testButton).addClass("running"); + function onFail(reason) { + $(testButton).addClass("fail"); + var msg = ("Failure in " + $(testButton).text() + ": " + + reason); + var msgElem = $('

').text(msg); + msgElem.hide(); + $("#messages").append(msgElem); + msgElem.slideDown(); + } function onDone() { $(testButton).removeClass("running"); + if (!$(testButton).hasClass("fail")) + $(testButton).addClass("success"); } resetDashboard( @@ -128,7 +140,8 @@ case "blackBox.onDashboardLoaded": var dashboard = args[0]; var options = args[1]; - auto = new Automator(window, options.jQuery, onDone); + auto = new Automator(window, options.jQuery, onDone, + onFail); testFunc(auto); break; case "blackBox.afterInit":