diff options
Diffstat (limited to 'src/scenario')
| -rw-r--r-- | src/scenario/DSL.js | 47 | ||||
| -rw-r--r-- | src/scenario/Runner.js | 15 | ||||
| -rw-r--r-- | src/scenario/bootstrap.js | 1 |
3 files changed, 60 insertions, 3 deletions
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js new file mode 100644 index 00000000..4bc21d6c --- /dev/null +++ b/src/scenario/DSL.js @@ -0,0 +1,47 @@ +angular.scenario.dsl.browser = { + navigateTo: function(url){ + $scenario.addStep('Navigate to: ' + url, function(done){ + var self = this; + self.testFrame.load(function(){ + self.testFrame.unbind(); + self.testDocument = jQuery(self.testWindow.document); + done(); + }); + if (this.testFrame.attr('src') == url) { + this.testWindow.location.reload(); + } else { + this.testFrame.attr('src', url); + } + }); + } +}; + +angular.scenario.dsl.input = function(selector) { + return { + enter: function(value){ + $scenario.addStep("Set input text of '" + selector + "' to value '" + + value + "'", function(done){ + var input = this.testDocument.find('input[name=' + selector + ']'); + input.val(value); + input.trigger('change'); + this.testWindow.angular.element(input[0]).trigger('change'); + done(); + }); + } + }; +}; + +angular.scenario.dsl.expect = function(selector) { + return { + toEqual: function(expected) { + $scenario.addStep("Expect that " + selector + " equals '" + expected + "'", function(done){ + var attrName = selector.substring(2, selector.length - 2); + var binding = this.testDocument.find('span[ng-bind=' + attrName + ']'); + if (binding.text() != expected) { + this.result.fail("Expected '" + expected + "' but was '" + binding.text() + "'"); + } + done(); + }); + } + }; +}; diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js index 9e20d394..003ce487 100644 --- a/src/scenario/Runner.js +++ b/src/scenario/Runner.js @@ -1,9 +1,11 @@ -angular['scenario'] = (angular['scenario'] = {}); +angular['scenario'] = (angular['scenario'] = {}); +angular.scenario['dsl'] = (angular.scenario['dsl'] = {}); angular.scenario.Runner = function(scope, jQuery){ var self = scope.$scenario = this; this.scope = scope; this.jQuery = jQuery; + angular.extend(scope, angular.scenario.dsl); var specs = this.specs = {}; var path = []; @@ -18,7 +20,13 @@ angular.scenario.Runner = function(scope, jQuery){ name: specName, steps:[] }; - body(); + try { + body(); + } catch(err) { + self.addStep(err.message || 'ERROR', function(){ + throw err; + }); + } self.currentSpec = null; }; this.logger = function returnNoop(){ @@ -55,6 +63,7 @@ angular.scenario.Runner.prototype = { return angular.extend(logger(element), { close: function(){ element.removeClass('running'); + console.scrollTop(console[0].scrollHeight); }, fail: function(){ element.removeClass('running'); @@ -66,7 +75,7 @@ angular.scenario.Runner.prototype = { current = current.parent(); } } - });; + }); }; } this.logger = logger(console); diff --git a/src/scenario/bootstrap.js b/src/scenario/bootstrap.js index 51d24c38..4c9cdc8d 100644 --- a/src/scenario/bootstrap.js +++ b/src/scenario/bootstrap.js @@ -29,6 +29,7 @@ addScript("../../lib/jquery/jquery-1.4.2.js"); addScript("../angular-bootstrap.js"); addScript("Runner.js"); + addScript("DSL.js"); document.write('<script type="text/javascript">' + '$scenarioRunner = new angular.scenario.Runner(window, jQuery);' + '</script>'); |
