From 80c04de647d9bec310c616589b05b97061cc9223 Mon Sep 17 00:00:00 2001 From: Stephen Cresswell Date: Mon, 14 Oct 2013 21:56:50 +0100 Subject: [PATCH] Updating for Yadda 0.6.2 --- .gitignore | 1 + package.json | 7 +++++-- runtests.js | 32 ++++++++++++++++---------------- stepdefs/Sample.js | 40 ++++++++++++++++++---------------------- weblibrary.js | 11 ++++++----- 5 files changed, 46 insertions(+), 45 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/package.json b/package.json index acfff1f..8f4dee3 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,14 @@ "description": "Packages used for running web acceptance tests", "author": "Colin Vipurs ", "devDependencies": { - "yadda": "~0.5.2", + "yadda": "~0.6.2", "mocha": "~1.12.0", "selenium-webdriver": "2.35.x", "glob": "~3.2.x", "xunit-file" : "0.0.4" }, - "engine": "node >= 0.8.0" + "engine": "node >= 0.8.0", + "scripts": { + "test": "make test" + } } diff --git a/runtests.js b/runtests.js index 63f79bc..3facb74 100644 --- a/runtests.js +++ b/runtests.js @@ -8,18 +8,21 @@ *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -var Yadda = require('yadda').Yadda; -require('yadda').plugins.mocha(); var glob = require('glob'); -var Library = require('yadda').localisation.English; -var library = new Library(); +var Yadda = require('yadda'); +Yadda.plugins.mocha(); -var context = {}; -var webcontext = require('./weblibrary').library.init(context); -var yadda = new Yadda(library, context); +var libraries = stepDefs().reduce(importStepDef, []); +var context = require('./weblibrary').library.init(); +var yadda = new Yadda.Yadda(libraries, context); -stepDefs().forEach(importStepDef); -featureFiles().forEach(executeFeature); +featureFiles().forEach(function(file) { + feature(file, function(feature) { + scenarios(feature.scenarios, function(scenario, done) { + yadda.yadda(scenario.steps, done); + }) + }) +}); function featureFiles() { return glob.sync("features/**/*.feature"); @@ -29,11 +32,8 @@ function stepDefs() { return glob.sync("stepdefs/**/*.js") }; -function importStepDef(stepdef) { +function importStepDef(stepdefs, stepdef) { var fileName = stepdef.replace('.js', ''); - require('./' + fileName).steps.using(library, context); -}; - -function executeFeature(featureFile) { - yadda.mocha('Bootstrap', featureFile); -}; + var library = require('./' + fileName); + return stepdefs.concat(library); +}; \ No newline at end of file diff --git a/stepdefs/Sample.js b/stepdefs/Sample.js index 7e8c1f0..c6f3084 100644 --- a/stepdefs/Sample.js +++ b/stepdefs/Sample.js @@ -9,31 +9,27 @@ */ var webdriver = require('selenium-webdriver'); var assert = require('selenium-webdriver/testing/assert'); +var library = new require('yadda').localisation.English(); -var Steps = { - using: function(library, ctx) { - library.given("I am on google", function(next) { - ctx.driver.get("http://www.google.co.uk") - .then(function() { - next(); - }); - }); +module.exports = library - library.when("I search for $query", function(query, next) { - ctx.driver.findElement(webdriver.By.css("#gbqfq")).sendKeys(query); - ctx.driver.findElement(webdriver.By.css("#gbqfb")).click().then(function() { - next(); - }); + .given("I am on google", function(next) { + this.driver.get("http://www.google.co.uk") + .then(function() { + next(); }); + }) - library.then("I should see the yadda github in the results", function(next) { - ctx.driver.findElement(webdriver.By.css("cite")).getText().then(function(text) { - assert(text).contains("https://github.com/acuminous/"); - - next(); - }); + .when("I search for $query", function(query, next) { + this.driver.findElement(webdriver.By.css("#gbqfq")).sendKeys(query); + this.driver.findElement(webdriver.By.css("#gbqfb")).click().then(function() { + next(); }); - } -}; + }) -exports.steps = Steps; + .then("I should see the yadda github in the results", function(next) { + this.driver.findElement(webdriver.By.css("cite")).getText().then(function(text) { + assert(text).contains("https://github.com/acuminous/"); + next(); + }); + }); diff --git a/weblibrary.js b/weblibrary.js index f274e13..808539b 100644 --- a/weblibrary.js +++ b/weblibrary.js @@ -11,9 +11,8 @@ var context; var webdriver = require('selenium-webdriver'); var weblibrary = { - init: function(context) { - var self = this; - self.context = context; + init: function() { + var context = {}; // mocha lifecycle operations function initBrowser(done) { @@ -22,18 +21,20 @@ var weblibrary = { .withCapabilities({'browserName': 'chrome'}) .build(); driver.manage().timeouts().implicitlyWait(15000); - self.context.driver = driver; + context.driver = driver; done(); } function shutdownBrowser(done) { - self.context.driver.quit().then(function() { + context.driver.quit().then(function() { done(); }); } before(initBrowser); after(shutdownBrowser); + + return context; } };