From 3fab5d9879272b9f991a67c8135754f00c055834 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Mon, 24 May 2010 15:25:30 -0700 Subject: added error handling on scenario definition --- jsTestDriver-jquery.conf | 1 + jsTestDriver.conf | 1 + scenario/Runner.html | 2 +- scenario/widgets-scenario.js | 20 +++++++++++++++ scenario/widgets-scenario2.js | 55 ------------------------------------------ scenario/widgets-scenarios.js | 49 ------------------------------------- scenario/widgets-scenarios.old | 49 +++++++++++++++++++++++++++++++++++++ scenario/widgets.html | 4 +-- src/scenario/DSL.js | 47 ++++++++++++++++++++++++++++++++++++ src/scenario/Runner.js | 15 +++++++++--- src/scenario/bootstrap.js | 1 + test/scenario/RunnerSpec.js | 18 +++++++++++++- 12 files changed, 151 insertions(+), 111 deletions(-) create mode 100644 scenario/widgets-scenario.js delete mode 100644 scenario/widgets-scenario2.js delete mode 100644 scenario/widgets-scenarios.js create mode 100644 scenario/widgets-scenarios.old create mode 100644 src/scenario/DSL.js diff --git a/jsTestDriver-jquery.conf b/jsTestDriver-jquery.conf index 128fcb6c..953e4521 100644 --- a/jsTestDriver-jquery.conf +++ b/jsTestDriver-jquery.conf @@ -7,6 +7,7 @@ load: - test/jquery_alias.js - src/Angular.js - src/*.js + - src/scenario/Runner.js - src/scenario/*.js - test/testabilityPatch.js - test/angular-mocks.js diff --git a/jsTestDriver.conf b/jsTestDriver.conf index 4a702a3e..c28e9ff1 100644 --- a/jsTestDriver.conf +++ b/jsTestDriver.conf @@ -7,6 +7,7 @@ load: - test/jquery_remove.js - src/Angular.js - src/*.js + - src/scenario/Runner.js - src/scenario/*.js - test/testabilityPatch.js - test/angular-mocks.js diff --git a/scenario/Runner.html b/scenario/Runner.html index 5502283a..ffa08af9 100644 --- a/scenario/Runner.html +++ b/scenario/Runner.html @@ -2,7 +2,7 @@
- + diff --git a/scenario/widgets-scenario.js b/scenario/widgets-scenario.js new file mode 100644 index 00000000..9e23d4df --- /dev/null +++ b/scenario/widgets-scenario.js @@ -0,0 +1,20 @@ +describe('widgets', function(){ + it('should verify that basic widgets work', function(){ + browser.navigateTo('widgets.html'); + + expect('{{text.basic}}').toEqual(''); + input('text.basic').enter('John'); + expect('{{text.basic}}').toEqual('John'); + + expect('{{text.password}}').toEqual(''); + input('text.password').enter('secret'); + expect('{{text.password}}').toEqual('secret'); + + expect('{{text.hidden}}').toEqual('hiddenValue'); + + expect('{{gender}}').toEqual('male'); + input('gender').select('female'); + expect('{{gender}}').toEqual('female'); + + }); +}); diff --git a/scenario/widgets-scenario2.js b/scenario/widgets-scenario2.js deleted file mode 100644 index b966b270..00000000 --- a/scenario/widgets-scenario2.js +++ /dev/null @@ -1,55 +0,0 @@ -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); - } - }); - } -}; - -function input(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(); - }); - } - }; -} - -function expect(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(); - }); - } - }; -} - -describe('widgets', function(){ - it('should verify that basic widgets work', function(){ - browser.navigateTo('widgets.html'); - expect('{{text.basic}}').toEqual(''); - input('text.basic').enter('John'); - expect('{{text.basic}}').toEqual('John'); - }); -}); diff --git a/scenario/widgets-scenarios.js b/scenario/widgets-scenarios.js deleted file mode 100644 index a1e6c0ed..00000000 --- a/scenario/widgets-scenarios.js +++ /dev/null @@ -1,49 +0,0 @@ -angular.scenarioDef.widgets = { - $before:[ - {Given:"browser", at:"widgets.html"} - ], - checkWidgetBinding:[ - {Then:"text", at:"{{text.basic}}", should_be:""}, - {When:"enter", text:"John", at:":input[name=text.basic]"}, - {Then:"text", at:"{{text.basic}}", should_be:"John"}, - - {Then:"text", at:"{{gender}}", should_be:"male"}, - {When:"click", at:"input:radio[value=female]"}, - {Then:"text", at:"{{gender}}", should_be:"female"}, - - {Then:"text", at:"{{tea}}", should_be:"on"}, - {When:"click", at:"input[name=tea]"}, - {Then:"text", at:"{{tea}}", should_be:""}, - - {Then:"text", at:"{{coffee}}", should_be:""}, - {When:"click", at:"input[name=coffee]"}, - {Then:"text", at:"{{coffee}}", should_be:"on"}, - - {Then:"text", at:"{{count}}", should_be:0}, - {When:"click", at:"form :button"}, - {When:"click", at:"form :submit"}, - {When:"click", at:"form :image"}, - {Then:"text", at:"{{count}}", should_be:3}, - - {Then:"text", at:"{{select}}", should_be:"A"}, - {When:"select", at:"select[name=select]", option:"B"}, - {Then:"text", at:"{{select}}", should_be:"B"}, - - {Then:"text", at:"{{multiple}}", should_be:"[]"}, - {When:"select", at:"select[name=multiple]", option:"A"}, - {Then:"text", at:"{{multiple}}", should_be:["A"]}, - {When:"select", at:"select[name=multiple]", option:"B"}, - {Then:"text", at:"{{multiple}}", should_be:["A", "B"]}, - {When:"select", at:"select[name=multiple]", option:"A"}, - {Then:"text", at:"{{multiple}}", should_be:["B"]}, - - {Then:"text", at:"{{hidden}}", should_be:"hiddenValue"}, - - {Then:"text", at:"{{password}}", should_be:"passwordValue"}, - {When:"enter", text:"reset", at:":input[name=password]"}, - {Then:"text", at:"{{password}}", should_be:"reset"}, - ], - checkNewWidgetEmpty:[ - {Then:"text", at:"{{name}}", should_be:""}, - ] -}; diff --git a/scenario/widgets-scenarios.old b/scenario/widgets-scenarios.old new file mode 100644 index 00000000..a1e6c0ed --- /dev/null +++ b/scenario/widgets-scenarios.old @@ -0,0 +1,49 @@ +angular.scenarioDef.widgets = { + $before:[ + {Given:"browser", at:"widgets.html"} + ], + checkWidgetBinding:[ + {Then:"text", at:"{{text.basic}}", should_be:""}, + {When:"enter", text:"John", at:":input[name=text.basic]"}, + {Then:"text", at:"{{text.basic}}", should_be:"John"}, + + {Then:"text", at:"{{gender}}", should_be:"male"}, + {When:"click", at:"input:radio[value=female]"}, + {Then:"text", at:"{{gender}}", should_be:"female"}, + + {Then:"text", at:"{{tea}}", should_be:"on"}, + {When:"click", at:"input[name=tea]"}, + {Then:"text", at:"{{tea}}", should_be:""}, + + {Then:"text", at:"{{coffee}}", should_be:""}, + {When:"click", at:"input[name=coffee]"}, + {Then:"text", at:"{{coffee}}", should_be:"on"}, + + {Then:"text", at:"{{count}}", should_be:0}, + {When:"click", at:"form :button"}, + {When:"click", at:"form :submit"}, + {When:"click", at:"form :image"}, + {Then:"text", at:"{{count}}", should_be:3}, + + {Then:"text", at:"{{select}}", should_be:"A"}, + {When:"select", at:"select[name=select]", option:"B"}, + {Then:"text", at:"{{select}}", should_be:"B"}, + + {Then:"text", at:"{{multiple}}", should_be:"[]"}, + {When:"select", at:"select[name=multiple]", option:"A"}, + {Then:"text", at:"{{multiple}}", should_be:["A"]}, + {When:"select", at:"select[name=multiple]", option:"B"}, + {Then:"text", at:"{{multiple}}", should_be:["A", "B"]}, + {When:"select", at:"select[name=multiple]", option:"A"}, + {Then:"text", at:"{{multiple}}", should_be:["B"]}, + + {Then:"text", at:"{{hidden}}", should_be:"hiddenValue"}, + + {Then:"text", at:"{{password}}", should_be:"passwordValue"}, + {When:"enter", text:"reset", at:":input[name=password]"}, + {Then:"text", at:"{{password}}", should_be:"reset"}, + ], + checkNewWidgetEmpty:[ + {Then:"text", at:"{{name}}", should_be:""}, + ] +}; diff --git a/scenario/widgets.html b/scenario/widgets.html index 4d0f30b0..86269e86 100644 --- a/scenario/widgets.html +++ b/scenario/widgets.html @@ -26,8 +26,8 @@